|
@@ -2,7 +2,6 @@ package app.brest.utils.app.brest.game;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
-import android.content.SharedPreferences;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
@@ -24,7 +23,6 @@ import app.brest.utils.JSONLoader;
|
|
|
import app.brest.utils.ResourceManager;
|
|
|
import app.brest.utils.SensorsManager;
|
|
|
import app.brest.utils.Settings;
|
|
|
-import app.brest.utils.geometry.Point;
|
|
|
|
|
|
/**
|
|
|
* Created by ptitcois on 19/08/16.
|
|
@@ -41,7 +39,6 @@ public class Game implements Serializable {
|
|
|
protected String mName;
|
|
|
protected Settings mSettings = new Settings();
|
|
|
protected boolean mFinished= false;
|
|
|
-
|
|
|
public Game(String name, Activity act)
|
|
|
{
|
|
|
JSONObject root = JSONLoader.load(act, name);
|
|
@@ -144,20 +141,25 @@ public class Game implements Serializable {
|
|
|
|
|
|
public boolean pickResource()
|
|
|
{
|
|
|
- ArrayList<LocatedResource> r = getResourcesNextToPlayer();
|
|
|
+ mResources.clearPickedUpResources();
|
|
|
+ ArrayList<LocatedResources> r = getResourcesNextToPlayer();
|
|
|
for(int i=0; i<r.size(); i++) {
|
|
|
for (int j = 0; j < mCurrentStageAreas.size(); j++) {
|
|
|
|
|
|
- if (r.get(i).getResource().getName().compareTo(mCurrentStageAreas.get(j).getName()) == 0 &&
|
|
|
- r.get(i).getResource().getStage() == mCurrentStage) {
|
|
|
+ if (r.get(i).getResource(0).getName().compareTo(mCurrentStageAreas.get(j).getName()) == 0 &&
|
|
|
+ r.get(i).getResource(0).getStage() == mCurrentStage) {
|
|
|
removeArea(j);
|
|
|
}
|
|
|
}
|
|
|
- pickResource(r.get(i).getResource().getName());
|
|
|
+ pickResource(r.get(i).getResource(0).getName());
|
|
|
}
|
|
|
return mCurrentStageAreas.size()==0;
|
|
|
}
|
|
|
|
|
|
+ public ArrayList<Resource> getPickedUpResources()
|
|
|
+ {
|
|
|
+ return mResources.getPickedUpResources();
|
|
|
+ }
|
|
|
|
|
|
public boolean pickResource(String name)
|
|
|
{
|
|
@@ -231,8 +233,13 @@ public class Game implements Serializable {
|
|
|
{
|
|
|
ArrayList<Resource> tmp = new ArrayList<Resource>();
|
|
|
for(int i=0; i<mAreas.size(); i++)
|
|
|
- if(!tmp.contains(mAreas.get(i)))
|
|
|
- tmp.add(mAreas.get(i).getResource());
|
|
|
+ {
|
|
|
+ ArrayList<Resource> c = mAreas.get(i).getResource();
|
|
|
+ for(int j=0; j<c.size(); j++)
|
|
|
+ if(!tmp.contains(c.get(j)))
|
|
|
+ tmp.add(c.get(j));
|
|
|
+ }
|
|
|
+
|
|
|
return tmp;
|
|
|
}
|
|
|
|
|
@@ -271,15 +278,16 @@ public class Game implements Serializable {
|
|
|
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();
|
|
|
+ for(int j=0; j<mAreas.get(i).countResource(); j++)
|
|
|
+ if(mAreas.get(i).getResourceNames().get(j).compareTo(name)==0)
|
|
|
+ return mAreas.get(i).getResource(j);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Charge la ressource 3d quand on entre dans une zone
|
|
|
*/
|
|
|
- public boolean precache3DResource(Activity contecxt)
|
|
|
+ synchronized public boolean precache3DResource(Activity contecxt)
|
|
|
{
|
|
|
boolean b =false;
|
|
|
for(int i=0; i<mAreas.size(); i++)
|
|
@@ -287,9 +295,9 @@ public class Game implements Serializable {
|
|
|
if(mAreas.get(i).getStage()==mCurrentStage && mAreas.get(i).isOnArea(mPlayer))
|
|
|
{
|
|
|
b=true;
|
|
|
- Resource r = mResources.getResourceLeftByName(mAreas.get(i).getResourceName());
|
|
|
- if(r!=null)
|
|
|
- r.get3DModel(contecxt);
|
|
|
+ ArrayList<Resource> rs = mResources.getResourceLeftByName(mAreas.get(i).getResourceNames());
|
|
|
+ for(int j=0; j<rs.size(); j++)
|
|
|
+ rs.get(j).get3DModel(contecxt);
|
|
|
}
|
|
|
}
|
|
|
return b;
|
|
@@ -301,9 +309,9 @@ public class Game implements Serializable {
|
|
|
* Fonction principale de positionnnemnt et orientation
|
|
|
*
|
|
|
*/
|
|
|
- public ArrayList<LocatedResource> getResourcesNextToPlayer()
|
|
|
+ public ArrayList<LocatedResources> getResourcesNextToPlayer()
|
|
|
{
|
|
|
- ArrayList<LocatedResource> r = new ArrayList<LocatedResource>();
|
|
|
+ ArrayList<LocatedResources> r = new ArrayList<LocatedResources>();
|
|
|
for(int i=0; i<mCurrentStageAreas.size(); i++)
|
|
|
{
|
|
|
//probleme de GPS..
|
|
@@ -315,8 +323,9 @@ public class Game implements Serializable {
|
|
|
if(i<mCurrentStageAreas.size() && mCurrentStageAreas.get(i).isOnDirection(mPlayer) &&
|
|
|
mCurrentStageAreas.get(i).isOnPlace(mPlayer))
|
|
|
{
|
|
|
- r.add(new LocatedResource(
|
|
|
- mResources.getResourceLeftByName(mCurrentStageAreas.get(i).getResourceName()),
|
|
|
+ ArrayList<Resource> rs = mResources.getResourceLeftByName(mCurrentStageAreas.get(i).getResourceNames());
|
|
|
+ r.add(new LocatedResources(
|
|
|
+ rs,
|
|
|
mCurrentStageAreas.get(i).getPlace(0)
|
|
|
));
|
|
|
}
|