Commit ed3617c8 authored by Arnaud Guerquin's avatar Arnaud Guerquin

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

parents 7b72c26d 8414b73e
......@@ -2,26 +2,64 @@ 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);
/**
* Create a new AI of indicated type given as context a gameContent and a relayer to contact.
* @param gameContent
* @param dmr
* @param type the behaviour of the AI to create
*/
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);
}
/**
* Return all the AIs active or created but not active.
* @return the list of AIs
*/
public static ArrayList<AbstractEntity> getList() {
return list;
}
/**
* In order to know how many AIs are created.
* @return the size of the list
*/
public static int getNumber() {
return list.size();
}
/**
* To use for example at the end of a map.
*/
public static void killAll(){
for(AbstractEntity ai :list){
ai.setEndThread(false);
......@@ -29,6 +67,9 @@ public class AIControler {
list.clear();
}
/**
* To start all the AIs at the begining of the map and after init complete inialization.
*/
public static void startAll() {
for(AbstractEntity ai :list){
ai.start();
......
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{}
package graphics.graphical_utility;
import core.zone.Point;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
/**
* Created by etouss on 20/12/2015.
*/
......@@ -12,4 +15,29 @@ public final class GraphicalBridgeConfiguration {
public static final int TILE_SCALE=32;
public static final int TILE_SIZE=16;
/**
* Converts a distance expressed in the Core coordinate system to the same distance, expressed in the Graphics coordinate system
* @param distanceInCoreSystem
* @return
*/
public static final int core2Graphics(int distanceInCoreSystem) {
return ( (int) ((float) distanceInCoreSystem * (float) TILE_SCALE / (float) (Point.TileScale)));
}
//For checking the core2Graphics method
public static void main(String[] args){
System.out.println("DistanceConverterCheck: Input="+50+", Output="+ core2Graphics(50));
}
/**
* Convert the coordinates of a Point instance (defined in the core) to an instance of GraphicsMapPoint (with coordinates in the Swing system)
* @param x: the x coordinate of an instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @param y: the y coordinate of the same instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @return
*/
public static GraphicsMapPoint makeMapPointFromCoreCoordinates(int x, int y)
{
return new GraphicsMapPoint(core2Graphics(y), core2Graphics(x));
}
}
package graphics.guiSkeleton.entityDisplayer;
import core.gamestate.Being;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
import graphics.guiSkeleton.mapManagement.PositionedSprite;
......@@ -37,7 +38,7 @@ public class HealthBarDisplayer {
int hp = being.getHP();
int maxHP = being.getMaxHP();
float healthRatio = ((float)hp)/maxHP;
GraphicsMapPoint beingPosition = graphicsMap.makeMapPointFromCoreCoordinates(being.getX(), being.getY());
GraphicsMapPoint beingPosition = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(being.getX(), being.getY());
//applying translation
GraphicsMapPoint healthBarContainerTopLeft = beingPosition.translate(- assumedSpriteWidth/2, assumedSpriteHeight + yOffsetForHealthBarContainer);
......
......@@ -2,6 +2,7 @@ package graphics.guiSkeleton.entityDisplayer.entityDisplayerBank;
import core.gamestate.Action;
import core.gamestate.Entity;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayer;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
......@@ -44,7 +45,7 @@ public class ChatRoseEntityDisplayer extends EntityDisplayer {
Sprite sprite = SpriteStorage.getInstance().getChatRose();
Entity entity = getAssociatedEntity();
GraphicsMapPoint entityPositionGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
GraphicsMapPoint entityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
//applying translation
GraphicsMapPoint spriteTopLeftGraphicsMapPoint = entityPositionGraphicsMapPoint.translate(- sprite_width/2, - sprite_height/2);
int direction = entity.getDirection().ordinal();
......
package graphics.guiSkeleton.entityDisplayer.entityDisplayerBank;
import core.gamestate.Entity;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayer;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
......@@ -26,7 +27,7 @@ public class InvisibleEntityDisplayer extends EntityDisplayer {
public PositionedSprite getPositionedSprite(GraphicsMap graphicsMap) {
Sprite sprite = SpriteStorage.getInstance().getInvisible();
Entity entity = getAssociatedEntity();
GraphicsMapPoint entityPositionGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
GraphicsMapPoint entityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
return PositionedSprite.PositionSprite(sprite, entityPositionGraphicsMapPoint);
}
}
......@@ -2,6 +2,7 @@ package graphics.guiSkeleton.entityDisplayer.entityDisplayerBank;
import core.gamestate.Entity;
import core.gamestate.Action;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.guiSkeleton.mapManagement.GraphicsMap;
import graphics.guiSkeleton.entityDisplayer.EntityDisplayer;
import graphics.guiSkeleton.mapManagement.GraphicsMapPoint;
......@@ -41,7 +42,7 @@ public class RonflexEntityDisplayer extends EntityDisplayer {
Sprite sprite = SpriteStorage.getInstance().getRonflex();
Entity entity = getAssociatedEntity();
GraphicsMapPoint entityPositionGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
GraphicsMapPoint entityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(entity.getX(), entity.getY());
//applying translation
GraphicsMapPoint spriteTopLeftGraphicsMapPoint = entityPositionGraphicsMapPoint.translate(- sprite_width/2, - sprite_height/2);
int direction = entity.getDirection().ordinal();
......
......@@ -12,6 +12,7 @@ import gameloop.DummyLocalGameLoop;
import gameloop.GameStarter;
import graphics.graphical_abstraction.panel.GamePanelAbstraction;
import graphics.graphical_abstraction.panel.GamePanelAbstractionController;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.graphical_utility.coreProcesses.GameContentMapChangeListener;
import graphics.guiSkeleton.*;
import graphics.guiSkeleton.entityDisplayer.HealthBarDisplayer;
......@@ -85,7 +86,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
//Getting the map, creating a bufferedImage out of it and storing it
GraphicsMap graphicsMap = MapDrawer.drawMap(gameContent.getMap());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftGraphicsMapPoint, getSize().width, getSize().height, graphicsMap);
topLeftLabel = new JLabel("Press ESC to go back to main menu");
......@@ -162,7 +163,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
// System.out.println("coreEntityTopLeft "+processedEntity.getTopLeft().getPosX()+","+processedEntity.getTopLeft().getPosY());
//Debug
// System.out.println("coreColBoxTopLeft "+collisionBox.getTopLeft().getPosX()+","+collisionBox.getTopLeft().getPosY());
GraphicsMapPoint graphicsTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
GraphicsMapPoint graphicsTopLeft = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
//Debug
// GraphicsMapPoint graphicsEntityTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(processedEntity.getTopLeft().getPosX(), processedEntity.getTopLeft().getPosY());
//Debug
......@@ -175,11 +176,11 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
if(zone instanceof Rectangle){
Rectangle rectColBox = (Rectangle) zone;
//getWidth and getHeight may have to be swapped (these are method from the core, and I'm unsure about what their return mean in swing coordinate system)
g.drawRect(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(rectColBox.getWidth()), DistanceConverter.core2Graphics(rectColBox.getHeight()));
g.drawRect(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getWidth()), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getHeight()));
}
if(zone instanceof Circle){
Circle circleColBox = (Circle) zone;
g.drawOval(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()));
g.drawOval(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()));
}
}
......@@ -193,7 +194,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
}
/** Get the GraphicsMapPoint of the position of the entity followed by the gamePanel **/
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
if (debugMapPoint) {
System.out.println("followedEntityPositionGraphicsMapPoint:");
followedEntityPositionGraphicsMapPoint.print();
......@@ -282,7 +283,7 @@ public class GamePanel extends GUIPanel implements GameContentMapChangeListener,
@Override
public void mapChange() {
GraphicsMap graphicsMap = MapDrawer.drawMap(DummyLocalGameLoop.getInstance().getContent().getMap());
GraphicsMapPoint initialTopLeftMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftMapPoint, getSize().width, getSize().height, graphicsMap);
repaint();
}
......
......@@ -10,6 +10,7 @@ import gameloop.DummyLocalGameLoop;
import gameloop.GameStarter;
import graphics.graphical_abstraction.panel.GamePanelAbstraction;
import graphics.graphical_abstraction.panel.GamePanelAbstractionController;
import graphics.graphical_utility.GraphicalBridgeConfiguration;
import graphics.graphical_utility.coreProcesses.GameContentMapChangeListener;
import graphics.guiSkeleton.*;
import graphics.guiSkeleton.entityDisplayer.HealthBarDisplayer;
......@@ -84,7 +85,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
//Getting the map, creating a bufferedImage out of it and storing it
GraphicsMap graphicsMap = MapDrawer.drawMap(gameContent.getMap());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftGraphicsMapPoint, getSize().width, getSize().height, graphicsMap);
topLeftLabel = new JLabel("Press ESC to go back to main menu");
......@@ -161,7 +162,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
// System.out.println("coreEntityTopLeft "+processedEntity.getTopLeft().getPosX()+","+processedEntity.getTopLeft().getPosY());
//Debug
// System.out.println("coreColBoxTopLeft "+collisionBox.getTopLeft().getPosX()+","+collisionBox.getTopLeft().getPosY());
GraphicsMapPoint graphicsTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
GraphicsMapPoint graphicsTopLeft = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(coreTopLeft.getPosX(), coreTopLeft.getPosY());
//Debug
// GraphicsMapPoint graphicsEntityTopLeft = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(processedEntity.getTopLeft().getPosX(), processedEntity.getTopLeft().getPosY());
//Debug
......@@ -174,11 +175,11 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
if(zone instanceof Rectangle){
Rectangle rectColBox = (Rectangle) zone;
//getWidth and getHeight may have to be swapped (these are method from the core, and I'm unsure about what their return mean in swing coordinate system)
g.drawRect(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(rectColBox.getWidth()), DistanceConverter.core2Graphics(rectColBox.getHeight()));
g.drawRect(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getWidth()), GraphicalBridgeConfiguration.core2Graphics(rectColBox.getHeight()));
}
if(zone instanceof Circle){
Circle circleColBox = (Circle) zone;
g.drawOval(gpmp.getX(), gpmp.getY(), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()), DistanceConverter.core2Graphics(2 * circleColBox.getRadius()));
g.drawOval(gpmp.getX(), gpmp.getY(), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()), GraphicalBridgeConfiguration.core2Graphics(2 * circleColBox.getRadius()));
}
}
......@@ -192,7 +193,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
}
/** Get the GraphicsMapPoint of the position of the entity followed by the gamePanel **/
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = visionBox.getGraphicsMap().makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint followedEntityPositionGraphicsMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
if (debugMapPoint) {
System.out.println("followedEntityPositionGraphicsMapPoint:");
followedEntityPositionGraphicsMapPoint.print();
......@@ -274,7 +275,7 @@ public class GamePanel2 extends GUIPanel implements GameContentMapChangeListener
@Override
public void mapChange() {
GraphicsMap graphicsMap = MapDrawer.drawMap(DummyLocalGameLoop.getInstance().getContent().getMap());
GraphicsMapPoint initialTopLeftMapPoint = graphicsMap.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
GraphicsMapPoint initialTopLeftMapPoint = GraphicalBridgeConfiguration.makeMapPointFromCoreCoordinates(followedRelayer.getCharacter().getX(), followedRelayer.getCharacter().getY());
visionBox = new VisionBox(initialTopLeftMapPoint, getSize().width, getSize().height, graphicsMap);
repaint();
}
......
......@@ -45,14 +45,5 @@ public class GraphicsMap {
return Width * TileSprite.TileSpriteWidth();
}
/**
* Convert the coordinates of a Point instance (defined in the core) to an instance of GraphicsMapPoint (with coordinates in the Swing system)
* @param x: the x coordinate of an instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @param y: the y coordinate of the same instance of Point (IN THE CORE COORDINATE SYSTEM !)
* @return
*/
public GraphicsMapPoint makeMapPointFromCoreCoordinates(int x, int y)
{
return new GraphicsMapPoint(y,x);
}
}
package graphics.guiSkeleton.mapManagement;
package graphics.guiSkeleton.mapManagement.trash;
import core.zone.Point;
import graphics.guiSkeleton.tileSpriteLinker.TileSprite;
......
......@@ -7,6 +7,8 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
/** First iteration of the panel for ingame programming
Created by Alexis Ghyselen **/
......@@ -49,7 +51,7 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
add(titlePanel, c);
/** Creation of the buttonPanel **/
JPanel buttonPanel = new JPanel();
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
buttonPanel.setOpaque(true);
buttonPanel.setBackground(GUIColorsAndFonts.backGround1);
......@@ -89,6 +91,7 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
prflabel[i].setText("");
prflabel[i].setForeground(GUIColorsAndFonts.fontColor1);
prflabel[i].setBackground(GUIColorsAndFonts.buttonBackground1);
prflabel[i].addActionListener(parselistener);
c2 = new GridBagConstraints();
c2.gridx=3; c2.gridy=(i+1); c2.gridwidth=2; c2.gridheight=1; c2.weightx=3; c2.weighty=1; c2.fill=GridBagConstraints.BOTH;
buttonPanel.add(prflabel[i],c2);
......@@ -99,9 +102,9 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
c2 = new GridBagConstraints();
c2.gridx=5; c2.gridy=(i+1); c2.gridwidth=2; c2.gridheight=1; c2.weightx=3; c2.weighty=1; c2.fill=GridBagConstraints.BOTH;
buttonPanel.add(hintlabel[i],c2);
}
/** Back button **/
JButton exitButton = new JButton();
exitButton.setFont(GUIColorsAndFonts.buttonFont1);
......@@ -154,7 +157,7 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
hintlabel[vswitch].setText(s);
bswitch[vswitch].setBackground(GUIColorsAndFonts.buttonBackground1);
vswitch = -1;
}
}
};
......@@ -166,8 +169,34 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
}
};
/**
* ActionListener to parse an instruction.
* Should be modified soon.
*/
private ActionListener parselistener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Script parser = new Script(stringToStream(((JTextField)e.getSource()).getText()));
if (parser.checkInput()) {
System.out.println("L'instruction est correcte");
} else {
System.out.println("Erreur dans l'instruction");
}
}
};
/**
* Convert a String to an equivalent InputStream.
* @param the String to convert.
* @return the equivalent InputStream.
*/
private InputStream stringToStream(String s) {
InputStream is = new ByteArrayInputStream(s.getBytes());
return is;
}
@Override
public void initialise() {
......@@ -187,11 +216,10 @@ public class IGPpanel extends graphics.guiSkeleton.guiPanel.GUIPanel{
public void keyReleasedHandler(Input e) {
}
@Override
public void keyTypedHandler(Input e) {
}
}
}
......@@ -3,14 +3,21 @@ package ingame_programming;
/** Interpréteur du langage de script */
public class Script implements ScriptConstants {
/* TODO. Pour l'instant, on analyse les phrases depuis la ligne de commande. */
public static void main(String args[]) throws ParseException {
Script parser = new Script(System.in);
parser.Instruction();
/**
* Check whether the input is correct.
* @return a boolean about the correctness of the input string.
*/
public boolean checkInput() {
try {
Instruction();
return true;
} catch(ParseException e) {
return false;
}
}
static final public void Instruction() throws ParseException {
final public void Instruction() throws ParseException {
String s, ss;
Token t;
int count = 0;
......@@ -65,7 +72,7 @@ public class Script implements ScriptConstants {
}
/** Détail des options. */
static final public String Option() throws ParseException {
final public String Option() throws ParseException {
String s, ss;
Token t;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
......@@ -178,17 +185,16 @@ public class Script implements ScriptConstants {
}
}
static private boolean jj_initialized_once = false;
/** Generated Token Manager. */
static public ScriptTokenManager token_source;
static SimpleCharStream jj_input_stream;
public ScriptTokenManager token_source;
SimpleCharStream jj_input_stream;
/** Current token. */
static public Token token;
public Token token;
/** Next token. */
static public Token jj_nt;
static private int jj_ntk;
static private int jj_gen;
static final private int[] jj_la1 = new int[6];
public Token jj_nt;
private int jj_ntk;
private int jj_gen;
final private int[] jj_la1 = new int[6];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
......@@ -203,13 +209,6 @@ public class Script implements ScriptConstants {
}
/** Constructor with InputStream and supplied encoding */
public Script(java.io.InputStream stream, String encoding) {
if (jj_initialized_once) {
System.out.println(