Commit 97b39e13 authored by Lucas Delcros's avatar Lucas Delcros
parents d1b73d7f 76db9885
...@@ -261,6 +261,17 @@ public abstract class AbstractEntity extends Thread { ...@@ -261,6 +261,17 @@ public abstract class AbstractEntity extends Thread {
} }
} }
public void waiting_move(){
Direction dir = this.relayer.getCharacter().getDirection();
double r = random();
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(dir);
}
}
else{this.random_move();}
}
public void act() { public void act() {
} }
......
...@@ -39,7 +39,7 @@ public class BossEntity extends AbstractEntity { ...@@ -39,7 +39,7 @@ public class BossEntity extends AbstractEntity {
Entity victim = this.gameState.getAllEntities().get(victim_i); Entity victim = this.gameState.getAllEntities().get(victim_i);
/* d_min minimum distance to not run away /* d_min minimum distance to not run away
* dmax maximum distance to not get closer*/ * dmax maximum distance to not get closer*/
double d_min = 32*3; // tiles of length 32 : so 3 and 7 tiles double d_min = 32*5; // tiles of length 32 : so 5 and 14 tiles
double d_max = 32*14; double d_max = 32*14;
double d = Distance_to_victim(victim); double d = Distance_to_victim(victim);
if(d<d_min){ if(d<d_min){
...@@ -56,14 +56,7 @@ public class BossEntity extends AbstractEntity { ...@@ -56,14 +56,7 @@ public class BossEntity extends AbstractEntity {
} }
else{ else{
Direction dir = this.relayer.getCharacter().getDirection(); this.waiting_move();
double r = random();
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(Direction.NONE);
}
}
else{this.random_move();}
} }
......
...@@ -52,17 +52,8 @@ public class StraightEntity extends AbstractEntity { ...@@ -52,17 +52,8 @@ public class StraightEntity extends AbstractEntity {
} }
} }
else{ else{
Direction d = this.relayer.getCharacter().getDirection(); this.waiting_move();
double r = random();
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(d);
}
}
else{this.random_move();}
} }
// attack // attack
} }
} }
...@@ -40,8 +40,7 @@ public class AITile { ...@@ -40,8 +40,7 @@ public class AITile {
} }
public boolean isObstacle(Map map){ public boolean isObstacle(Map map){
//Map map=AbstractEntity.GetMap();
//Relayer relayer=AbstractEntity.GetRelay();
Tile tile=map.getTileAt(x/32,y/32); Tile tile=map.getTileAt(x/32,y/32);
TilePropertyVector tpv=tile.getTilePropertyVector(); TilePropertyVector tpv=tile.getTilePropertyVector();
List list= new ArrayList<TilePropertyVector.TileProperty>(); List list= new ArrayList<TilePropertyVector.TileProperty>();
...@@ -91,7 +90,4 @@ public class AITile { ...@@ -91,7 +90,4 @@ public class AITile {
return Direction.NONE; return Direction.NONE;
} }
} }
// others information could be here and be handled by Case Comparator if u want.
} }
\ No newline at end of file
package artificial_intelligence.AlphaStar; package artificial_intelligence.AlphaStar;
import artificial_intelligence.AlphaStar.AITile;
import java.util.Comparator; import java.util.Comparator;
...@@ -21,12 +20,11 @@ public class AITileComparator implements Comparator<AITile> { ...@@ -21,12 +20,11 @@ public class AITileComparator implements Comparator<AITile> {
* Allows to compare two tiles with respect to their distances to the obj tile. * Allows to compare two tiles with respect to their distances to the obj tile.
* @param c1 * @param c1
* @param c2 * @param c2
* @return * @return heuristic distance between both element
*/ */
@Override
public int compare(AITile c1, AITile c2) public int compare(AITile c1, AITile c2)
{ {
// juste pour tester, mais il faudra changer car la conversion est trop violente
return heuristique(c1)- heuristique(c2); return heuristique(c1)- heuristique(c2);
} }
......
...@@ -5,14 +5,14 @@ import java.util.Objects; ...@@ -5,14 +5,14 @@ import java.util.Objects;
/** /**
* @author Yann RAMUSAT and Remy GARNIER * @author Yann RAMUSAT and Remy GARNIER
* *
* Specific queue for the A* algorithm. * Implement a queue for A* Algorithms
*/ */
public class AITileQueueElement implements Comparable<AITileQueueElement>{ public class AITileQueueElement implements Comparable<AITileQueueElement>{
private AITile caseElement; private AITile caseElement;
private double value; private double value;
/** /**
* Enqueue. * Add an eleement to the queue.
* @param element * @param element
* @param d * @param d
*/ */
...@@ -29,7 +29,7 @@ public class AITileQueueElement implements Comparable<AITileQueueElement>{ ...@@ -29,7 +29,7 @@ public class AITileQueueElement implements Comparable<AITileQueueElement>{
return caseElement; return caseElement;
} }
@Override
public int compareTo(AITileQueueElement cqe) public int compareTo(AITileQueueElement cqe)
{ {
return (value>cqe.value)?1:-1; return (value>cqe.value)?1:-1;
......
# Fichier contenant l'ensemble des species du jeu. # Fichier contenant l'ensemble des species du jeu.
# Nombre de species total # Nombre de species total
8 9
#Ronflex - Character #Ronflex - Character
C C
...@@ -308,4 +308,32 @@ TRIGGER_DEGAT_LP ...@@ -308,4 +308,32 @@ TRIGGER_DEGAT_LP
#abilityList #abilityList
1 1
TEST_SUICIDE TEST_SUICIDE
#--------------------------------------------------------------------
#Gold - Entity
E
#name
Gold
#tilePropertyVector
2
SOLID
LIQUID
#collisionBox
R
15
15
#visilibity
R
200
200
#entityDisplayerType
FIREBOLT
#triggers
1
#trigger function
DEFAULT_TRIGGER
#effect descriptor
1
TRAP_TRIGGER
#abilityList
0
...@@ -269,6 +269,29 @@ public class EffectBuilder implements Serializable{ ...@@ -269,6 +269,29 @@ public class EffectBuilder implements Serializable{
} }
}; };
} }
Effect trigger_gold() {
return new Effect() {
private static final long serialVersionUID = 1L;
@Override
public void effect(List<Integer> targetCharacterIDList, GameContent gameContent, int casterCharacterID) throws InterruptedException {
boolean hit = false;
for (Integer targetID : targetCharacterIDList) {
try {
if(gameContent.getGameState().getEntity(casterCharacterID).getOwned_character() != targetID) {
gameContent.getGameState().getCharacter(targetID).takeDamage(Math.max(1, 0));
hit =true;
}
} catch (EntityNotFoundExeption entityNotFoundExeption) {
}
}
if(hit){
Event event = new AbilityEvent(casterCharacterID, 0);
DummyLocalGameLoop.getInstance().getNetworkConnection().sendEvent(event);
}
}
};
}
/** Methods to be applied on an Effect to transform it into another one **/ /** Methods to be applied on an Effect to transform it into another one **/
......
...@@ -96,6 +96,15 @@ public final class EffectGeneratorRoster { ...@@ -96,6 +96,15 @@ public final class EffectGeneratorRoster {
eb.trigger_degat_lp())); eb.trigger_degat_lp()));
}; };
effectFactory.registerEffectGenerator(EffectKey.TRIGGER_DEGAT_LP, effectGenerator); effectFactory.registerEffectGenerator(EffectKey.TRIGGER_DEGAT_LP, effectGenerator);
effectGenerator =
(casterCharacterID, parameters) -> {
return eb.affectZone((character -> character.getHitbox()),
eb.filter( CommonCharacterIDListFilter.allExceptOne(casterCharacterID),
eb.trigger_gold()));
};
effectFactory.registerEffectGenerator(EffectKey.TRIGGER_GOLD, effectGenerator);
} }
} }
...@@ -16,7 +16,9 @@ public enum EffectKey { ...@@ -16,7 +16,9 @@ public enum EffectKey {
TRAP_TRIGGER(0), TRAP_TRIGGER(0),
TRIGGER_DEGAT(0), TRIGGER_DEGAT(0),
TRIGGER_DEGAT_LP(0), TRIGGER_DEGAT_LP(0),
MENTALI_ATTACK_DAMAGE(2); MENTALI_ATTACK_DAMAGE(2),
TRIGGER_GOLD(0),
SPAWN_GOLD(1);
private EffectKey(int parameterNb) { private EffectKey(int parameterNb) {
this.parameterNb = parameterNb; this.parameterNb = parameterNb;
......
package core.event;
import core.abilities.effects.Effect;
import core.gamestate.*;
import core.gamestate.Character;
import core.relayer.RelayerEntity;
import core.zone.Direction;
import core.zone.Point;
import core.zone.Translation;
import gameloop.DummyLocalGameLoop;
import java.util.List;
/**
* Created by hilaire on 06/01/16.
*
* this event is used when some Gold is created
*/
public class SpawnGold implements ClientEvent,ServerEvent {
private static final long serialVersionUID = 1L;
private int targetID;
public SpawnGold(int targetID){
this.targetID=targetID;
}
@Override
public boolean execute(GameContent gameContent) throws InterruptedException {
Entity target = null;
try {
target = gameContent.getGameState().getEntity(targetID);
Character charac = null;
try {
charac = gameContent.getGameState().getCharacter(targetID);
} catch (EntityNotFoundExeption entityNotFoundExeption) {
return false;
}
Entity entity = SpeciesArray.create(charac.getX(), charac.getY(), 0, "Gold", "Gold");
entity.setOrientation(charac.getOrientation());
entity.setSpeed(0);
entity.setOwned_character(targetID);
gameContent.getGameState().addEntity(entity);
gameContent.addTriggerToCheck(entity);
RelayerEntity relayer = new RelayerEntity(entity.getID(),entity,gameContent);
entity.setRelayer(relayer);
if(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection() != Direction.NONE) {
relayer.move(DummyLocalGameLoop.getInstance().getFollowedRelayer().getDirection());
}
else{
relayer.move(charac.getDirection());
}
relayer.start();
return true;
} catch (EntityNotFoundExeption entityNotFoundExeption) {
return true;
}
}
@Override
public Event resolve(GameContent gameContent) {
return this;
}
}
\ No newline at end of file
...@@ -6,7 +6,9 @@ import java.util.Objects; ...@@ -6,7 +6,9 @@ import java.util.Objects;
import java.util.logging.Logger; import java.util.logging.Logger;
import core.abilities.Ability; import core.abilities.Ability;
import core.abilities.effects.EffectBuilder;
import core.event.Event; import core.event.Event;
import core.event.SpawnGold;
import core.event.ToServerDeathEvent; import core.event.ToServerDeathEvent;
import core.zone.Zone; import core.zone.Zone;
import gameloop.DummyLocalGameLoop; import gameloop.DummyLocalGameLoop;
...@@ -153,6 +155,14 @@ public class Being extends Entity { ...@@ -153,6 +155,14 @@ public class Being extends Entity {
} else { } else {
LOGGER.info("Death of "+this.getID()+" is send"); LOGGER.info("Death of "+this.getID()+" is send");
network.sendEvent(event); network.sendEvent(event);
}
Event event2 = new SpawnGold(this.getID());
if (network==null){
LOGGER.severe("NetworkConnection null, GOld"+this.getID()+" can't be created");
} else {
LOGGER.info("Gold creation by " + this.getID() + " is send");
network.sendEvent(event2);
} }
} }
......
...@@ -29,6 +29,8 @@ public final class Character extends Being { ...@@ -29,6 +29,8 @@ public final class Character extends Being {
*/ */
private int intel; private int intel;
private int gold;
/** /**
* ???? * ????
*/ */
...@@ -82,6 +84,23 @@ public final class Character extends Being { ...@@ -82,6 +84,23 @@ public final class Character extends Being {
return intel; return intel;
} }
/**
* Returns the character's gold value.
* @return the character's gold value.
*/
public int getGold() {
return gold;
}
/**
* Returns the character's gold value.
* @return the character's gold value.
*/
public void setGold( int gold2) {
this.gold = gold2;
}
/** /**
* ???? * ????
* @return * @return
......
...@@ -43,7 +43,13 @@ public class GameContent implements Serializable{ ...@@ -43,7 +43,13 @@ public class GameContent implements Serializable{
for(Entity e:map.getEntities()){ for(Entity e:map.getEntities()){
gameState.addEntity(e); gameState.addEntity(e);
Relayer dmr = Relayers.addNewRelayer(e); Relayer dmr = Relayers.addNewRelayer(e);
AIControler.add(this,dmr, EnumBehaviourType.Boss); String name = dmr.getCharacter().getSpeciesName();
if(name.equals("Ronflex")){
AIControler.add(this,dmr, EnumBehaviourType.Boss);
}
else{
AIControler.add(this,dmr, EnumBehaviourType.Straight);
}
} }
} }
int posX=(map.getPositionPlayerStart().getI())*Point.TileScale; int posX=(map.getPositionPlayerStart().getI())*Point.TileScale;
......
package gameloop; package gameloop;
import core.event.Event; import core.event.Event;
import core.event.MapChangeEvent;
import core.event.MapInit; import core.event.MapInit;
import core.event.ToClientDeathEvent; import core.event.ToClientDeathEvent;
import core.gamestate.GameContent; import core.gamestate.GameContent;
...@@ -149,6 +150,9 @@ public class DummyLocalGameLoop extends Thread{ ...@@ -149,6 +150,9 @@ public class DummyLocalGameLoop extends Thread{
setFollowedRelayer(firstEntityRelayer); setFollowedRelayer(firstEntityRelayer);
relayerSemaphore.release(); relayerSemaphore.release();
} }
if(eventToReceive instanceof MapChangeEvent){
GraphicsMasterAbstraction.getInstance().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.GAME_WIN);
}
if (eventToReceive instanceof ToClientDeathEvent && ((ToClientDeathEvent) eventToReceive).getEntityID()==followedRelayer.getCharacter().getID()) { if (eventToReceive instanceof ToClientDeathEvent && ((ToClientDeathEvent) eventToReceive).getEntityID()==followedRelayer.getCharacter().getID()) {
GraphicsMasterAbstraction.getInstance().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.GAME_OVER); GraphicsMasterAbstraction.getInstance().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.GAME_OVER);
......
...@@ -39,7 +39,8 @@ public abstract class GraphicsMasterAbstraction { ...@@ -39,7 +39,8 @@ public abstract class GraphicsMasterAbstraction {
LOST_CONNECTION, LOST_CONNECTION,
PLEASE_WAIT, PLEASE_WAIT,
SERVER_ADDRESS_PANEL, SERVER_ADDRESS_PANEL,
SERVER_CREATED_PANEL SERVER_CREATED_PANEL,
GAME_WIN;
} }
//This map indicates to graphicsMaster which guiPanel is associated to each GUIState, it is filled in Graphicsmaster's constructor //This map indicates to graphicsMaster which guiPanel is associated to each GUIState, it is filled in Graphicsmaster's constructor
protected HashMap<GUIStates, PanelAbstraction> mapGUIStatesToGUIPanel = new HashMap<>(); protected HashMap<GUIStates, PanelAbstraction> mapGUIStatesToGUIPanel = new HashMap<>();
......
...@@ -58,6 +58,7 @@ public class GraphicsMaster extends GraphicsMasterAbstraction { ...@@ -58,6 +58,7 @@ public class GraphicsMaster extends GraphicsMasterAbstraction {
mapGUIStatesToGUIPanel.put(GUIStates.SERVER_ADDRESS_PANEL, new ServerAddressPanel(this)); mapGUIStatesToGUIPanel.put(GUIStates.SERVER_ADDRESS_PANEL, new ServerAddressPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.GAME_OVER, new GameOverPanel(this)); mapGUIStatesToGUIPanel.put(GUIStates.GAME_OVER, new GameOverPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.GAME_WIN, new GameWinPanel(this));
} }
public static void build() { public static void build() {
......
...@@ -11,8 +11,6 @@ import javax.swing.*; ...@@ -11,8 +11,6 @@ import javax.swing.*;
* The gui changes what it displays by swapping GUIPanels in the mainFrame. * The gui changes what it displays by swapping GUIPanels in the mainFrame.
*/ */
public abstract class GUIPanel extends JPanel implements PanelAbstraction{ public abstract class GUIPanel extends JPanel implements PanelAbstraction{
//The following line is commented because KeyListener does not seem to work in a JPanel
//Private KeyListenerForGUIPanel associatedKeyHandler;
//Store the graphicsMaster that created the guiPanel (there should be only one GraphicsMaster instanciation per application, //Store the graphicsMaster that created the guiPanel (there should be only one GraphicsMaster instanciation per application,
// this variable is just there to give the guiPanel the right to call the method changeGUIStateTo de graphicsMaster) // this variable is just there to give the guiPanel the right to call the method changeGUIStateTo de graphicsMaster)
...@@ -24,66 +22,6 @@ public abstract class GUIPanel extends JPanel implements PanelAbstraction{ ...@@ -24,66 +22,6 @@ public abstract class GUIPanel extends JPanel implements PanelAbstraction{
public GUIPanel(GraphicsMaster graphicsMaster) { public GUIPanel(GraphicsMaster graphicsMaster) {
this.graphicsMaster = graphicsMaster; this.graphicsMaster = graphicsMaster;
//The following 2 lines are commented because KeyListener does not seem to work in a JPanel
//associatedKeyHandler = new KeyListenerForGUIPanel(this);
setFocusable(true); setFocusable(true);
} }
}
/** \ No newline at end of file
* This method is called by the gui before displaying the panel
*/
//abstract void initialise();
/**
* This method is called by the gui after this panel is no more displayed
*/
//abstract void finalise();
/**
* Define here what should happen if a key is pressed while this panel has the focus
* @param e
*/
//abstract void keyPressedHandler(KeyEvent e);
//Example of a body one could give to the keyPressedHandler method when implementing a guiPanel
//if(e.getKeyCode() == 27) { // 27 -> Escape
// System.out.println("Escape has been pressed");
//}
/**
* Define here what should happen if a key is released while this panel has the focus
* @param e
*/
//abstract void keyReleasedHandler(KeyEvent e);
/**
* Define here what should happen if a key is typed while this panel has the focus
* @param e
*/
//abstract void keyTypedHandler(KeyEvent e);
}
// The following code is commented because KeyListener does not seem to work on a JPanel
///**
// * This class detects the KeyEvents coming from the keyboard (KeyPressed, KeyReleased and KeyTyped) when the guiPanel
// * it is associated with has the focus, and call the corresponding KeyEvent handler of the associated guiPanel
// */
//class KeyListenerForGUIPanel implements KeyListener {
//
// private guiPanel associatedGUIPanel;
//
// KeyListenerForGUIPanel(guiPanel associatedGUIPanel) {
// this.associatedGUIPanel = associatedGUIPanel;
// }
//
// public final void keyPressed(KeyEvent e) {
// associatedGUIPanel.keyPressedHandler(e);
// }
//
// public final void keyReleased(KeyEvent e) {
// associatedGUIPanel.keyReleasedHandler(e);
// }
//
// public final void keyTyped(KeyEvent e) {
// associatedGUIPanel.keyTypedHandler(e);
// }
//}
package graphics.guiSkeleton.guiPanel.menuPanel;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;
import graphics.graphical_abstraction.panel.menu.GameOverPanelAbstraction;
import graphics.graphical_abstraction.panel.menu.GameOverPanelAbstractionController;
import graphics.graphical_abstraction.panel.menu.MainMenuPanelAbstraction;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
import graphics.guiSkeleton.guiPanel.menuPanel.facilities.ButtonMaker;
import graphics.guiSkeleton.guiPanel.menuPanel.facilities.MenuPanel;
import graphics.ingame_input_listener.Input;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by dupriez on 01/01/16.
*/
public class GameWinPanel extends MenuPanel implements GameOverPanelAbstraction {
GameOverPanelAbstractionController controller = new GameOverPanelAbstractionController(this);