Commit d584d2df authored by Fardale's avatar Fardale

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

parents 3db555fa 13111efc
package core.event;
import artificial_intelligence.AIControler;
import core.gamestate.Entity;
import core.gamestate.GameContent;
......
......@@ -8,6 +8,7 @@ import core.zone.Point;
import core.zone.Zone;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayerType;
import map_generation.tiles.TilePropertyVector;
import map_generation.tiles.TileType;
public class EntitySpecies{
......@@ -59,8 +60,11 @@ public class EntitySpecies{
}
//TODO change this
public boolean canSpawn(Point p) {
return true;
public boolean canSpawn(TileType tile) {
switch (tile){
case WATER : return false;
default : return true;
}
}
}
package core.gamestate;
import core.zone.Point;
import map_generation.map.Map;
import network.NetworkConnection;
import network.NetworkObject;
......@@ -9,14 +10,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import core.zone.Point;
/**
* Just a class to contain a Map and a GameState
*
* Possible improvement: design a readonly interface for it, to give to the gui to ensure she isn't able to modify it.
*
*
* @author Dupriez Thomas
* @author Guerquin Arnaud
*
......@@ -51,7 +50,7 @@ public class GameContent implements Serializable{
* Relayer dmr = Relayers.addNewRelayer(2,AItest,this);
* AIControler.add(gameContent,dmr);
*/
System.out.println("One gameContent created");
System.out.println("GameContent class: One gameContent created by"+Thread.currentThread().getId());
}
public Map getMap() {
......@@ -78,7 +77,7 @@ public class GameContent implements Serializable{
return gameState.getOnlyBeings();
}
public List<Being> getAllBeings() {
return gameState.getAllBeings();
return gameState.getAllBeings();
}
public List<Character> getOnlyCharacters() {
......@@ -95,6 +94,10 @@ public class GameContent implements Serializable{
return players.get(i);
}
public ArrayList<Character> getAllPlayers() {
return players;
}
public void applyTrigger(NetworkConnection<NetworkObject> networkConnection) {
for(Entity e:triggerEntities){
e.checkTrigger(this,networkConnection);
......@@ -104,7 +107,7 @@ public class GameContent implements Serializable{
public void addTriggerToCheck(Entity e) {
triggerEntities.add(e);
}
public void removeTriggerToCheck(Entity e) {
triggerEntities.remove(e);
......
......@@ -7,6 +7,7 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Objects;
import map_generation.tiles.TileType;
import assets.UsedForLoadingSprites;
import core.zone.Point;
......@@ -87,8 +88,8 @@ public class SpeciesArray {
"Line"+lineError + message);
}
public static boolean canSpawn(Point p,String speciesName){
public static boolean canSpawn(TileType tile,String speciesName){
EntitySpecies species=array.get(speciesName);
return species!=null && species.canSpawn(p);
return species!=null && species.canSpawn(tile);
}
}
......@@ -33,14 +33,15 @@ public class DummyLocalGameLoop extends Thread{
public Relayer getFollowedRelayer() {
try {
relayerSemaphore.acquire();
System.out.println("Acquired relayer");
System.out.println("Acquired relayer "+ followedRelayer+ " by "+currentThread().getId());
return followedRelayer;
} catch (InterruptedException e) {
System.out.println("Problem with acquiring relayer...");
}finally {
//finally is almost always executed, unless an Interrupted exception or a System.exit appeared
System.out.println("Relayer is "+followedRelayer);
relayerSemaphore.release();
System.out.println("Released relayer");
System.out.println("Released relayer by "+currentThread().getId());
}
return followedRelayer;
......@@ -98,6 +99,9 @@ public class DummyLocalGameLoop extends Thread{
public synchronized void pauseGame()
{
isPlaying=false;
//do not release here
//relayerSemaphore.release();
System.out.println("Released relayer");
}
public synchronized boolean getIsPlaying()
......@@ -126,15 +130,15 @@ public class DummyLocalGameLoop extends Thread{
@Override
public void run() {
System.out.println("DummyLocalGameLoop Thread started");
System.out.println("DummyLocalGameLoop Thread started+"+currentThread().getId());
while (true) {
//System.out.println("DummyLocalGameLoopThread, game is "+isPlaying);
if (getIsPlaying()) {
System.out.println("DummyLocalGameLoopThread, game is "+isPlaying);
System.out.println("DummyLocalGameLoopThread,"+currentThread().getId()+ "game is "+isPlaying);
Event eventToReceive = null;
System.out.println("The game is on!");
while (!((eventToReceive = (Event) getNetworkConnection().receiveEvent(true)) instanceof EndEvent)) {
//System.out.println("DummyLocalGameLoop Thread: We have received an event!applying...");
//System.out.println("DummyLocalGameLoop Thread: We have received an event!applying...+"+eventToReceive);
eventToReceive.apply(gameContent);
if (eventToReceive instanceof MapInit) {
GameContent gc = DummyLocalGameLoop.getInstance().getContent();
......
......@@ -23,10 +23,9 @@ public class GameStarter {
static public void startGameSinglePlayer()
{
NetworkConnection<NetworkObject>[] localConnections= LocalConnection.initiate();
NetworkConnection<NetworkObject>[] localConnections= LocalConnection.createNew();
NetworkConnection<NetworkObject> serverConnection = localConnections[0];
NetworkConnection<NetworkObject> clientConnection = localConnections[1];
ServerLoop dummyServerLoop=new ServerLoop(serverConnection);
DummyLocalGameLoop.getInstance().setNetworkConnection(clientConnection);
......@@ -36,6 +35,7 @@ public class GameStarter {
if (!DummyLocalGameLoop.getInstance().startedBefore())
DummyLocalGameLoop.getInstance().start();
//this is start and not run like in the DummyServer, because here we are dealing with a thread
ServerLoop dummyServerLoop=new ServerLoop(serverConnection);
dummyServerLoop.start();
//let the loop run now!
DummyLocalGameLoop.getInstance().startGame();
......
......@@ -76,6 +76,7 @@ public class ServerLoop extends Thread {
System.out.println("DummyServerLoop: Just received an EndEvent");
//this is so bad because if this thread sleeps for too long it's a disaster
cont=false;
networkConnection.initiateConnectionEnd();
}
}
if(cont == false)
......
......@@ -35,7 +35,9 @@ public abstract class GraphicsMasterAbstraction {
SINGLEPLAYER_GAME_CREATION,
MULTIPLAYER_CHARACTER_CHOICE,
SINGLEPLAYER_CHARACTER_CHOICE,
GAME_OVER}
GAME_OVER,
LOST_CONNECTION
}
//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<>();
//The current state of the GUI
......
......@@ -38,12 +38,24 @@ public class GamePanelAbstractionController {
MyInputInterpreter.setMoveXRight(true);break;
case DOWN_ARROW:
MyInputInterpreter.setMoveYBottom(true);break;
case SPELL:
case ABILITY_1:
if(spellReleased){
MyInputInterpreter.tryToCastAbility(1);
spellReleased=false;
}
break;
case ABILITY_2:
if(spellReleased){
MyInputInterpreter.tryToCastAbility(2);
spellReleased=false;
}
break;
case ABILITY_3:
if(spellReleased){
MyInputInterpreter.tryToCastAbility(3);
spellReleased=false;
}
break;
case ATTACK:
if(attackReleased){
MyInputInterpreter.tryToCastAbility(0);
......@@ -70,7 +82,11 @@ public class GamePanelAbstractionController {
MyInputInterpreter.setMoveYBottom(false);break;
case ATTACK:
attackReleased=true;break;
case SPELL:
case ABILITY_1:
spellReleased=true;break;
case ABILITY_2:
spellReleased=true;break;
case ABILITY_3:
spellReleased=true;break;
default:
break;
......
......@@ -11,5 +11,6 @@ public interface LoungePanelAbstraction extends MenuPanelAbstraction {
public void chooseCharacterButtonAction();
public void backButtonAction();
public void playButtonAction();
}
......@@ -24,5 +24,6 @@ public class LoungePanelAbstractionController extends MenuPanelAbstractionContro
public void backButtonPressed(){
this.lounge_panel.backButtonAction();
}
public void playButtonPressed(){this.lounge_panel.playButtonAction();}
}
......@@ -6,6 +6,7 @@ import graphics.guiSkeleton.guiPanel.*;
import graphics.guiSkeleton.guiPanel.menuPanel.*;
import graphics.guiSkeleton.guiPanel.menuPanel.characterChoice.MultiPlayer_CharacterChoicePanel;
import graphics.guiSkeleton.guiPanel.menuPanel.characterChoice.SinglePlayer_CharacterChoicePanel;
import graphics.guiSkeleton.guiPanel.menuPanel.configuration.ConfigurationPanel;
import graphics.guiSkeleton.guiPanel.menuPanel.gameCreation.MultiPlayer_GameCreationPanel;
import graphics.guiSkeleton.guiPanel.menuPanel.gameCreation.SinglePlayer_GameCreationPanel;
import graphics.guiSkeleton.guiPanel.menuPanel.gameLoad.SinglePlayer_LoadGamePanel;
......@@ -54,6 +55,7 @@ public class GraphicsMaster extends GraphicsMasterAbstraction {
mapGUIStatesToGUIPanel.put(GUIStates.SINGLEPLAYER_GAME_CREATION, new SinglePlayer_GameCreationPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.SINGLEPLAYER_CHARACTER_CHOICE, new SinglePlayer_CharacterChoicePanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.SINGLEPLAYER_LOADGAME, new SinglePlayer_LoadGamePanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.LOST_CONNECTION, new LostConnectionPanel(this));
mapGUIStatesToGUIPanel.put(GUIStates.GAME_OVER, new GameOverPanel(this));
}
......
......@@ -17,6 +17,7 @@ public class Igniter_Main {
/** Initialise some packages to detect instantly uncorrect declarations **/
AbilityPackageInitialiser.initialisePackage();
EffectPackageInitialiser.initialisePackage();
System.out.println();
/** Launch the GUI (and thus the game) **/
GraphicsMaster.build();
......
package graphics.guiSkeleton;
import core.gamestate.Character;
import core.gamestate.GameContent;
import core.relayer.Relayer;
import graphics.guiSkeleton.guiPanel.GamePanel;
......@@ -11,6 +12,7 @@ import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.util.ArrayList;
/**
* Created by ghocquet on 02/01/16.
......@@ -22,6 +24,7 @@ public class MinimapDisplayer
private Graphics2D g_map;
private Relayer relayer;
private GamePanel gamePanel;
private GameContent gameContent;
private BufferedImage map;
private int mapWidth;
private int mapHeight;
......@@ -29,6 +32,7 @@ public class MinimapDisplayer
private int tileH = TileSprite.TileSpriteHeight();
private Color playerColor = new Color(255,0,0);
private Color stairsColor = new Color(255,255,0);
private Color friendColor = new Color(0,255,0);
/**
* @param gameContent: used to get the map generated
......@@ -39,6 +43,7 @@ public class MinimapDisplayer
Relayer followedRelayer,
GamePanel gamePanel)
{
this.gameContent = gameContent;
this.relayer = followedRelayer;
this.gamePanel = gamePanel;
......@@ -71,8 +76,17 @@ public class MinimapDisplayer
// Update the map
Graphics2D g_newMap = newMap.createGraphics();
g_newMap.setColor(playerColor);
g_newMap.drawRect(relayer.getCharacter().getY()/tileW-1,relayer.getCharacter().getX()/tileH-1,3,3);
ArrayList<Character> playerList = gameContent.getAllPlayers();
for (Character player : playerList) {
if (player.getName() == relayer.getCharacter().getName()) {
g_newMap.setColor(playerColor);
g_newMap.drawRect(player.getY() / tileW - 1, player.getX() / tileH - 1, 3, 3);
}
else {
g_newMap.setColor(friendColor);
g_newMap.drawRect(player.getY() / tileW - 1, player.getX() / tileH - 1, 3, 3);
}
}
// Draw on the Screen
g.drawImage(newMap, gamePanel.getSize().width - (mapWidth-1) / tileW, 0, null);
......
package graphics.guiSkeleton.guiPanel.menuPanel;
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 bogdanbear on 02/01/2016.
*/
public class LostConnectionPanel extends MenuPanel{
public LostConnectionPanel(GraphicsMaster graphicsMaster) {
super(graphicsMaster);
JLabel sorryLabel = new JLabel("Connection Lost...");
sorryLabel.setFont(GUIColorsAndFonts.smallFont1);
sorryLabel.setForeground(GUIColorsAndFonts.fontColor1);
setTitlePanel("Connection Lost");
addToCentralColumn(sorryLabel,1,1);
addToCentralColumn(ButtonMaker.makeButton("Return to main menu", returnButtonActionListener),1,1);
}
private ActionListener returnButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
getGraphicsMaster().changeGUIStateTo(GraphicsMaster.GUIStates.MAIN_MENU);
}
};
@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) {
}
}
package graphics.guiSkeleton.guiPanel.menuPanel;
package graphics.guiSkeleton.guiPanel.menuPanel.configuration;
import graphics.guiSkeleton.GUIColorsAndFonts;
import graphics.guiSkeleton.GraphicsMaster;
......@@ -17,25 +17,15 @@ import java.awt.event.ActionListener;
public class ConfigurationPanel extends MenuPanel {
private static final long serialVersionUID = 1L;
//TODO use those variable
/**
* if one configuration button is pressed then the corresponding variable
* is modified to true showing we are currently modifying it
*/
private static boolean escape = false;
private static boolean circle = false;
private static boolean square = false;
private static boolean triangle = false;
private static boolean moveUp = false;
private static boolean moveDown = false;
private static boolean moveRight = false;
private static boolean moveLeft = false;
private static Input InputBeingChanged = Input.NONE;
public static Input GetInputBeingChanged(){return InputBeingChanged;}
/** create a key Labels */
private JLabel makeKeyLabel(Input input){
JLabel keyLabel = new JLabel();
keyLabel.setFont(GUIColorsAndFonts.buttonFont1);
keyLabel.setText(InputConfiguration.GetKey(input));
keyLabel.setText(InputConfiguration.GetFormalInputString(input));
keyLabel.setForeground(GUIColorsAndFonts.fontColor1);
return keyLabel;
}
......@@ -44,51 +34,77 @@ public class ConfigurationPanel extends MenuPanel {
super(graphicsMaster);
setTitlePanel("Configuration");
addToCentralColumn(ButtonMaker.makeButton("move up: " + (InputConfiguration.GetKey(Input.UP_ARROW)), configUpListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move up: ", configUpListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move down: ", configDownListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move right: ", configLeftListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("move left: ", configRightListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("attack: ", configAttackListener),1,1);
addToCentralColumn(ButtonMaker.makeButton("ability 1: ", configAbility1Listener),1,1);
addToCentralColumn(ButtonMaker.makeButton("ability 2: ", configAbility2Listener),1,1);
addToCentralColumn(ButtonMaker.makeButton("ability 3: ", configAbility3Listener),1,1);
addToCentralColumn(ButtonMaker.makeButton("back: ", backButtonListener),1,1);
//TODO: not working for now
/*// Creation of the list of the keys linked with the buttons previously created
ArrayList<JPanel> keyList = new ArrayList<JPanel>();
keyList.add(makeKeyLabel(Input.UP_ARROW));*/
}
/**###################################**/
/** List of the configuration buttons **/
/**###################################**/
private ActionListener configUpListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveUp=true;System.out.println(moveUp);
InputBeingChanged=Input.UP_ARROW;
InputChangeFrame.main("Move Up: current control: "+(InputConfiguration.GetFormalInputString(Input.UP_ARROW)));
}
};
private ActionListener configDownListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveDown=true;
InputBeingChanged=Input.DOWN_ARROW;
InputChangeFrame.main("Move Down: current control: "+(InputConfiguration.GetFormalInputString(Input.DOWN_ARROW)));
}
};
private ActionListener configLeftListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.LEFT_ARROW;
InputChangeFrame.main("Move Left: current control: "+(InputConfiguration.GetFormalInputString(Input.LEFT_ARROW)));
}
};
private ActionListener configRightListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveRight=true;
InputBeingChanged=Input.RIGHT_ARROW;
InputChangeFrame.main("Move Right: current control: "+(InputConfiguration.GetFormalInputString(Input.RIGHT_ARROW)));
}
};
private ActionListener configLeftListener = new ActionListener() {
private ActionListener configAttackListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
moveLeft=true;
InputBeingChanged=Input.ATTACK;
InputChangeFrame.main("Attack: current control: "+(InputConfiguration.GetFormalInputString(Input.ATTACK)));
}
};
private ActionListener configAbility1Listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.ABILITY_1;
InputChangeFrame.main("First Ability: current control: "+(InputConfiguration.GetFormalInputString(Input.ABILITY_1)));
}
};
private ActionListener configAbility2Listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.ABILITY_2;
InputChangeFrame.main("Second Ability: current control: "+(InputConfiguration.GetFormalInputString(Input.ABILITY_2)));}
};
private ActionListener configAbility3Listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InputBeingChanged=Input.ABILITY_3;
InputChangeFrame.main("Third Ability: current control: "+(InputConfiguration.GetFormalInputString(Input.ABILITY_3)));
}
};
private ActionListener backButtonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
......@@ -100,24 +116,11 @@ public class ConfigurationPanel extends MenuPanel {
/** necessary as extension of guiPanel **/
/**###################################**/
@Override
public void keyPressedHandler(Input e) {
//TODO: find a way to do this : change Input e into KeyEvent e
/*if(moveUp==true){moveUp=false;System.out.println(moveUp);InputConfiguration.ChangeKey(Input.UP_ARROW,KeyEvent.VK_B);System.out.println(InputConfiguration.up);}
if (escape) {escape=false; InputConfiguration.ChangeInput(e,Input.ESCAPE);}
if (moveUp){moveUp=false; InputConfiguration.ChangeInput(e,Input.UP_ARROW);}
if (moveDown){moveDown=false; InputConfiguration.ChangeInput(e,Input.DOWN_ARROW);}
if (moveLeft) {moveLeft=false; InputConfiguration.ChangeInput(e,Input.LEFT_ARROW);}
if (moveRight){moveRight=false; InputConfiguration.ChangeInput(e,Input.RIGHT_ARROW);}
*/
}
public void keyPressedHandler(Input e) {}
@Override
public void keyReleasedHandler(Input e) {
// if(moveUp==true){moveUp=false; InputConfiguration.ChangeKey(Input.UP_ARROW,KeyEvent.VK_B);System.out.println(InputConfiguration.up);}
}
public void keyReleasedHandler(Input e) {}
@Override
public void keyTypedHandler(Input e) {
//if(moveUp==true){moveUp=false; InputConfiguration.ChangeKey(Input.UP_ARROW,KeyEvent.VK_B);System.out.println(InputConfiguration.up);}
}
public void keyTypedHandler(Input e) {}
@Override
public void initialise() {}
@Override
......
package graphics.guiSkeleton.guiPanel.menuPanel.configuration;
import graphics.ingame_input_listener.InputConfiguration;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
/**
* Created by zobi on 02/01/16.
*/
public class InputChangeFrame extends Frame implements ActionListener{
private ArrayList<Button> b= new ArrayList<Button>();
public static void main(String string) {
InputChangeFrame myWindow = new InputChangeFrame(string);
myWindow.setSize(600, 600);
myWindow.setVisible(true);
}
public InputChangeFrame(String title) {
super(title);
setLayout(new GridLayout(13, 2));
String alphabet="abcdefghijklmnopqrstuvwxyz";
for (int i=0;i<alphabet.length();i++) {
b.add(new Button(Character.toString(alphabet.charAt(i))));
b.get(i).addActionListener(this);
add(b.get(i));
}
}
public void actionPerformed(ActionEvent e) {
Object source=e.getSource();
for(int i=0;i<b.size();i++){
if(source==b.get(i)){
InputConfiguration.ChangeInput(ConfigurationPanel.GetInputBeingChanged(),b.get(i).getLabel());
dispose();
}
}
}
}
\ No newline at end of file
package graphics.guiSkeleton.guiPanel.menuPanel.loungePanel;
import graphics.graphical_abstraction.GraphicsMasterAbstraction;