|
@@ -1,8 +1,10 @@
|
|
package app.mar.utils.game;
|
|
package app.mar.utils.game;
|
|
|
|
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
|
|
+import android.app.admin.SystemUpdatePolicy;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONException;
|
|
@@ -35,7 +37,7 @@ public class Game implements Serializable {
|
|
protected int mNStages;
|
|
protected int mNStages;
|
|
protected int mCurrentStage=0;
|
|
protected int mCurrentStage=0;
|
|
protected Player mPlayer;
|
|
protected Player mPlayer;
|
|
- protected ResourceManager mResources;
|
|
|
|
|
|
+ public ResourceManager mResources;
|
|
protected String mName;
|
|
protected String mName;
|
|
protected Settings mSettings = new Settings();
|
|
protected Settings mSettings = new Settings();
|
|
protected boolean mFinished= false;
|
|
protected boolean mFinished= false;
|
|
@@ -76,16 +78,29 @@ public class Game implements Serializable {
|
|
findMaxStage();
|
|
findMaxStage();
|
|
mResources.set( getAllResources(), mNStages);
|
|
mResources.set( getAllResources(), mNStages);
|
|
|
|
|
|
-
|
|
|
|
nextStage();
|
|
nextStage();
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
|
|
+ System.err.println("_________________ B\n");
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ System.err.println("_________________ C\n");
|
|
mMap=root.getString("map");
|
|
mMap=root.getString("map");
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ System.err.println("_________________ C\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(!mPlayer.hasMagneticField() || !mPlayer.hasAcceleromter())
|
|
|
|
+ {
|
|
|
|
+ mSettings.setARMode(false);
|
|
|
|
+ if(!mPlayer.hasMagneticField()) Toast.makeText(act, "Votre dispositif n'a pas de boussole. Le mode RA ne peut fonctionner et a été désactivé", Toast.LENGTH_LONG).show();
|
|
|
|
+ else if(!mPlayer.hasAcceleromter()) Toast.makeText(act, "Votre dispositif n'a pas d'accélerometre. Le mode RA ne peut fonctionner et a été désactivé", Toast.LENGTH_LONG).show();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ System.err.println("___________||||| "+mCurrentStageAreas.size());
|
|
}
|
|
}
|
|
|
|
|
|
public Stage getCurrentStageObj()
|
|
public Stage getCurrentStageObj()
|
|
@@ -134,7 +149,7 @@ public class Game implements Serializable {
|
|
mCurrentStage++;
|
|
mCurrentStage++;
|
|
Log.e("------------", "Is Finished : "+mCurrentStage+" > "+mNStages+" = "+(mCurrentStage>mNStages));
|
|
Log.e("------------", "Is Finished : "+mCurrentStage+" > "+mNStages+" = "+(mCurrentStage>mNStages));
|
|
if(mCurrentStage>mNStages) return true;
|
|
if(mCurrentStage>mNStages) return true;
|
|
-
|
|
|
|
|
|
+ System.out.println("La");
|
|
loadStageAreasResources();
|
|
loadStageAreasResources();
|
|
mResources.nextStage(mCurrentStage);
|
|
mResources.nextStage(mCurrentStage);
|
|
|
|
|
|
@@ -149,6 +164,7 @@ public class Game implements Serializable {
|
|
if(mAreas.get(i).getStage() == mCurrentStage)
|
|
if(mAreas.get(i).getStage() == mCurrentStage)
|
|
mCurrentStageAreas.add(mAreas.get(i));
|
|
mCurrentStageAreas.add(mAreas.get(i));
|
|
}
|
|
}
|
|
|
|
+ System.err.println("================================ ICI =======================" + mCurrentStageAreas.size());
|
|
}
|
|
}
|
|
|
|
|
|
public int currentAreasCount()
|
|
public int currentAreasCount()
|
|
@@ -215,18 +231,33 @@ public class Game implements Serializable {
|
|
* @param name Le nom de la ressource
|
|
* @param name Le nom de la ressource
|
|
* @return true si l'étape est finie, sinon false
|
|
* @return true si l'étape est finie, sinon false
|
|
*/
|
|
*/
|
|
- public boolean pickResource(String name)
|
|
|
|
|
|
+ public boolean pickResource(String name, boolean otherRes)
|
|
{
|
|
{
|
|
|
|
|
|
- for (int j = 0; j < mCurrentStageAreas.size(); j++)
|
|
|
|
- if (name.compareTo(mCurrentStageAreas.get(j).getName())==0) {
|
|
|
|
- removeArea(j);
|
|
|
|
- }
|
|
|
|
|
|
+ if(otherRes)
|
|
|
|
+ {
|
|
|
|
+ for (int j = 0; j < mCurrentStageAreas.size(); j++)
|
|
|
|
+ if (name.compareTo(mCurrentStageAreas.get(j).getName())==0) {
|
|
|
|
+ removeArea(j);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
mResources.pickUpResource(name);
|
|
mResources.pickUpResource(name);
|
|
|
|
|
|
return mCurrentStageAreas.size()==0;
|
|
return mCurrentStageAreas.size()==0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Récupere une ressource par son nom, sans besoin de localisation ou d'orientation
|
|
|
|
+ * @param name Le nom de la ressource
|
|
|
|
+ * @return true si l'étape est finie, sinon false
|
|
|
|
+ */
|
|
|
|
+ public boolean pickResource(String name)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ return pickResource(name, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Récupere toutes les ressources du jeu
|
|
* Récupere toutes les ressources du jeu
|
|
*/
|
|
*/
|
|
@@ -249,7 +280,7 @@ public class Game implements Serializable {
|
|
public String toString()
|
|
public String toString()
|
|
{
|
|
{
|
|
String out = "Game : "+super.toString();
|
|
String out = "Game : "+super.toString();
|
|
- out+="mAreas[]:\n";
|
|
|
|
|
|
+ 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";
|
|
@@ -265,6 +296,14 @@ public class Game implements Serializable {
|
|
return out;
|
|
return out;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public String toString2()
|
|
|
|
+ {
|
|
|
|
+ String out = "Game : "+mResources.getResourceLeft()+" : "+mCurrentStageAreas+";";
|
|
|
|
+ ArrayList<Resource> arr= mResources.getResourceLeft();
|
|
|
|
+
|
|
|
|
+ return out+";";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* Sauvegarde la partie (l'objet game)
|
|
* Sauvegarde la partie (l'objet game)
|
|
@@ -326,6 +365,20 @@ public class Game implements Serializable {
|
|
return tmp;
|
|
return tmp;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void pickUpOtherResources()
|
|
|
|
+ {
|
|
|
|
+ ArrayList<Resource> r = mResources.getOtherResource();
|
|
|
|
+ for(int i=0; i<r.size(); i++) {
|
|
|
|
+ pickResource(r.get(i).getName(), false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public ArrayList<Area> getCurrentStageAreas()
|
|
|
|
+ {
|
|
|
|
+ return mCurrentStageAreas;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Teste si le jeu est déja sauvé
|
|
* Teste si le jeu est déja sauvé
|
|
* @param context Le contexte
|
|
* @param context Le contexte
|
|
@@ -333,6 +386,7 @@ public class Game implements Serializable {
|
|
*/
|
|
*/
|
|
public static boolean isSaved(Activity context)
|
|
public static boolean isSaved(Activity context)
|
|
{
|
|
{
|
|
|
|
+
|
|
boolean b = false;
|
|
boolean b = false;
|
|
try {
|
|
try {
|
|
FileInputStream fis = context.openFileInput("data");
|
|
FileInputStream fis = context.openFileInput("data");
|
|
@@ -437,6 +491,7 @@ public class Game implements Serializable {
|
|
public ArrayList<LocatedResources> getResourcesNextToPlayer()
|
|
public ArrayList<LocatedResources> getResourcesNextToPlayer()
|
|
{
|
|
{
|
|
ArrayList<LocatedResources> r = new ArrayList<LocatedResources>();
|
|
ArrayList<LocatedResources> r = new ArrayList<LocatedResources>();
|
|
|
|
+
|
|
for(int i=0; i<mCurrentStageAreas.size(); i++)
|
|
for(int i=0; i<mCurrentStageAreas.size(); i++)
|
|
{
|
|
{
|
|
//probleme de GPS..
|
|
//probleme de GPS..
|
|
@@ -522,6 +577,8 @@ public class Game implements Serializable {
|
|
public void newSensorManager(Activity act)
|
|
public void newSensorManager(Activity act)
|
|
{
|
|
{
|
|
mPlayer.newSensorManager(act);
|
|
mPlayer.newSensorManager(act);
|
|
|
|
+ if(!mPlayer.hasMagneticField() || !mPlayer.hasAcceleromter())
|
|
|
|
+ mSettings.setARMode(false);
|
|
}
|
|
}
|
|
|
|
|
|
public ArrayList< ArrayList<Resource> > getResourceByStage()
|
|
public ArrayList< ArrayList<Resource> > getResourceByStage()
|
|
@@ -556,7 +613,8 @@ public class Game implements Serializable {
|
|
|
|
|
|
public boolean canSendData() {
|
|
public boolean canSendData() {
|
|
Stage s =getCurrentStageObj();
|
|
Stage s =getCurrentStageObj();
|
|
- if(s==null) return false;
|
|
|
|
|
|
+ if(s==null ) return false;
|
|
|
|
+ if(!s.isTransition()) return false;
|
|
return mResources.getNResourceAquiredByStage()>=s.getNResourceStep() && !isFinished();
|
|
return mResources.getNResourceAquiredByStage()>=s.getNResourceStep() && !isFinished();
|
|
//return mResources.getNResourceLeft()<s.getNResourceStep() && !isFinished();
|
|
//return mResources.getNResourceLeft()<s.getNResourceStep() && !isFinished();
|
|
}
|
|
}
|
|
@@ -583,6 +641,6 @@ public class Game implements Serializable {
|
|
Log.e("---------------", " '" + mResources.getResourceLeft().get(i).getName() + "'");
|
|
Log.e("---------------", " '" + mResources.getResourceLeft().get(i).getName() + "'");
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|