Commit 97b39e13 authored by Lucas Delcros's avatar Lucas Delcros
parents d1b73d7f 76db9885
......@@ -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() {
}
......
......@@ -39,7 +39,7 @@ public class BossEntity extends AbstractEntity {
Entity victim = this.gameState.getAllEntities().get(victim_i);
/* d_min minimum distance to not run away
* 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 = Distance_to_victim(victim);
if(d<d_min){
......@@ -56,14 +56,7 @@ public class BossEntity extends AbstractEntity {
}
else{
Direction dir = this.relayer.getCharacter().getDirection();
double r = random();
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(Direction.NONE);
}
}
else{this.random_move();}
this.waiting_move();
}
......
......@@ -52,17 +52,8 @@ public class StraightEntity extends AbstractEntity {
}
}
else{
Direction d = this.relayer.getCharacter().getDirection();
double r = random();
if(r<0.8){
for(int i=0; i<1;i++) {
this.relayer.move(d);
}
}
else{this.random_move();}
this.waiting_move();
}
// attack
}
}
......@@ -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
......
......@@ -43,7 +43,13 @@ public class GameContent implements Serializable{
for(Entity e:map.getEntities()){
gameState.addEntity(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;
......
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());
......
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