|
@@ -28,25 +28,34 @@ import app.brest.utils.Settings;
|
|
*/
|
|
*/
|
|
public class Game implements Serializable {
|
|
public class Game implements Serializable {
|
|
|
|
|
|
- protected ArrayList<Area> mAreas = new ArrayList<Area>();
|
|
|
|
- protected ArrayList<Area> mCurrentStageAreas = new ArrayList<Area>();
|
|
|
|
- protected int mNStages;
|
|
|
|
- protected int mCurrentStage=0;
|
|
|
|
- protected Player mPlayer;
|
|
|
|
- protected ResourceManager mResources;
|
|
|
|
- protected String mName;
|
|
|
|
- protected Settings mSettings = new Settings();
|
|
|
|
|
|
+ protected ArrayList<Area> mAreas = new ArrayList<Area>();
|
|
|
|
+ protected ArrayList<Area> mCurrentStageAreas = new ArrayList<Area>();
|
|
|
|
+ protected ArrayList<Stage> mStages = new ArrayList<Stage>();
|
|
|
|
+ protected int mNStages;
|
|
|
|
+ protected int mCurrentStage=0;
|
|
|
|
+ protected Player mPlayer;
|
|
|
|
+ protected ResourceManager mResources;
|
|
|
|
+ protected String mName;
|
|
|
|
+ protected Settings mSettings = new Settings();
|
|
|
|
|
|
public Game(String name, Activity act)
|
|
public Game(String name, Activity act)
|
|
{
|
|
{
|
|
|
|
+ Log.e("_______", "Nouveau jeu");
|
|
JSONObject root = JSONLoader.load(act, name);
|
|
JSONObject root = JSONLoader.load(act, name);
|
|
mName=name;
|
|
mName=name;
|
|
mPlayer = new Player(act);
|
|
mPlayer = new Player(act);
|
|
try {
|
|
try {
|
|
JSONArray areas = root.getJSONArray("areas");
|
|
JSONArray areas = root.getJSONArray("areas");
|
|
|
|
+ JSONArray stages = root.getJSONArray("stages_list");
|
|
for(int i=0; i<areas.length(); i++)
|
|
for(int i=0; i<areas.length(); i++)
|
|
mAreas.add(new Area(areas.getJSONObject(i), act));
|
|
mAreas.add(new Area(areas.getJSONObject(i), act));
|
|
mResources = new ResourceManager(this, act);
|
|
mResources = new ResourceManager(this, act);
|
|
|
|
+ for(int i=0; i<stages.length(); i++) {
|
|
|
|
+ Stage s = new Stage(stages.getJSONObject(i));
|
|
|
|
+ Resource r = findResource(s.getResourceName());
|
|
|
|
+ s.setResource(r);
|
|
|
|
+ mStages.add(s);
|
|
|
|
+ }
|
|
findMaxStage();
|
|
findMaxStage();
|
|
nextStage();
|
|
nextStage();
|
|
|
|
|
|
@@ -54,6 +63,15 @@ public class Game implements Serializable {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ public Stage getCurrentStageObj()
|
|
|
|
+ {
|
|
|
|
+ return mStages.get(mCurrentStage-1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Stage getStage(int i)
|
|
|
|
+ {
|
|
|
|
+ return mStages.get(i);
|
|
|
|
+ }
|
|
|
|
|
|
public Settings getmSettings(){return mSettings;}
|
|
public Settings getmSettings(){return mSettings;}
|
|
public void setSettings(Settings s){ mSettings=s;}
|
|
public void setSettings(Settings s){ mSettings=s;}
|
|
@@ -124,13 +142,16 @@ public class Game implements Serializable {
|
|
public boolean pickResource()
|
|
public boolean pickResource()
|
|
{
|
|
{
|
|
ArrayList<Resource> r = getResourcesNextToPlayer();
|
|
ArrayList<Resource> r = getResourcesNextToPlayer();
|
|
|
|
+ Log.e("_______", "N Res Left : "+mResources.getNResourceAcquired());
|
|
for(int i=0; i<r.size(); i++) {
|
|
for(int i=0; i<r.size(); i++) {
|
|
for (int j = 0; j < mCurrentStageAreas.size(); j++)
|
|
for (int j = 0; j < mCurrentStageAreas.size(); j++)
|
|
if (r.get(i).getName().compareTo(mCurrentStageAreas.get(j).getName())==0) {
|
|
if (r.get(i).getName().compareTo(mCurrentStageAreas.get(j).getName())==0) {
|
|
removeArea(j);
|
|
removeArea(j);
|
|
}
|
|
}
|
|
- mResources.pickUpResource(r.get(i).getName());
|
|
|
|
|
|
+ pickResource(r.get(i).getName());
|
|
}
|
|
}
|
|
|
|
+ Log.e("_______", "N Res Left : "+mResources.getNResourceAcquired());
|
|
|
|
+ Log.e("_______", toString()+"____________________________\n");
|
|
return mCurrentStageAreas.size()==0;
|
|
return mCurrentStageAreas.size()==0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -151,10 +172,16 @@ public class Game implements Serializable {
|
|
|
|
|
|
public String toString()
|
|
public String toString()
|
|
{
|
|
{
|
|
- String out = "mAreas[]:\n";
|
|
|
|
|
|
+ String out = "Game : "+super.toString();
|
|
|
|
+ out+="mAreas[]:\n";
|
|
for(int i=0; i<mAreas.size(); i++)
|
|
for(int i=0; i<mAreas.size(); i++)
|
|
out+="\tmAres["+i+"] = "+mAreas.get(i).getJson().toString()+"\n";
|
|
out+="\tmAres["+i+"] = "+mAreas.get(i).getJson().toString()+"\n";
|
|
out+="\nmResourcesAcquired[] : \n";
|
|
out+="\nmResourcesAcquired[] : \n";
|
|
|
|
+ for(int i=0; i<mResources.getResourceAquiered().size(); i++) {
|
|
|
|
+ out+="\tmResourcesAcquired["+i+"][] : \n";
|
|
|
|
+ for (int j = 0; j < mResources.getResourceAquiered().get(i).size(); j++)
|
|
|
|
+ out += "\t\tmResourcesAcquired[" + i + "]["+j+"] = " + mResources.getResourceAquiered().get(i).get(j).getJson().toString() + "\n";
|
|
|
|
+ }
|
|
out+="mNStages :" +mNStages +"\n";
|
|
out+="mNStages :" +mNStages +"\n";
|
|
out+="mCurrentStage" + mCurrentStage +"\n";
|
|
out+="mCurrentStage" + mCurrentStage +"\n";
|
|
return out;
|
|
return out;
|
|
@@ -198,7 +225,7 @@ public class Game implements Serializable {
|
|
ArrayList<Resource> tmp = new ArrayList<Resource>();
|
|
ArrayList<Resource> tmp = new ArrayList<Resource>();
|
|
for(int i=0; i<mAreas.size(); i++)
|
|
for(int i=0; i<mAreas.size(); i++)
|
|
if(!tmp.contains(mAreas.get(i)))
|
|
if(!tmp.contains(mAreas.get(i)))
|
|
- tmp.add(mAreas.get(i).getResource(act));
|
|
|
|
|
|
+ tmp.add(mAreas.get(i).getResource());
|
|
return tmp;
|
|
return tmp;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -234,6 +261,14 @@ public class Game implements Serializable {
|
|
mPlayer.setSensorsManager(sm);
|
|
mPlayer.setSensorsManager(sm);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public Resource findResource(String name)
|
|
|
|
+ {
|
|
|
|
+ for(int i=0; i<mAreas.size(); i++)
|
|
|
|
+ if(mAreas.get(i).getResourceName().compareTo(name)==0)
|
|
|
|
+ return mAreas.get(i).getResource();
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Charge la ressource 3d quand on entre dans une zone
|
|
* Charge la ressource 3d quand on entre dans une zone
|
|
*/
|
|
*/
|
|
@@ -266,6 +301,7 @@ public class Game implements Serializable {
|
|
{
|
|
{
|
|
//probleme de GPS..
|
|
//probleme de GPS..
|
|
boolean b = mCurrentStageAreas.get(i).isOnArea(mPlayer);
|
|
boolean b = mCurrentStageAreas.get(i).isOnArea(mPlayer);
|
|
|
|
+
|
|
if(b)
|
|
if(b)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -325,5 +361,8 @@ public class Game implements Serializable {
|
|
{
|
|
{
|
|
mPlayer.getSensorsManager().stopSensors();
|
|
mPlayer.getSensorsManager().stopSensors();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ public void printNResource(String str)
|
|
|
|
+ {
|
|
|
|
+ Log.e("_______", str+" : "+mResources.getNResourceAcquired());
|
|
|
|
+ }
|
|
}
|
|
}
|