|
@@ -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;
|
|
|
+ }
|
|
|
}
|