François Gautrais 7 роки тому
батько
коміт
52c64100fd

+ 245 - 5
app/src/main/assets/game_medium

@@ -5,10 +5,7 @@
 	"name" : "Intro",
 	"challenges" : [],
 	"resources" : ["intro"],
-	"event_start" : {
-		"method" : "print",
-		"args" : ["Salut, ça va ?"]
-	}
+	"event_end" : { "method" : "armBomb" }
 },
 {
 	"name" : "QrCode",
@@ -16,7 +13,250 @@
 		[
 			{
 				"type" : "QRCodeGeoTreasure",
-				"name" : "A trouver",
+				"name" : "A trouver 0",
+				"bad_message" : "Essaye encore",
+				"qr_value" : "1",
+				"resource" : "bib",
+				"indices" : [
+					{
+						"type" : "geo",
+						"penality": 1
+					},
+					{
+						"type" : "text",
+						"text" : "Entre le 0 et le 2",
+						"penality": 1
+					},
+					{
+						"type" : "text",
+						"text" : "sqrt(x) = x",
+						 "penality": 5
+					}
+				],
+				"area" : {
+					"coordinates": [
+							[
+							  0.1493293046951294,
+							  45.62988696308149
+							],
+							[
+							  0.14950096607208252,
+							  45.62975941918258
+							],
+							[
+							  0.1496753096580505,
+							  45.629898216940994
+							],
+							[
+							  0.14950096607208252,
+							  45.63003888999412
+							],
+							[
+							  0.14934271574020386,
+							  45.63002951180155
+							],
+							[
+							  0.1493293046951294,
+							  45.62988696308149
+							]
+						  ],
+					"name" : "a",
+					"point" :
+						{
+							"angle" : 180.0,
+							"coordinates" :
+							[
+							  0.14950096607208252,
+							  45.629875709219725
+							],
+							"field" : 90.0,
+							"radius" : 100.0,
+							"useAngle" : false
+						}
+				}
+			}
+		],
+	"resources" : [],
+	"charIndex" : 0
+},
+{
+	"name" : "QrCode",
+	"challenges" :
+		[
+			{
+                    "type" : "QCM",
+                    "name" : "Joconde",
+                    "question" : "Qui a peint la Joconde ?",
+                    "answer" : "Léonard De Vinci",
+                    "choices" : ["Léonard De Vinci", "Jean Ferrat", "Patrick Timsit", "BHL"],
+                    "good_message" : "Bien joué !",
+                    "bad_message" : "T'es nul !",
+					"resource" : "question",
+                     "indices" : [
+                         {
+                             "type" : "text",
+                             "text" : "Un italien",
+                                "penality": 1
+                         },
+                         {
+                             "type" : "text",
+                             "text" : "Un vieu !",
+                                 "penality": 1
+                         }
+                     ],
+					 "penality": 3,
+                     "charIndex" : 1
+                 },
+                 {
+                     "type" : "QCM",
+                    "name" : "OS",
+                    "question" : "Windows 7 et 10 sont des systèmes d'explploitation, parmi ces proposition lequel en est un ?",
+                    "answer" : "Linux",
+                    "choices" : ["Apple", "Linux", "Microsoft Word", "Mozilla La réponse D"],
+                    "good_message" : "Bien joué !",
+                    "bad_message" : "T'es nul !",
+					"resource" : "question",
+                     "indices" : [
+                         {
+                             "type" : "text",
+                             "text" : "Il a été inventé par Linus Torvalds",
+                                "penality": 1
+                         },
+                         {
+                             "type" : "text",
+                             "text" : "Il est de la famille des UNIX",
+                                 "penality": 1
+                         }
+                     ],
+					 "penality": 3,
+                     "charIndex" : 2
+                 },
+                 {
+                     "type" : "QCM",
+                    "name" : "RA",
+                    "question" : "Qu'est ce que la réalité augmentée ?",
+                    "answer" : "Une technologie qui permet d'ajouter virtuellement des éléments à la réalité",
+                    "choices" : ["Une technologie qui permet d'ajouter virtuellement des éléments à la réalité", 
+								"Des jeux vidéos sur PC ou consoles qui sont très réalistes", 
+								"Une technique de médium", 
+								"Une Fake News"],
+                    "good_message" : "Bien joué !",
+                    "bad_message" : "T'es nul !",
+					"resource" : "question",
+                     "indices" : [
+                         {
+                             "type" : "text",
+                             "text" : "Pokemon GO est une application en réalité augmentée",
+                                "penality": 1
+                         }
+                     ],
+					 "penality": 3,
+                     "charIndex" : 3
+                 },
+                 {
+                     "type" : "QCM",
+                    "name" : "Question conne",
+                    "question" : "Combien fait 10 / (10-10) ?",
+                    "answer" : "C'est impossible",
+                    "choices" : ["10", 
+								"1", 
+								"C'est impossible", 
+								"0"],
+                    "good_message" : "Bien joué !",
+                    "bad_message" : "T'es nul !",
+					"resource" : "question",
+                     "indices" : [
+                         {
+                             "type" : "text",
+                             "text" : "Ce calcul peut provoquer des erreurs sur les ordinateurs",
+                                "penality": 1
+                         }
+                     ],
+					 "penality": 3,
+                     "charIndex" : 4
+                 }
+		]
+},
+{
+	"name" : "QrCode",
+	"challenges" :
+		[
+			{
+				"type" : "QRCodeGeoTreasure",
+				"name" : "A trouver 1",
+				"bad_message" : "Essaye encore",
+				"qr_value" : "1",
+				"resource" : "mjc",
+				"indices" : [
+					{
+						"type" : "geo",
+						"penality": 1
+					},
+					{
+						"type" : "text",
+						"text" : "Entre le 0 et le 2",
+						"penality": 1
+					},
+					{
+						"type" : "text",
+						"text" : "sqrt(x) = x",
+						 "penality": 5
+					}
+				],
+				"area" : {
+					"coordinates": [
+						[
+						  0.1493293046951294,
+						  45.62988696308149
+						],
+						[
+						  0.14950096607208252,
+						  45.62975941918258
+						],
+						[
+						  0.1496753096580505,
+						  45.629898216940994
+						],
+						[
+						  0.14950096607208252,
+						  45.63003888999412
+						],
+						[
+						  0.14934271574020386,
+						  45.63002951180155
+						],
+						[
+						  0.1493293046951294,
+						  45.62988696308149
+						]
+					  ],
+					"name" : "a",
+					"point" :
+						{
+							"angle" : 180.0,
+							"coordinates" :
+							[
+								0.1493561267852783,
+								45.62970127407351
+							],
+							"field" : 90.0,
+							"radius" : 100.0,
+							"useAngle" : false
+						}
+				}
+			}
+		],
+	"resources" : ["milieu"],
+	"event_end" : { "method" : "setTimerTo", "args" : [15] },
+	"charIndex" : 5
+},
+{
+	"name" : "QrCode",
+	"challenges" :
+		[
+			{
+				"type" : "QRCodeGeoTreasure",
+				"name" : "A trouver 2",
 				"bad_message" : "Essaye encore",
 				"qr_value" : "1",
 				"resource" : "creche",

+ 1 - 1
app/src/main/java/app/mar/activities/ARActivity.java

@@ -390,7 +390,7 @@ public class ARActivity extends RendererActivity
         mGame.newSensorManager(this);
         loadUI();
 
-        Challenge c = mGame.getCurrentChallenge(null);
+        Challenge c = mGame.getCurrentChallenge();
         if(c!=null)
         {
             if(c instanceof ARTreasure)

+ 8 - 2
app/src/main/java/app/mar/activities/ChallengeDriver.java

@@ -5,14 +5,16 @@ import android.view.View;
 
 import app.mar.game.Area;
 import app.mar.game.Game;
+import app.mar.game.Resource;
 import app.mar.game.challenges.Challenge;
+import app.mar.game.scheduler.Scheduler;
 
 public interface ChallengeDriver extends ChallengeFragment.OnFragmentInteractionListener {
     public void challengeValidate(Challenge c, Game g, ChallengeDriver cd);
     public Challenge currentChallenge();
-    public void setFragment(Class c);
+    public void setFragment(Challenge c);
     public void onFragmentInteraction(Uri uri);
-    public void onReady();
+    public void onReady(Challenge chall);
 
 
     public void   startLocalisation();
@@ -20,6 +22,7 @@ public interface ChallengeDriver extends ChallengeFragment.OnFragmentInteraction
     public void   pauseLocalisation();
     public double getDistanceWith(Area a);
     public double getAccuracy();
+    public void   startResource(Resource r);
 
 
     public void setVisibilityView(int res, int state);
@@ -28,4 +31,7 @@ public interface ChallengeDriver extends ChallengeFragment.OnFragmentInteraction
     public void setFinished();
     public void setFailed();
 
+
+
+    //TODO: Sauvegarde dans le prototype
 }

+ 1 - 1
app/src/main/java/app/mar/activities/ChallengeFragment.java

@@ -225,7 +225,7 @@ public abstract class ChallengeFragment extends Fragment {
 
     protected void ready()
     {
-        getDriver().onReady();
+        getDriver().onReady(getDriver().currentChallenge());
     }
 
     @Override

+ 44 - 91
app/src/main/java/app/mar/activities/HostActivity.java

@@ -20,6 +20,7 @@ import app.mar.game.Resource;
 import app.mar.game.Stage;
 import app.mar.game.challenges.Challenge;
 import app.mar.game.challenges.Indice;
+import app.mar.game.scheduler.Scheduler;
 import app.mar.utils.AndroidResources;
 import app.mar.utils.L;
 
@@ -37,13 +38,9 @@ public class HostActivity extends Activity implements ChallengeDriver{
     protected QRCodeFragment mQRCodeFragment;
     protected QuestionFragment mQuestionFragment;
     protected ChallengeFragment mCurrentFragment;
-    protected boolean isFirstRessrouceViewed=true;
+    protected Challenge mCurrentChallenge;
 
-    private static int sViewerDepth=0;
-
-    public static void decViewerDepth() {  sViewerDepth--;   }
-    public static void incViewerDepth() {  sViewerDepth++;   }
-    private static final int ACTIVITY_RESULT_RESOURCE_VIEWER = 1;
+    private static final int ACTIVITY_RESULT_RESOURCE_VIEWER_SCHEDULER = 2;
 
     private Runnable mTimerTick = new Runnable() {
         public void run() {
@@ -88,15 +85,22 @@ public class HostActivity extends Activity implements ChallengeDriver{
 
         updateCode();
 
-        if(mGame.isFirstChallenge()) {
-            mGame.getCurrentStage().execStartEvent(this, mGame);
+        if(mGame.getCurrentStageIndex()<0) { //noueau jeu
+            mGame.nextStage(this);
+            mGame.getScheduler().schedule(this, mGame);
+        }else
+        {
+            //TODO: Chargement de la sauvegarde
         }
-        startChallenge();
+
+
 
     }
 
-    public   void setFragment(Class type)
+    public   void setFragment(Challenge c)
     {
+        Class type = c.getStartWith();
+        mCurrentChallenge=c;
         ChallengeFragment f = null;
 
         if(type.isInstance(mQCMFragment))
@@ -119,13 +123,12 @@ public class HostActivity extends Activity implements ChallengeDriver{
         }
         else
         {
-            onReady();
+            onReady(c);
         }
     }
 
     @Override
-    public void onReady() {
-        Challenge chall = mGame.getCurrentChallenge(this);
+    public void onReady(Challenge chall) {
         mCurrentFragment.initChallenge(chall);
     }
 
@@ -143,9 +146,7 @@ public class HostActivity extends Activity implements ChallengeDriver{
 
 
     @Override
-    public void onFragmentInteraction(Uri uri) {
-
-    }
+    public void onFragmentInteraction(Uri uri) {}
 
 
     private void timerCallback()
@@ -212,79 +213,59 @@ public class HostActivity extends Activity implements ChallengeDriver{
             setVisibilityView(res[i], state);
     }
 
-    public void nextChallenge() {
-        Stage s = mGame.getCurrentStage();
-
-        //on lance levenemnt de fin du challenge precedent
-        if(mGame.getCurrentChallenge(this)!=null && !mGame.isFirstChallenge())
-            mGame.getCurrentChallenge(this).execEndEvent(this, mGame);
+    public Challenge nextChallenge() {
 
-        Challenge c = s.nextChallenge(this, mGame);
+        Challenge c = mGame.nextChallenge(this);
+        Stage s = mGame.getCurrentStage();
+        Log.e("___SCHEDULER_PRESQUE","\t->"+ c);
         if(c!=null)
         {
-            startChallenge();
-            Log.i("----", "Continue challenge in stage");
-        }else //new stage
+            mGame.getScheduler().append(c);
+        }else if(s!=null) //new stage
         {
             Log.i("----", "New Stage !");
             mGame.getBomb().addKnownCharacter(s.getCharIndex());
             updateCode();
-            if(mGame.nextStage(this)!=null) { // il reste au moins une étape
-                startChallenge();
-            }
-            else //c'est fini
-            {
-                startResourceFound();
-                //setFinished();
-            }
-
+        }else{
+            mGame.getScheduler().appendFinished();
         }
+        return c;
     }
 
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (requestCode == ACTIVITY_RESULT_RESOURCE_VIEWER) {
-            startResourceFound();
-        }
-    }
-
-    private boolean startResourceFound()
-    {
-        if(isFirstRessrouceViewed && !mGame.isFirstChallenge())
+        if(requestCode == ACTIVITY_RESULT_RESOURCE_VIEWER_SCHEDULER)
         {
-            isFirstRessrouceViewed=false;
-            if( mGame.getCurrentChallenge(this)!=null)
-                mGame.getCurrentChallenge(this).execStartEvent(this, mGame);
-        }
-        Resource r = mGame.popLastResource();
+            mGame.getScheduler().schedule(this, mGame);
 
-        if(r!=null )
-        {
-            Intent intent = AndroidResources.getViewerIntent(this, r);
-            incViewerDepth();
-            startActivityForResult(intent, ACTIVITY_RESULT_RESOURCE_VIEWER);
-            return true;
-        }else //plus de ressources a montrer
-        {
-            Challenge c = mGame.getCurrentChallenge(this);
-            if(c!=null) c.execStartEvent(this, mGame);
-            isFirstRessrouceViewed=true;
-            return false;
+            //TODO: Sauvegarde
         }
+    }
 
-
+    public void startResource(Resource r)
+    {
+        Intent intent = AndroidResources.getViewerIntent(this, r);
+        startActivityForResult(intent, ACTIVITY_RESULT_RESOURCE_VIEWER_SCHEDULER);
     }
 
+
     @Override
     public void challengeValidate(Challenge c, Game g, ChallengeDriver dri) {
-        c.setDone(dri, g);
         mGame.getBomb().addKnownCharacter(c.getCharIndex());
         updateCode();
         nextChallenge();
+
+        /////////////////
+
+        /////////////////
+
+        //TODO: Sauvegarde
+
+        mGame.getScheduler().schedule(this, mGame);
     }
 
     public Challenge currentChallenge() {
-        return mGame.getCurrentChallenge(this);
+        return mCurrentChallenge;
     }
 
     public void setFinished()
@@ -301,34 +282,6 @@ public class HostActivity extends Activity implements ChallengeDriver{
         finish();
     }
 
-    private boolean startChallenge()
-    {
-        boolean b=false;
-        int res[] = {R.id.btn_indice, R.id.btn_valid, R.id.btn_videos};
-        for(int i=0; i<res.length; i++)
-        {
-            View v = findViewById(res[i]);
-            v.setVisibility(View.VISIBLE);
-        }
-
-        startResourceFound();
-
-        Challenge c = mGame.getCurrentChallenge(this);
-
-        if(c==null) //fin du stage
-        {
-            mGame.nextStage(this);
-        }
-
-        if(c!=null) {
-            c.exec(mGame,this);
-            b=true;
-        }
-
-        nextChallenge();
-        return b;
-    }
-
     @Override
     public void startLocalisation() {
         mGame.newSensorManager(this);

+ 0 - 2
app/src/main/java/app/mar/activities/MediaViewerAcitvity.java

@@ -112,14 +112,12 @@ public class MediaViewerAcitvity extends AppCompatActivity implements MediaPlaye
 
     public void onOk(View v)
     {
-        HostActivity.decViewerDepth();
         setResult(RESULT_OK, new Intent());
         finish();
     }
 
     @Override
     public void onBackPressed() {
-        HostActivity.decViewerDepth();
         setResult(RESULT_OK, new Intent());
         super.onBackPressed();
     }

+ 5 - 26
app/src/main/java/app/mar/activities/MenuActivity.java

@@ -97,46 +97,25 @@ public  class  MenuActivity extends Activity implements View.OnClickListener {
         mRootLayout = (RelativeLayout) findViewById(R.id.menu_root);
         if(Game.game()==null)
         {
-            Game g = null;// Game.load(this);
-            if (g != null && mGame == null) {
+            Game g = Game.load(this);
+            if (g != null ) {
                 mGame = g;
                 Game.setGame(mGame);
                 mGame.newSensorManager(this);
-                Toast.makeText(this, "Chargement", Toast.LENGTH_LONG).show();
-            } else if (mGame == null) {
+                Toast.makeText(this, "Chargement", Toast.LENGTH_SHORT).show();
+            } else {
                 mGame = new Game("game_medium", this);
                 Game.setGame(mGame);
-                Toast.makeText(this, "Nouveau Jeu", Toast.LENGTH_LONG).show();
-            } else if (mGame == null) {
-                Toast.makeText(this, "Erreur", Toast.LENGTH_LONG).show();
-                throw new Error("Le jeu n'est pas sauvegardé");
+                Toast.makeText(this, "Nouveau Jeu", Toast.LENGTH_SHORT).show();
             }
         }
 
-
-
-
-
         updateSize();
-        //Settings.setSettings(mGame.getSettings());
-
-
-        ////// A virer dela
-
-        //startChallenge();
 
         Intent intent = new Intent(this, HostActivity.class);
         startActivity(intent);
         finish();
 
-        ////////////////////////////////////////////////////////////////////
-
-
-
-
-        /// a dela
-
-
         setUpMenuStyle();
         refreshMenuStyle();
 

+ 3 - 3
app/src/main/java/app/mar/activities/QCMFragment.java

@@ -93,7 +93,6 @@ public class QCMFragment extends ChallengeFragment {
     public void onInitChallenge(Challenge c) {
         mUIGoupQCM.removeAllViews();
 
-
         super.onInitChallenge(c);
         if (c instanceof QCM) {
             mQCM = (QCM) c;
@@ -110,13 +109,14 @@ public class QCMFragment extends ChallengeFragment {
             }
 
         } else {
-            Toast.makeText(getActivity(), "Error l'entrée n'est pas une question ! ", Toast.LENGTH_LONG).show();
+            Toast.makeText(getActivity(), "Error l'entrée n'est pas une question ! : "+c.getClass().getName(), Toast.LENGTH_LONG).show();
         }
     }
 
     @Override
     protected void onResetUi() {
-
+        mUIGoupQCM.clearCheck();
+        getDriver().setVisibilityView(R.id.btn_valid, View.VISIBLE);
     }
 
 }

+ 1 - 0
app/src/main/java/app/mar/activities/QRCodeFragment.java

@@ -124,6 +124,7 @@ public class QRCodeFragment extends ChallengeFragment  implements
         if(mUIGlobalIndice2!=null) {
             mUIGlobalIndice2.setVisibility(View.GONE);
         }
+        getDriver().setVisibilityView(R.id.btn_valid, View.INVISIBLE);
     }
 
     @Override

+ 1 - 1
app/src/main/java/app/mar/game/Bomb.java

@@ -113,7 +113,7 @@ public class Bomb implements Serializable{
 
     public void setSecondsBeforeBoom(long s)
     {
-        mDeadLine=(s+Calendar.getInstance().getTimeInMillis())*1000;
+        mDeadLine=(s*1000+Calendar.getInstance().getTimeInMillis());
     }
 
     public boolean hasExplosed()

+ 15 - 1
app/src/main/java/app/mar/game/Event.java

@@ -73,11 +73,15 @@ public class Event implements Serializable {
     {
         try {
             mMethod = j.getString("method");
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+
+        try {
             JSONArray arr  = j.getJSONArray("args");
             for(int i=0; i<arr.length(); i++)
                 mArgs.add(new EventParam(arr.get(i)));
         } catch (JSONException e) {
-            e.printStackTrace();
         }
     }
 
@@ -129,7 +133,11 @@ public class Event implements Serializable {
     {
         long time = g.getBomb().getSecondsBeforeBoom();
         long seuil = argAsInt(0, 15) * 60;
+        Log.e("___PARAM___", "Seuil = "+seuil+" secondes");
+        Log.e("___PARAM___", "Ancien temps = "+time+" secondes");
         long newTime = (time>seuil)?seuil:time;
+        Log.e("___PARAM___", "Nouveau temps = "+newTime+" secondes");
+        Log.e("___PARAM___", " ");
         g.getBomb().setSecondsBeforeBoom(newTime);
         return new EventReturn(0,"OK");
     }
@@ -142,5 +150,11 @@ public class Event implements Serializable {
         return new EventReturn(0,"OK");
     }
 
+    public String getMethod() {
+        return mMethod;
+    }
 
+    public ArrayList<EventParam> getArgs() {
+        return mArgs;
+    }
 }

+ 61 - 76
app/src/main/java/app/mar/game/Game.java

@@ -20,6 +20,7 @@ import app.mar.activities.ChallengeDriver;
 import app.mar.game.challenges.Challenge;
 import app.mar.game.challenges.ChallengeReturn;
 import app.mar.game.challenges.Treasure;
+import app.mar.game.scheduler.Scheduler;
 import app.mar.utils.SensorsManager;
 import app.mar.utils.Settings;
 import app.mar.utils.files.JSONAssetsManager;
@@ -34,19 +35,19 @@ public class Game  implements Serializable {
     protected ArrayList<Resource>   mResourceQueue = new ArrayList<Resource>();
     protected ArrayList<Stage> mStages = new ArrayList<Stage>();
     protected Stage            mCurrentStage=null;
-    protected int              mCurrentStageIndex=0;
+    protected int              mCurrentStageIndex=-1;
 
     protected Player           mPlayer;
     protected Settings         mSettings = new Settings();
-    protected String           mMap=null;
     protected Inventaire       mInventaire;
+    protected Scheduler        mSched = new Scheduler();
 
-    protected ArrayList<Event> mEventQueue = new ArrayList<Event>();
 
     protected ResourceManager mResources = ResourceManager.newInstance();
     protected ChallengeReturn mLastReturn = null;
 
     protected Bomb            mBomb;
+    protected boolean         mIsLoad=false;
 
 
     public Game(String name, Activity act)
@@ -63,20 +64,14 @@ public class Game  implements Serializable {
             e.printStackTrace();
         }
 
-        try {
-            mMap=root.getString("map");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
 
         try {
             mBomb=new Bomb(root.getString("password"), root.getInt("max_time"));
-            //mBomb.arm();
         } catch (JSONException e) {
             e.printStackTrace();
         }
 
-        mCurrentStageIndex=0;
+        mCurrentStageIndex=-1;
         if(mStages.size()>0)
             mCurrentStage=mStages.get(0);
 
@@ -94,41 +89,25 @@ public class Game  implements Serializable {
         return mCurrentStage;
     }
 
-    public boolean isFirstChallenge()
-    {
-        return mCurrentStageIndex==0 && mCurrentStage.getStep()==0;
-    }
 
-    public void scheduleEventStartStage()
-    {
 
-    }
-
-    public void scheduleEventEndStage()
+    public Challenge getCurrentChallenge()
     {
-
-    }
-
-    public void scheduleEventEndChallenge()
-    {
-
-    }
-
-    public void scheduleEventStartChallenge()
-    {
-
+        if(mCurrentStage==null) return null;
+        Challenge c = mCurrentStage.getCurrentChallenge();
+        return c;
     }
 
-
-    public Challenge getCurrentChallenge(ChallengeDriver cd)
+    public Challenge nextChallenge(ChallengeDriver cd)
     {
         if(mCurrentStage==null) return null;
-        Challenge c = mCurrentStage.getCurrentChallenge();
-        /* if(c==null)
+        mCurrentStage.nextChallenge(cd, this);
+        Challenge c = getCurrentChallenge();
+        if(c==null)
         {
             nextStage(cd);
-            return getCurrentChallenge(cd);
-        }*/
+            return null;
+        }
         return c;
     }
 
@@ -137,23 +116,12 @@ public class Game  implements Serializable {
         return mResources.get(res);
     }
 
-    public Resource popLastResource()
-    {
-        if(mResourceQueue.size()>0)
-        {
-            Resource x = mResourceQueue.get(0);
-            mResourceQueue.remove(0);
-            return x;
-        }
-        return null;
-    }
 
     public void registerResource(String name, Activity act)
     {
         mResources.addResource(name, act);
     }
 
-
     public Settings getSettings(){return mSettings;}
     public void setSettings(Settings s){ mSettings=s;}
 
@@ -212,6 +180,7 @@ public class Game  implements Serializable {
             Game obj = (Game) is.readObject();
             is.close();
             fis.close();
+            obj.mIsLoad=true;
             return obj;
         } catch (Exception e) {
             e.printStackTrace();
@@ -275,21 +244,17 @@ public class Game  implements Serializable {
      */
     synchronized public void precache3DResource(Activity contecxt)
     {
-        Challenge c = getCurrentChallenge((ChallengeDriver)contecxt);
+        Challenge c = getCurrentChallenge();
         if(c instanceof Treasure)
         {
-
         }
     }
 
-
-
-
     /**
      *
      * renvoie la liste des ressources sur lesquelles le joueur est présent
      * @return la liste des ressources sur lesquelles le joueur est présent
-     */
+
     public ArrayList<Resource> getResourcesNextToPlayer(Area a)
     {
         ArrayList<Resource> r = new ArrayList<Resource>();
@@ -299,18 +264,18 @@ public class Game  implements Serializable {
             r.add(findResource(rs.get(i)));
 
         return r;
-    }
+    }*/
 
     public Player getPlayer()
     {
         return mPlayer;
     }
 
-
+/*
     public void removeCached3DModels()
     {
         mResources.deleteAll3DModel();
-    }
+    }*/
 
     public void newSensorManager(Activity act)
     {
@@ -319,8 +284,6 @@ public class Game  implements Serializable {
             mSettings.setARMode(false);
     }
 
-
-
     public void restartSensors()
     {
         mPlayer.getSensorsManager().restartSensors();
@@ -331,8 +294,6 @@ public class Game  implements Serializable {
         mPlayer.getSensorsManager().stopSensors();
     }
 
-
-
     public static void setGame(Game m)
     {
         gGame=m;
@@ -342,39 +303,55 @@ public class Game  implements Serializable {
     {
         return gGame;
     }
-
-
-
+/*
     public boolean hasResource(String name)
     {
         return mResources.contains(name);
-    }
+    }*/
     
-
+/*
     public ChallengeReturn getReturn() {
         return mLastReturn;
     }
 
     public void setReturn(ChallengeReturn mLastReturn) {
         this.mLastReturn = mLastReturn;
-    }
+    }*/
 
     public Stage nextStage(ChallengeDriver cd) {
         mCurrentStageIndex++;
         if(mCurrentStageIndex<=mStages.size())
         {
-            mStages.get(mCurrentStageIndex-1).execEndEvent(cd, this);
-
-
-            ArrayList<Resource> res = mCurrentStage.getResources();
-            mInventaire.addResource(res);
-
-            for(int i=0; i<res.size(); i++)
-                mResourceQueue.add(res.get(i));
-
+            //MAJ currentStage
             if(mStages.size()==mCurrentStageIndex) return mCurrentStage=null;
-            return mCurrentStage=mStages.get(mCurrentStageIndex);
+            mCurrentStage=mStages.get(mCurrentStageIndex);
+
+
+            //ajoute des taches du stage precedents
+            if(mCurrentStageIndex>0) {
+                //ajout des ressources gagnés
+                ArrayList<Resource> res = mStages.get(mCurrentStageIndex - 1).getResources();
+                mInventaire.addResource(res);
+                mSched.append(res);
+
+                //ajout des events de fin
+                mSched.append(mStages.get(mCurrentStageIndex - 1).getEndEvent());
+            }
+
+            //Ajout de la tache
+            mSched.append( mStages.get(mCurrentStageIndex).getStartEvent());
+
+            //si l'étape n'a pas de challenge on relance la fonction
+            if(mCurrentStage.getStepCount()==0)
+                return nextStage(cd);
+            else //sinon on ajoute le prmeier challenge
+            {
+                nextChallenge(cd);
+                mSched.append(getCurrentChallenge());
+            }
+            return mCurrentStage;
         }
+        mSched.appendFinished();
         return mCurrentStage=null;
     }
 
@@ -385,4 +362,12 @@ public class Game  implements Serializable {
     public Inventaire getInventaire() {
         return mInventaire;
     }
+
+    public int getCurrentStageIndex() {
+        return mCurrentStageIndex;
+    }
+
+    public Scheduler getScheduler(){
+        return mSched;
+    }
 }

+ 10 - 22
app/src/main/java/app/mar/game/Stage.java

@@ -18,7 +18,7 @@ public class Stage  implements Serializable {
     protected ArrayList<Challenge> mChallenge = new ArrayList<Challenge>();
     protected ArrayList<Resource> mResources = new ArrayList<Resource>();
     protected boolean mDone=false;
-    protected int     mStep=0;
+    protected int     mStep=-1;
     protected int   mCharIndex=-1;
 
     protected ArrayList<Event> mStartEvent = new ArrayList<Event>();
@@ -96,24 +96,7 @@ public class Stage  implements Serializable {
     }
 
 
-    private void execEvent(ArrayList<Event> e, Game g, ChallengeDriver dri)
-    {
-        for(int i=0; i<e.size(); i++)
-            e.get(i).exec(dri, g);
-    }
-
-    public void execStartEvent(ChallengeDriver dri, Game g)
-    {
-
-        Log.e("___DEBUG_EXEC___", "Stage exec start '"+mName+"' : "+mCharIndex);
-        execEvent(mStartEvent, g, dri);
-    }
 
-    public void execEndEvent(ChallengeDriver dri, Game g)
-    {
-        Log.e("___DEBUG_EXEC___", "Stage exec end '"+mName+"' : "+mCharIndex);
-        execEvent(mEndEvent, g, dri);
-    }
 
     public int getCharIndex() {return mCharIndex; }
 
@@ -142,7 +125,6 @@ public class Stage  implements Serializable {
         this.mDone = mDone;
     }
 
-    public Stage start(ChallengeDriver dri, Game g) { execStartEvent(dri, g); return this;}
 
     public int getStep() {
         return mStep;
@@ -152,13 +134,12 @@ public class Stage  implements Serializable {
         return mChallenge.size();
     }
 
-    public Challenge nextChallenge(ChallengeDriver dri, Game g)
+    Challenge nextChallenge(ChallengeDriver dri, Game g)
     {
-        if(mStep==0) start(dri, g);
         mStep++;
         if(mStep<mChallenge.size())
             return mChallenge.get(mStep);
-        execEndEvent(dri, g);
+
         return null;
     }
 
@@ -175,4 +156,11 @@ public class Stage  implements Serializable {
         return null;
     }
 
+    public ArrayList<Event> getStartEvent() {
+        return mStartEvent;
+    }
+
+    public ArrayList<Event> getEndEvent() {
+        return mEndEvent;
+    }
 }

+ 13 - 37
app/src/main/java/app/mar/game/challenges/Challenge.java

@@ -27,7 +27,6 @@ public abstract class Challenge implements Serializable{
 
     protected char mCharPassword;
     protected int  mCharPasswordIndex;
-    protected boolean mDone=false;
     protected Class  mStartWith = null;
     protected ArrayList<Indice> mIndices = new ArrayList<Indice>();
     protected int mLastIndiceDiscoveredIndex = 0;
@@ -41,7 +40,6 @@ public abstract class Challenge implements Serializable{
     public Challenge(Game g, JSONObject root, Class start, Activity act)
     {
         mStartWith=start;
-        mDone = false;
         try {
             mType = root.getString("type");
         } catch (JSONException e) {
@@ -118,26 +116,10 @@ public abstract class Challenge implements Serializable{
         }
     }
 
-    private void execEvent(ArrayList<Event> e, ChallengeDriver a, Game g)
-    {
-        for(int i=0; i<e.size(); i++)
-            e.get(i).exec(a,g);
-    }
-
-    public void execStartEvent(ChallengeDriver a,Game g)
-    {
-        Log.e("___DEBUG_EXEC___", "Challenge exec start '"+mName+"'");
-        execEvent(mStartEvent, a, g);
-    }
-    public void execEndEvent(ChallengeDriver a,Game g)
-    {
-        Log.e("___DEBUG_EXEC___", "Challenge exec end '"+mName+"'");
-        execEvent(mEndEvent,a, g);
-    }
 
     public void exec(Game g, ChallengeDriver act)
     {
-        act.setFragment(mStartWith);
+        act.setFragment(this);
     }
 
     public String getType() {
@@ -148,19 +130,9 @@ public abstract class Challenge implements Serializable{
         return mName;
     }
 
-    public abstract int getResultCode();
-
-    public boolean isDone() {
-        return mDone;
-    }
 
     public int getCharIndex() {return mCharIndex; }
 
-    public void setDone(ChallengeDriver a, Game g)
-    {
-        mDone=true;
-        execEndEvent(a, g);
-    }
 
     public static Class getChallengeClass(String classe)
     {
@@ -201,14 +173,6 @@ public abstract class Challenge implements Serializable{
         return null;
     }
 
-    public char getCharPassword() {
-        return mCharPassword;
-    }
-
-    public int getCharPasswordIndex() {
-        return mCharPasswordIndex;
-    }
-
     public boolean hasNextIndice()
     {
         int i=0;
@@ -237,4 +201,16 @@ public abstract class Challenge implements Serializable{
     public String getResourceName() {
         return mResource;
     }
+
+    public ArrayList<Event> getStartEvent() {
+        return mStartEvent;
+    }
+
+    public ArrayList<Event> getEndEvent() {
+        return mEndEvent;
+    }
+
+    public Class getStartWith(){
+        return mStartWith;
+    }
 }

+ 31 - 0
app/src/main/java/app/mar/game/scheduler/ChallengeTask.java

@@ -0,0 +1,31 @@
+package app.mar.game.scheduler;
+
+import app.mar.activities.ChallengeDriver;
+import app.mar.game.Game;
+import app.mar.game.challenges.Challenge;
+
+public class ChallengeTask extends Task {
+
+    protected Challenge mChallenge;
+
+
+    public String toString()
+    {
+        return "[ Challenge, '"+mChallenge.getType()+"',  '"+mChallenge.getName()+"' ]";
+    }
+
+    public ChallengeTask(Challenge g) {
+        super(TASK_CHALLENGE);
+        mChallenge = g;
+    }
+
+    @Override
+    public int exec(Scheduler s, ChallengeDriver cd, Game g) {
+        mChallenge.exec(g, cd);
+        return TASK_CHALLENGE;
+    }
+
+    public Challenge getChallenge() {
+        return mChallenge;
+    }
+}

+ 42 - 0
app/src/main/java/app/mar/game/scheduler/EndTask.java

@@ -0,0 +1,42 @@
+package app.mar.game.scheduler;
+
+import app.mar.activities.ChallengeDriver;
+import app.mar.game.Game;
+
+public class EndTask extends Task {
+
+    public static final int STATE_FINISHED_SUCESS=1;
+    public static final int STATE_FINISHED_FAILED=2;
+    public static final int STATE_BOMB=3;
+
+    protected int mState;
+
+    public EndTask(int x) {
+        super(TASK_END);
+        mState=x;
+    }
+
+    private static final String[] gStrings={"STATE_NONE", "STATE_FINISHED_SUCESS",
+                                              "STATE_FINISHED_FAILED", "STATE_FINISHED_FAILED" };
+
+    public String toString()
+    {
+        return "[ End, "+gStrings[mState]+" ]";
+    }
+
+    @Override
+    public int exec(Scheduler s, ChallengeDriver cd, Game g) {
+        switch(mState)
+        {
+            case STATE_FINISHED_SUCESS:
+                cd.setFinished();
+                break;
+            case STATE_FINISHED_FAILED:
+                cd.setFailed();
+                break;
+            case STATE_BOMB:
+                break;
+        }
+        return TASK_END;
+    }
+}

+ 32 - 0
app/src/main/java/app/mar/game/scheduler/EventTask.java

@@ -0,0 +1,32 @@
+package app.mar.game.scheduler;
+
+
+import app.mar.activities.ChallengeDriver;
+import app.mar.game.Event;
+import app.mar.game.Game;
+
+public class EventTask extends Task {
+    protected Event mEvent;
+
+    public EventTask(Event e) {
+        super(TASK_EVENT);
+        mEvent = e;
+    }
+
+
+    public String toString()
+    {
+        return "[ Event, '"+mEvent.getMethod()+"' ]";
+    }
+
+    @Override
+    public int exec(Scheduler s, ChallengeDriver cd, Game g) {
+        mEvent.exec(cd, g);
+        //TODO: Sauvegarde
+        return s.schedule(cd, g);
+    }
+
+    public Event getEvent() {
+        return mEvent;
+    }
+}

+ 31 - 0
app/src/main/java/app/mar/game/scheduler/ResourceTask.java

@@ -0,0 +1,31 @@
+package app.mar.game.scheduler;
+
+import app.mar.activities.ChallengeDriver;
+import app.mar.game.Game;
+import app.mar.game.Resource;
+
+public class ResourceTask extends Task {
+
+    protected Resource mResource;
+
+    public ResourceTask(Resource r) {
+        super(TASK_RESOURCE);
+        mResource =r;
+    }
+
+
+    public String toString()
+    {
+        return "[ Resource, '"+mResource.getName()+"' ]";
+    }
+
+    @Override
+    public int exec(Scheduler s, ChallengeDriver cd, Game g) {
+        cd.startResource(mResource);
+        return TASK_RESOURCE;
+    }
+
+    public Resource getResource() {
+        return mResource;
+    }
+}

+ 86 - 0
app/src/main/java/app/mar/game/scheduler/Scheduler.java

@@ -0,0 +1,86 @@
+package app.mar.game.scheduler;
+
+import android.util.Log;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import app.mar.activities.ChallengeDriver;
+import app.mar.game.Event;
+import app.mar.game.Game;
+import app.mar.game.Resource;
+import app.mar.game.challenges.Challenge;
+
+
+public class Scheduler implements Serializable {
+
+    protected Task mStart;
+    protected Task mLastTask;
+
+    public Scheduler() {
+    }
+
+    public String toString()
+    {
+        String out = "[ ";
+        Task t = mStart;
+        for(t=mStart; t!=null; t=t.next()) {
+            if(t!=mStart) out+=", ";
+            out+=t.toString();
+        }
+        return out+" ]";
+    }
+
+    private void append(Task t)
+    {
+        Log.e("___SCHEDULER_DEBUG___AP", "Ajout de : "+t.toString()+" : "+toString());
+        if(mStart==null) mStart=t;
+        else mStart.enqueue(t);
+    }
+
+    public void append(Challenge c)
+    {
+        ArrayList<Event> a = c.getStartEvent();
+        ArrayList<Event> b = c.getEndEvent();
+
+        append(a);
+        append(new ChallengeTask(c));
+        append(b);
+    }
+
+
+    public void append(Resource c){ append(new ResourceTask(c));}
+    public void append(Event c){ append(new EventTask(c));}
+    public void appendFinished(){ append(new EndTask(EndTask.STATE_FINISHED_SUCESS));}
+    public void appendFailed(){ append(new EndTask(EndTask.STATE_FINISHED_FAILED));}
+    public void appendBomb(){ append(new EndTask(EndTask.STATE_BOMB));}
+    public void append(ArrayList<?> cc) {
+        ArrayList<Object> c = (ArrayList<Object>) cc;
+        for(int i=0; i<c.size(); i++)
+            if(c.get(i) instanceof Resource)
+                append(new ResourceTask((Resource)c.get(i)));
+            else if(c.get(i) instanceof Event)
+                append(new EventTask((Event)c.get(i)));
+    }
+
+    public int schedule(ChallengeDriver cd, Game g)
+    {
+        Task t = mStart;
+        mLastTask=t;
+        if(t!=null)
+        {
+            mStart=mStart.next();
+            Log.e("___SCHEDULER_DEBUG___", "Executing task : "+t.toString());
+            return t.exec(this, cd, g);
+        }
+        return Task.TASK_NONE;
+    }
+
+    public ArrayList<Task> getTaskList()
+    {
+        ArrayList<Task> at = new ArrayList<Task>();
+        for(Task t=mStart; t!=null ;t=mStart.next())
+            at.add(t);
+        return at;
+    }
+}

+ 50 - 0
app/src/main/java/app/mar/game/scheduler/Task.java

@@ -0,0 +1,50 @@
+package app.mar.game.scheduler;
+
+import java.io.Serializable;
+
+import app.mar.activities.ChallengeDriver;
+import app.mar.game.Game;
+
+public abstract class Task implements Serializable {
+    public final static int TASK_NONE=0;
+    public final static int TASK_CHALLENGE=1;
+    public final static int TASK_EVENT=2;
+    public final static int TASK_RESOURCE=3;
+    public final static int TASK_END=4;
+
+    protected int mType;
+    protected Task mNext=null;
+
+    public Task(int type){ mType=type;}
+
+    public abstract int exec(Scheduler s, ChallengeDriver cd, Game g);
+
+
+    public Task end()
+    {
+        Task t = this;
+        while(t.mNext!=null) t=t.mNext;
+        return t;
+    }
+
+    public void insertAfter(Task t)
+    {
+        Task tt = mNext;
+        mNext=t;
+        Task e = mNext.end();
+        e.mNext=tt;
+    }
+
+    public void enqueue(Task t)
+    {
+        Task e = end();
+        e.insertAfter(t);
+    }
+
+    public Task next()
+    {
+        return mNext;
+    }
+
+
+}