|
@@ -1,26 +1,43 @@
|
|
package app.mar.activities;
|
|
package app.mar.activities;
|
|
|
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
|
+import android.app.Fragment;
|
|
import android.app.FragmentManager;
|
|
import android.app.FragmentManager;
|
|
import android.app.FragmentTransaction;
|
|
import android.app.FragmentTransaction;
|
|
|
|
+import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.os.Message;
|
|
|
|
+import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
|
+import android.widget.Button;
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import java.util.Timer;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
import app.mar.utils.game.Game;
|
|
import app.mar.utils.game.Game;
|
|
|
|
+import app.mar.utils.game.Stage;
|
|
|
|
+import app.mar.utils.game.challenges.Challenge;
|
|
|
|
+import app.mar.utils.game.challenges.Indice;
|
|
|
|
+import app.mar.utils.game.challenges.Question;
|
|
|
|
|
|
|
|
|
|
-public class HostActivity extends Activity {
|
|
|
|
|
|
+public class HostActivity extends Activity implements ChallengeDriver{
|
|
protected Game mGame;
|
|
protected Game mGame;
|
|
protected TextView mUITimeLeft;
|
|
protected TextView mUITimeLeft;
|
|
protected TextView mUICode;
|
|
protected TextView mUICode;
|
|
|
|
+ protected Button mUIButtonVideos;
|
|
|
|
+ protected Button mUIButtonIndice;
|
|
|
|
+ protected Button mUIButtonValid;
|
|
private Timer mTimer;
|
|
private Timer mTimer;
|
|
|
|
|
|
|
|
+ protected QCMFragment mQCMFragment;
|
|
|
|
+ protected QRCodeFragment mQRCodeFragment;
|
|
|
|
+ protected QuestionFragment mQuestionFragment;
|
|
|
|
+ protected ChallengeFragment mCurrentFragment;
|
|
|
|
+
|
|
private Runnable mTimerTick = new Runnable() {
|
|
private Runnable mTimerTick = new Runnable() {
|
|
public void run() {
|
|
public void run() {
|
|
if(!mGame.getBomb().hasExplosed())
|
|
if(!mGame.getBomb().hasExplosed())
|
|
@@ -40,13 +57,16 @@ public class HostActivity extends Activity {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_host);
|
|
setContentView(R.layout.activity_host);
|
|
|
|
|
|
- FragmentManager fm = getFragmentManager();
|
|
|
|
- FragmentTransaction ft = fm.beginTransaction();
|
|
|
|
- ft.replace(R.id.container, QuestionFragment.newInstance());
|
|
|
|
- ft.commit();
|
|
|
|
|
|
+ mQCMFragment = QCMFragment.newInstance();
|
|
|
|
+ mQuestionFragment = QuestionFragment.newInstance();
|
|
|
|
+ mQRCodeFragment = QRCodeFragment.newInstance();
|
|
|
|
+ mUIButtonVideos = (Button) findViewById(R.id.btn_videos);
|
|
|
|
+ mUIButtonIndice = (Button) findViewById(R.id.btn_indice);
|
|
|
|
+ mUIButtonValid = (Button) findViewById(R.id.btn_valid);
|
|
|
|
|
|
mGame=Game.game();
|
|
mGame=Game.game();
|
|
|
|
|
|
|
|
+
|
|
mUITimeLeft = findViewById(R.id.tv_car);
|
|
mUITimeLeft = findViewById(R.id.tv_car);
|
|
mUICode = findViewById(R.id.tv_code);
|
|
mUICode = findViewById(R.id.tv_code);
|
|
|
|
|
|
@@ -58,8 +78,46 @@ public class HostActivity extends Activity {
|
|
}
|
|
}
|
|
|
|
|
|
}, 0, 1000);
|
|
}, 0, 1000);
|
|
|
|
+
|
|
updateCode();
|
|
updateCode();
|
|
|
|
|
|
|
|
+ startChallenge();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setFragment(Class type)
|
|
|
|
+ {
|
|
|
|
+ ChallengeFragment f = null;
|
|
|
|
+ final Challenge chall = mGame.getCurrentChallenge();
|
|
|
|
+
|
|
|
|
+ if(type.isInstance(mQCMFragment))
|
|
|
|
+ f= mQCMFragment;
|
|
|
|
+ else if(type.isInstance(mQRCodeFragment))
|
|
|
|
+ f= mQRCodeFragment;
|
|
|
|
+ else if(type.isInstance(mQuestionFragment))
|
|
|
|
+ f= mQuestionFragment;
|
|
|
|
+ else {
|
|
|
|
+ throw new RuntimeException("Erreur: La classe de fragment est null");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(f!=mCurrentFragment)
|
|
|
|
+ {
|
|
|
|
+ mCurrentFragment=f;
|
|
|
|
+ FragmentManager fm = getFragmentManager();
|
|
|
|
+ FragmentTransaction ft = fm.beginTransaction();
|
|
|
|
+ ft.replace(R.id.container, mCurrentFragment);
|
|
|
|
+ ft.commit();
|
|
|
|
+ fm.executePendingTransactions();
|
|
|
|
+ Log.e("#########", "setFragment Commit : true");
|
|
|
|
+ }
|
|
|
|
+ else Log.e("#########", "setFragment Commit : false");
|
|
|
|
+ mCurrentFragment.initChallenge(chall);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onFragmentInteraction(Uri uri) {
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
private void timerCallback()
|
|
private void timerCallback()
|
|
@@ -74,8 +132,13 @@ public class HostActivity extends Activity {
|
|
|
|
|
|
public void onClickValid(View v)
|
|
public void onClickValid(View v)
|
|
{
|
|
{
|
|
- mGame.getBomb().addTime(-1);
|
|
|
|
- timerCallback();
|
|
|
|
|
|
+ if(mCurrentFragment!=null)
|
|
|
|
+ {
|
|
|
|
+ if(mCurrentFragment.check())
|
|
|
|
+ {
|
|
|
|
+ challengeValidate(mCurrentFragment.getChallenge());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -91,11 +154,57 @@ public class HostActivity extends Activity {
|
|
|
|
|
|
public void onClickIndice(View v)
|
|
public void onClickIndice(View v)
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ if(mCurrentFragment!=null)
|
|
|
|
+ {
|
|
|
|
+ Indice ind = mCurrentFragment.showIndice();
|
|
|
|
+ if(ind!=null && ind.getPenality()>0)
|
|
|
|
+ mGame.getBomb().addTime(-ind.getPenality());
|
|
|
|
+
|
|
|
|
+ if(!mCurrentFragment.getChallenge().hasNextIndice())
|
|
|
|
+ mUIButtonIndice.setVisibility(View.INVISIBLE);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void onExplose()
|
|
public void onExplose()
|
|
{
|
|
{
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void nextChallenge() {
|
|
|
|
+ Stage s = mGame.getCurrentStage();
|
|
|
|
+ Challenge c = s.nextChallenge();
|
|
|
|
+ if(c!=null)
|
|
|
|
+ {
|
|
|
|
+ startChallenge();
|
|
|
|
+ }else //new stage
|
|
|
|
+ {
|
|
|
|
+ if(mGame.nextStage()!=null)
|
|
|
|
+ startChallenge();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void challengeValidate(Challenge c) {
|
|
|
|
+ c.setDone();
|
|
|
|
+ nextChallenge();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Challenge currentChallenge() {
|
|
|
|
+ return mGame.getCurrentChallenge();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean startChallenge()
|
|
|
|
+ {
|
|
|
|
+ Challenge c = mGame.getCurrentChallenge();
|
|
|
|
+ Log.e("_____", "startChallenge : c : "+c);
|
|
|
|
+ if(c!=null) {
|
|
|
|
+ c.exec(this);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|