Commit 76db9885 authored by Louis Cohen's avatar Louis Cohen

Merge branch 'master' of gitlab.crans.org:genie_logiciel_2015/the_dungeon_project

parents 2e2feb64 e0e19cfe
......@@ -40,8 +40,7 @@ public class AITile {
}
public boolean isObstacle(Map map){
//Map map=AbstractEntity.GetMap();
//Relayer relayer=AbstractEntity.GetRelay();
Tile tile=map.getTileAt(x/32,y/32);
TilePropertyVector tpv=tile.getTilePropertyVector();
List list= new ArrayList<TilePropertyVector.TileProperty>();
......@@ -91,7 +90,4 @@ public class AITile {
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;
import artificial_intelligence.AlphaStar.AITile;
import java.util.Comparator;
......@@ -21,12 +20,11 @@ public class AITileComparator implements Comparator<AITile> {
* Allows to compare two tiles with respect to their distances to the obj tile.
* @param c1
* @param c2
* @return
* @return heuristic distance between both element
*/
@Override
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);
}
......
......@@ -5,14 +5,14 @@ import java.util.Objects;
/**
* @author Yann RAMUSAT and Remy GARNIER
*
* Specific queue for the A* algorithm.
* Implement a queue for A* Algorithms
*/
public class AITileQueueElement implements Comparable<AITileQueueElement>{
private AITile caseElement;
private double value;
/**
* Enqueue.
* Add an eleement to the queue.
* @param element
* @param d
*/
......@@ -29,7 +29,7 @@ public class AITileQueueElement implements Comparable<AITileQueueElement>{
return caseElement;
}
@Override
public int compareTo(AITileQueueElement cqe)
{
return (value>cqe.value)?1:-1;
......
# Fichier contenant l'ensemble des species du jeu.
# Nombre de species total
8
9
#Ronflex - Character
C
......@@ -308,4 +308,32 @@ TRIGGER_DEGAT_LP
#abilityList
1
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{
}
};
}
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 **/
......
......@@ -96,6 +96,15 @@ public final class EffectGeneratorRoster {
eb.trigger_degat_lp()));
};
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 {
TRAP_TRIGGER(0),
TRIGGER_DEGAT(0),
TRIGGER_DEGAT_LP(0),
MENTALI_ATTACK_DAMAGE(2);
MENTALI_ATTACK_DAMAGE(2),
TRIGGER_GOLD(0),
SPAWN_GOLD(1);
private EffectKey(int 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;
import java.util.logging.Logger;
import core.abilities.Ability;
import core.abilities.effects.EffectBuilder;
import core.event.Event;
import core.event.SpawnGold;
import core.event.ToServerDeathEvent;
import core.zone.Zone;
import gameloop.DummyLocalGameLoop;
......@@ -153,6 +155,14 @@ public class Being extends Entity {
} else {
LOGGER.info("Death of "+this.getID()+" is send");
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 {
*/
private int intel;
private int gold;
/**
* ????
*/
......@@ -82,6 +84,23 @@ public final class Character extends Being {
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
......
package gameloop;
import core.event.Event;
import core.event.MapChangeEvent;
import core.event.MapInit;
import core.event.ToClientDeathEvent;
import core.gamestate.GameContent;
......@@ -149,6 +150,9 @@ public class DummyLocalGameLoop extends Thread{
setFollowedRelayer(firstEntityRelayer);
relayerSemaphore.release();
}
if(eventToReceive instanceof MapChangeEvent){
GraphicsMasterAbstraction.getInstance().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.GAME_WIN);
}
if (eventToReceive instanceof ToClientDeathEvent && ((ToClientDeathEvent) eventToReceive).getEntityID()==followedRelayer.getCharacter().getID()) {
GraphicsMasterAbstraction.getInstance().changeGUIStateTo(GraphicsMasterAbstraction.GUIStates.GAME_OVER);
......
......@@ -39,7 +39,8 @@ public abstract class GraphicsMasterAbstraction {
LOST_CONNECTION,
PLEASE_WAIT,
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
protected HashMap<GUIStates, PanelAbstraction> mapGUIStatesToGUIPanel = new HashMap<>();
......
......@@ -58,6 +58,7 @@ public class GraphicsMaster extends GraphicsMasterAbstraction {
mapGUIStatesToGUIPanel.put(GUIStates.SERVER_ADDRESS_PANEL, new ServerAddressPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.GAME_OVER, new GameOverPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.GAME_WIN, new GameWinPanel(this));
}
public static void build() {
......
......@@ -11,8 +11,6 @@ import javax.swing.*;
* The gui changes what it displays by swapping GUIPanels in the mainFrame.
*/
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,
// 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{
public GUIPanel(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);
}
/**
* 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);
// }
//}
}
\ No newline at end of file
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);
public GameWinPanel(GraphicsMaster graphicsMaster) {
super(graphicsMaster);
JLabel winLabel = new JLabel("Congratulation, you have reached the stairs !");
winLabel.setFont(GUIColorsAndFonts.smallFont1);
winLabel.setForeground(GUIColorsAndFonts.fontColor1);
setTitlePanel("Game Over");
addToCentralColumn(winLabel,1,1);
addToCentralColumn(ButtonMaker.makeButton("Return to main menu", returnButtonActionListener),1,1);
}
private ActionListener returnButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
controller.returnButtonPressed();
}
};
@Override
public void initialise() {
}
@Override
public void finalise() {
}
@Override
public void keyPressedHandler(Input e) {
}
@Override
public void keyReleasedHandler(Input e) {
}
@Override
public void keyTypedHandler(Input e) {
}
@Override
public void returnButtonAction() {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.MAIN_MENU);
}
}
......@@ -32,8 +32,4 @@ public class GamePanelMapPoint {
public int getY() {
return Y;
}
//TODO: Useful?
public GraphicsMapPoint getGraphicsMapPoint() {
return graphicsMapPoint;
}
}
......@@ -5,7 +5,7 @@ import java.io.Serializable;
/**
* Created by dupriez on 03/11/15.
* Represents a basic sprite with no animation.
* Represents a basic sprite with no animation (just an image in fact).
*/
public class Sprite implements Serializable, Displayable{
......
......@@ -31,11 +31,9 @@ public abstract class SpriteLoader {
Sprite newSprite = null;
//The sprite asked is not in the map, so we load it and add it to the map
try {
// newSprite = new Sprite(ImageIO.read(new File(path)));
URL url=UsedForLoadingSprites.getInstance().getClass().getResource(path);
if(url==null)
throw new IllegalStateException("Missing sprite :"+path+ "!");
//System.out.println(url);
newSprite = new Sprite(ImageIO.read(url));
} catch (IOException e) {
Logging.getInstance().getLogger().severe(e.getMessage());
......
......@@ -40,7 +40,11 @@ public class IGPEntity extends AbstractEntity {
int sX = relayer.getCharacter().getX();
int sY = relayer.getCharacter().getY();
Direction dir = AI.alpha_star(map,sX, sY, dX, dY,map.getWidth(),map.getHeight());
this.relayer.move(dir);
if (relayer.getCharacter().getCollisionBox().intersect(victim.getCollisionBox())) {
this.relayer.move(Direction.NONE);
} else {
this.relayer.move(dir);
}
this.relayer.tryToCastAbility(0);
break;
case "proteger":
......@@ -67,15 +71,20 @@ public class IGPEntity extends AbstractEntity {
}
}
}
int tardX = entityList.get(newvictim).getX();
int tardY = entityList.get(newvictim).getY();
Direction dir2 = AI.alpha_star(map,sX2, sY2, tardX, tardY,map.getWidth(),map.getHeight());
this.relayer.move(dir2);
this.relayer.tryToCastAbility(0);
if (newvictim != -1) {
int tardX = entityList.get(newvictim).getX();
int tardY = entityList.get(newvictim).getY();
Direction dir2 = AI.alpha_star(map,sX2, sY2, tardX, tardY,map.getWidth(),map.getHeight());
if (relayer.getCharacter().getCollisionBox().intersect(entityList.get(newvictim).getCollisionBox())) {
this.relayer.move(Direction.NONE);
} else {
this.relayer.move(dir2);
}
this.relayer.tryToCastAbility(0);
}
break;
case "soigner" :
/*TODO : Soigner victim */
break;
default:
Entity owner =null;
try {
......@@ -88,7 +97,11 @@ public class IGPEntity extends AbstractEntity {
int sX3 = relayer.getCharacter().getX();
int sY3 = relayer.getCharacter().getY();
Direction dir3 = AI.alpha_star(map,sX3, sY3, dX3, dY3,map.getWidth(),map.getHeight());
this.relayer.move(dir3);
if (relayer.getCharacter().getCollisionBox().intersect(owner.getCollisionBox())) {
this.relayer.move(Direction.NONE);
} else {
this.relayer.move(dir3);
}this.relayer.move(dir3);
}
}
}
......@@ -209,7 +209,8 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
}
BehaviourHolder.getInstance().SetFollowerBehaviour(fob);
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.MAIN_MENU);
BehaviourHolder.getInstance().GetFollowerBehaviour().PrintElements();
/* Print the instruction, used for tests
BehaviourHolder.getInstance().GetFollowerBehaviour().PrintElements(); */
}
};
......
......@@ -12,15 +12,12 @@ import core.gamestate.Entity;
/**
*
*@author mapgen team
* Represents a map of tiles
*
*/
public class Map implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7578251078403583045L;
private Tile[][] map;
private MapPoint positionPlayerAtStart;
......@@ -45,7 +42,8 @@ public class Map implements Serializable {
if(x < 0 || x > height || y < 0 || y > width) {
throw new ArrayIndexOutOfBoundsException("Trying to get tile at "+x+" , "+y+" but map has dimension "+height+" , "+width);
}
}
}
/**
*
* @return the height of the map in tiles
......@@ -81,17 +79,22 @@ public class Map implements Serializable {
}
return map[x][y].getType();
}
/**
*
* @param x
* @param y
* @return clone of tile at position x, y in map[][]
* @return tile at position x, y in map[][]
*/
public Tile getTileAt(int x, int y){
checkBounds(x, y);
//return new Tile(map[x][y]);
return map[x][y];
}
/**
* This functions checks if every tile is reachable in the map by BFS
* @return true if every tile in the map is reachable
*/
public boolean check() {
// Application of a BFS to find the number of different surfaces in the map. If the map is correct it should be 1.
int nb=0;
......
......@@ -24,7 +24,6 @@ public final class MapBuilder implements Serializable{
private ArrayList<RoomBuilder> rooms;
private ArrayList<Surface> corridors;
private ArrayList<Surface> doors;
private ArrayList<Entity> entities;
private RoomGraph roomTree;