Commit c2bbc8f4 authored by Yann Ramusat's avatar Yann Ramusat

Fusion of the two controlers.

parent f3e8f66f
......@@ -2,26 +2,47 @@ package artificial_intelligence;
import java.util.ArrayList;
import artificial_intelligence.AIEntities.AbstractEntity;
import artificial_intelligence.AIEntities.BasicEntity;
import artificial_intelligence.AIEntities.*;
import core.gamestate.GameContent;
import core.relayer.Relayer;
/**
* This class is used to stop all AI thread when the game finishes.
* @author Guerquin Arnaud
* @author Guerquin Arnaud && Ramusat Yann
*
* TODO replace this class by AI_Controler (more general). Thanks avoiding using this class.
* This class allows to create a new entity of indicated type.
* This class provides a way to start or stop all the current working entities (for example when initializing and quitting a map).
*
*/
public class AIControler {
private static ArrayList<AbstractEntity> list=new ArrayList<>();
public static void add(GameContent gameContent,Relayer dmr){
AbstractEntity ai=new BasicEntity(gameContent,dmr);
public static void add(GameContent gameContent, Relayer dmr, EnumBehaviourType type) {
AbstractEntity ai = null;
switch(type) {
case Agressive:
ai = new AgressiveEntity(gameContent,dmr);
break;
case Basic:
ai = new BasicEntity(gameContent,dmr);
break;
case Defender:
ai = new DefenderEntity(gameContent,dmr);
break;
default:
System.out.println("Trying to instanciate unrecognized type of AI.");
break;
}
list.add(ai);
}
public static ArrayList<AbstractEntity> getList() {
return list;
}
public static int getNumber() {
return list.size();
}
public static void killAll(){
for(AbstractEntity ai :list){
ai.setEndThread(false);
......
package artificial_intelligence;
import artificial_intelligence.AIEntities.*;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import java.util.ArrayList;
/**
* Created by Yann RAMUSAT on 30/12/15.
*
* This class allows to create a new entity of indicated type.
* This class provides a way to start or stop all the current working entities (for example when initializing and quitting a map).
*
* Note: A part of this code (killAll and startAll) is inspired by the previous class AIControler implemented by Arnaud Guerquin.
*/
public class AI_Controler {
/*** SINGLETON PART ***/
private static AI_Controler ourInstance = new AI_Controler();
public static AI_Controler getInstance() {
return ourInstance;
}
private AI_Controler() {
}
/** CONTROLER PART ***/
private ArrayList<AbstractEntity> list=new ArrayList<>();
public ArrayList<AbstractEntity> getList() {
return list;
}
public void killAll(){
for(AbstractEntity ai :list){
ai.setEndThread(false);
}
list.clear();
}
public void startAll() {
for(AbstractEntity ai :list){
ai.start();
}
}
/*** FACTORY PART ***/
public void add(GameContent gameContent, Relayer dmr, EnumBehaviourType type) {
AbstractEntity ai = null;
switch(type) {
case Agressive:
ai = new AgressiveEntity(gameContent,dmr);
break;
case Basic:
ai = new BasicEntity(gameContent,dmr);
break;
case Defender:
ai = new DefenderEntity(gameContent,dmr);
break;
default:
System.out.println("Trying to instanciate unrecognized type of AI.");
break;
}
list.add(ai);
}
public int getNumber() {
return list.size();
}
}
......@@ -4,15 +4,7 @@ import artificial_intelligence.AIEntities.AbstractEntity;
import artificial_intelligence.AIEntities.AgressiveEntity;
import artificial_intelligence.AIEntities.BasicEntity;
import artificial_intelligence.AIEntities.EnumBehaviourType;
import artificial_intelligence.AI_Controler;
import core.gamestate.Character;
import core.gamestate.Entity;
import core.gamestate.GameState;
import core.relayer.Relayer;
import map_generation.map.SurfacesMapGeneration;
import map_generation.map.Map;
import map_generation.map.MapPoint;
import org.junit.Before;
import artificial_intelligence.AIControler;
import org.junit.Test;
import java.util.ArrayList;
......@@ -22,23 +14,23 @@ import static org.junit.Assert.*;
/**
* Created by Yann RAMUSAT on 30/12/15.
*
* This is the unit test class for the AI_Controler class.
* This is the unit test class for the AIControler class.
*/
public class AI_ControlerTest {
public class AIControlerTest {
@Test
public void testadd() throws Exception {
AI_Controler.getInstance().add(null, null, EnumBehaviourType.Basic);
assertEquals(1, AI_Controler.getInstance().getNumber());
AIControler.add(null, null, EnumBehaviourType.Basic);
assertEquals(1, AIControler.getNumber());
AI_Controler.getInstance().add(null, null, EnumBehaviourType.Agressive);
boolean obt = AI_Controler.getInstance().getList().get(1) instanceof AgressiveEntity;
AIControler.add(null, null, EnumBehaviourType.Agressive);
boolean obt = AIControler.getList().get(1) instanceof AgressiveEntity;
assertEquals(true, obt);
}
@Test
public void testkillAll() throws Exception {
AI_Controler.getInstance().killAll();
assertEquals(0, AI_Controler.getInstance().getNumber());
AIControler.killAll();
assertEquals(0, AIControler.getNumber());
}
}
\ No newline at end of file
......@@ -14,7 +14,7 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AI_ControlerTest.class,
AIControlerTest.class,
AITileComparatorTest.class
})
public class AITests{}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment