From 28c7b3e472f5e5c4d43b099d10c70e0d52c98f2d Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 2 Apr 2017 19:03:33 +0300 Subject: [PATCH 01/62] Init commit --- ConsoleUI/src/ViewScreen.java | 18 ++++++++++++++++++ GameEngine/src/GameDataFromXml.java | 27 +++++++++++++++++++++++++++ GameEngine/src/GameEngine.java | 11 +++++++++++ GameEngine/src/GameInformation.java | 3 --- GameEngine/src/Player.java | 13 ++++++++----- 5 files changed, 64 insertions(+), 8 deletions(-) delete mode 100644 GameEngine/src/GameInformation.java diff --git a/ConsoleUI/src/ViewScreen.java b/ConsoleUI/src/ViewScreen.java index 4f0f71b..de73d7c 100644 --- a/ConsoleUI/src/ViewScreen.java +++ b/ConsoleUI/src/ViewScreen.java @@ -1,4 +1,22 @@ public class ViewScreen { + private int col; + private int row; + + + ViewScreen(int _col, int _row){ + col = _col; + row = _row; + } + public void showBoard(){ + // TODO + } + + public void getMenue(){ + //TODO + } + public void showInstructions(){ + //TODO + } } diff --git a/GameEngine/src/GameDataFromXml.java b/GameEngine/src/GameDataFromXml.java index 1a89ce4..6d17c5b 100644 --- a/GameEngine/src/GameDataFromXml.java +++ b/GameEngine/src/GameDataFromXml.java @@ -1,3 +1,30 @@ +import java.util.HashMap; +import java.util.Map; public class GameDataFromXml { + + Map frequencyLetter = new HashMap (); + Map frequencyWord = new HashMap (); + private int boardSize; + private int numOfCubeWigs; + private int numOfTries; + private int totalTiles; + private int leftBoxTiles; + + //TODO: initializing by the xml + + public class Board { + + private GameDataFromXml boardData; + private int tilesInBoard; + } + + + public int getLeftBoxTiles(){ + return this.leftBoxTiles; + } + + + //TODO: all illiegele issues + xml loading + txt file in dictionary library + } diff --git a/GameEngine/src/GameEngine.java b/GameEngine/src/GameEngine.java index 7492637..4894625 100644 --- a/GameEngine/src/GameEngine.java +++ b/GameEngine/src/GameEngine.java @@ -1,2 +1,13 @@ public class GameEngine { + + private GameDataFromXml data; + private GameInformation info; + private Player player; + + + public void startGame(){ + + // TODO + } + } diff --git a/GameEngine/src/GameInformation.java b/GameEngine/src/GameInformation.java deleted file mode 100644 index abdcf9a..0000000 --- a/GameEngine/src/GameInformation.java +++ /dev/null @@ -1,3 +0,0 @@ - -public class GameInformation { -} diff --git a/GameEngine/src/Player.java b/GameEngine/src/Player.java index 4844ce3..6b80aa8 100644 --- a/GameEngine/src/Player.java +++ b/GameEngine/src/Player.java @@ -1,8 +1,11 @@ +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; public class Player { - private String mName; - private float mScore; - - -} + private String name; + private float score; + private Map numOfWords = new HashMap (); + } From 0866c65b0a3be7dcc2af3596a0e38c62670aa452 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 3 Apr 2017 16:38:21 +0300 Subject: [PATCH 02/62] Add menu and fix Map configuration --- ConsoleUI/src/MenuHandler.java | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ConsoleUI/src/MenuHandler.java diff --git a/ConsoleUI/src/MenuHandler.java b/ConsoleUI/src/MenuHandler.java new file mode 100644 index 0000000..f85f262 --- /dev/null +++ b/ConsoleUI/src/MenuHandler.java @@ -0,0 +1,37 @@ +import java.util.Scanner; + +public class MenuHandler { + + public static int showMainMenu() { + int selectedMenuItem; + Scanner scanner = new Scanner(System.in); + + System.out.println("Please select an option:"); + System.out.println("1. Load game from xml."); + System.out.println("2. Start game."); + System.out.println("3. Show board."); + System.out.println("4. Make a move."); + System.out.println("5. Show statistics."); + System.out.println("6. Exit game."); + + selectedMenuItem = scanner.nextInt(); + if (selectedMenuItem < 1 && selectedMenuItem > 6) { + System.out.println("Wrong menu number (need to bo 1-6)."); + } + + return selectedMenuItem; + } + + public static String getXML() { + Scanner scanner = new Scanner(System.in); + String pathToXml; + + System.out.println("Please enter the path to the XML file:"); + pathToXml = scanner.nextLine(); + if (!pathToXml.toLowerCase().endsWith(".xml")) { + System.out.println("The path entered is not to a XML file!"); + } + + return pathToXml; + } +} From 2f9a08c58fc30c6d0a0378ddb02e200d6de1ccf3 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 3 Apr 2017 16:38:21 +0300 Subject: [PATCH 03/62] Add menu and fix Map configuration --- ConsoleUI/src/ConsoleUI.java | 27 +++++++++++++++++++++ ConsoleUI/src/MenuHandler.java | 37 +++++++++++++++++++++++++++++ GameEngine/src/GameDataFromXml.java | 6 ++--- GameEngine/src/GameEngine.java | 6 ++++- GameEngine/src/Player.java | 4 ++-- 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 ConsoleUI/src/ConsoleUI.java create mode 100644 ConsoleUI/src/MenuHandler.java diff --git a/ConsoleUI/src/ConsoleUI.java b/ConsoleUI/src/ConsoleUI.java new file mode 100644 index 0000000..f1819bf --- /dev/null +++ b/ConsoleUI/src/ConsoleUI.java @@ -0,0 +1,27 @@ +public class ConsoleUI { + public static void main(String[] args) { + GameEngine engine = new GameEngine(); + int selectedMenu; + while((selectedMenu=MenuHandler.showMainMenu()) != 6){ + switch (selectedMenu){ + case 1: + String pathToXml = MenuHandler.getXML(); + try { + engine.loadXml(pathToXml); + } + catch (Exception e) { + System.out.println("Error, " + e.getMessage()); + } + break; + case 2: + break; + case 3: + break; + case 4: + break; + case 5: + break; + } + } + } +} diff --git a/ConsoleUI/src/MenuHandler.java b/ConsoleUI/src/MenuHandler.java new file mode 100644 index 0000000..f85f262 --- /dev/null +++ b/ConsoleUI/src/MenuHandler.java @@ -0,0 +1,37 @@ +import java.util.Scanner; + +public class MenuHandler { + + public static int showMainMenu() { + int selectedMenuItem; + Scanner scanner = new Scanner(System.in); + + System.out.println("Please select an option:"); + System.out.println("1. Load game from xml."); + System.out.println("2. Start game."); + System.out.println("3. Show board."); + System.out.println("4. Make a move."); + System.out.println("5. Show statistics."); + System.out.println("6. Exit game."); + + selectedMenuItem = scanner.nextInt(); + if (selectedMenuItem < 1 && selectedMenuItem > 6) { + System.out.println("Wrong menu number (need to bo 1-6)."); + } + + return selectedMenuItem; + } + + public static String getXML() { + Scanner scanner = new Scanner(System.in); + String pathToXml; + + System.out.println("Please enter the path to the XML file:"); + pathToXml = scanner.nextLine(); + if (!pathToXml.toLowerCase().endsWith(".xml")) { + System.out.println("The path entered is not to a XML file!"); + } + + return pathToXml; + } +} diff --git a/GameEngine/src/GameDataFromXml.java b/GameEngine/src/GameDataFromXml.java index 6d17c5b..28d3a3a 100644 --- a/GameEngine/src/GameDataFromXml.java +++ b/GameEngine/src/GameDataFromXml.java @@ -3,8 +3,8 @@ public class GameDataFromXml { - Map frequencyLetter = new HashMap (); - Map frequencyWord = new HashMap (); + Map frequencyLetter = new HashMap (); + Map frequencyWord = new HashMap (); private int boardSize; private int numOfCubeWigs; private int numOfTries; @@ -27,4 +27,4 @@ public int getLeftBoxTiles(){ //TODO: all illiegele issues + xml loading + txt file in dictionary library -} +} \ No newline at end of file diff --git a/GameEngine/src/GameEngine.java b/GameEngine/src/GameEngine.java index 4894625..75ff22e 100644 --- a/GameEngine/src/GameEngine.java +++ b/GameEngine/src/GameEngine.java @@ -1,7 +1,7 @@ public class GameEngine { private GameDataFromXml data; - private GameInformation info; + // private GameInformation info; private Player player; @@ -10,4 +10,8 @@ public void startGame(){ // TODO } + public void loadXml(String pathToXml) { + // TODO + } + } diff --git a/GameEngine/src/Player.java b/GameEngine/src/Player.java index 6b80aa8..94979ab 100644 --- a/GameEngine/src/Player.java +++ b/GameEngine/src/Player.java @@ -7,5 +7,5 @@ public class Player { private String name; private float score; - private Map numOfWords = new HashMap (); - } + private Map numOfWords = new HashMap (); +} From 16410f501a079e5b401db6d637f69d9c56d5332e Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Tue, 4 Apr 2017 00:40:51 +0300 Subject: [PATCH 04/62] statistic + rungame --- ConsoleUI/src/RunGame.java | 10 ++++++++++ GameEngine/src/Statistic.java | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ConsoleUI/src/RunGame.java create mode 100644 GameEngine/src/Statistic.java diff --git a/ConsoleUI/src/RunGame.java b/ConsoleUI/src/RunGame.java new file mode 100644 index 0000000..1e7d9f9 --- /dev/null +++ b/ConsoleUI/src/RunGame.java @@ -0,0 +1,10 @@ + +public class RunGame { + + private GameEngine ge; + + public void run(){ + + ge.startGame(); + } +} diff --git a/GameEngine/src/Statistic.java b/GameEngine/src/Statistic.java new file mode 100644 index 0000000..c678ef0 --- /dev/null +++ b/GameEngine/src/Statistic.java @@ -0,0 +1,18 @@ +import java.util.List; + +public class Statistic { + + private List players ; + private int numOfTurns; + private int leftBoxTiles; + private float time; //TODO: calculate + private GameDataFromXml gameData; + + + Statistic(List input_Player){ + players.addAll(input_Player) ; + numOfTurns = 0; + leftBoxTiles = gameData.getLeftBoxTiles(); + } + +} \ No newline at end of file From 0fcb4186d5d73d5e3d47a69178463070d470a6ae Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 23 Apr 2017 17:57:24 +0300 Subject: [PATCH 05/62] xml load --- GameEngine/src/GameDataFromXml.java | 30 --- GameEngine/src/GameEngine.java | 17 -- GameEngine/src/engine/GameDataFromXml.java | 201 ++++++++++++++++++ GameEngine/src/engine/GameEngine.java | 33 +++ GameEngine/src/{ => engine}/Player.java | 2 + GameEngine/src/{ => engine}/Statistic.java | 5 +- .../src/engine/jabx/SimpleJAXBMain.java | 5 + .../jabx/schema/SchemaBasedJAXBMain.java | 47 ++++ .../jabx/schema/generated/DynamicPlayers.java | 97 +++++++++ .../jabx/schema/generated/GameDescriptor.java | 148 +++++++++++++ .../jabx/schema/generated/GameType.java | 123 +++++++++++ .../engine/jabx/schema/generated/Letter.java | 111 ++++++++++ .../engine/jabx/schema/generated/Letters.java | 91 ++++++++ .../jabx/schema/generated/ObjectFactory.java | 177 +++++++++++++++ .../engine/jabx/schema/generated/Player.java | 120 +++++++++++ .../engine/jabx/schema/generated/Players.java | 71 +++++++ .../jabx/schema/generated/STGameType.java | 48 +++++ .../jabx/schema/generated/Structure.java | 157 ++++++++++++++ .../engine/jabx/schema/generated/Wordiada.xsd | 127 +++++++++++ GameEngine/src/resources/Wordiada.xsd | 127 +++++++++++ 20 files changed, 1689 insertions(+), 48 deletions(-) delete mode 100644 GameEngine/src/GameDataFromXml.java delete mode 100644 GameEngine/src/GameEngine.java create mode 100644 GameEngine/src/engine/GameDataFromXml.java create mode 100644 GameEngine/src/engine/GameEngine.java rename GameEngine/src/{ => engine}/Player.java (93%) rename GameEngine/src/{ => engine}/Statistic.java (86%) create mode 100644 GameEngine/src/engine/jabx/SimpleJAXBMain.java create mode 100644 GameEngine/src/engine/jabx/schema/SchemaBasedJAXBMain.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/DynamicPlayers.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/GameDescriptor.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/GameType.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/Letter.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/Letters.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/ObjectFactory.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/Player.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/Players.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/STGameType.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/Structure.java create mode 100644 GameEngine/src/engine/jabx/schema/generated/Wordiada.xsd create mode 100644 GameEngine/src/resources/Wordiada.xsd diff --git a/GameEngine/src/GameDataFromXml.java b/GameEngine/src/GameDataFromXml.java deleted file mode 100644 index 28d3a3a..0000000 --- a/GameEngine/src/GameDataFromXml.java +++ /dev/null @@ -1,30 +0,0 @@ -import java.util.HashMap; -import java.util.Map; - -public class GameDataFromXml { - - Map frequencyLetter = new HashMap (); - Map frequencyWord = new HashMap (); - private int boardSize; - private int numOfCubeWigs; - private int numOfTries; - private int totalTiles; - private int leftBoxTiles; - - //TODO: initializing by the xml - - public class Board { - - private GameDataFromXml boardData; - private int tilesInBoard; - } - - - public int getLeftBoxTiles(){ - return this.leftBoxTiles; - } - - - //TODO: all illiegele issues + xml loading + txt file in dictionary library - -} \ No newline at end of file diff --git a/GameEngine/src/GameEngine.java b/GameEngine/src/GameEngine.java deleted file mode 100644 index 75ff22e..0000000 --- a/GameEngine/src/GameEngine.java +++ /dev/null @@ -1,17 +0,0 @@ -public class GameEngine { - - private GameDataFromXml data; - // private GameInformation info; - private Player player; - - - public void startGame(){ - - // TODO - } - - public void loadXml(String pathToXml) { - // TODO - } - -} diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java new file mode 100644 index 0000000..720f605 --- /dev/null +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -0,0 +1,201 @@ +package engine; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.sql.Struct; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.lang.Character; +import java.lang.String; + + +import engine.jabx.schema.generated.GameDescriptor; +import engine.jabx.schema.generated.Letter; +import engine.jabx.schema.generated.Letters; +import engine.jabx.schema.generated.Structure; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + + +public class GameDataFromXml { + + Map frequencyLetter = new HashMap(); + Map frequencyWord = new HashMap(); + List letters; + private int boardSize; + private int numOfCubeWigs; + private int numOfTries; + private int totalTiles; + private int leftBoxTiles; + + private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jabx.schema.generated"; + + + public void initializingDataFromXml(String pathToXml) { + + GameDescriptor gd; + InputStream inputStream = null; + + // TODO: delete note after tests + /* + try { + inputStream = new FileInputStream(pathToXml); + } catch (FileNotFoundException e) { + e.printStackTrace(); + }*/ + + + inputStream = GameDataFromXml.class.getResourceAsStream("/resources/master.xml"); + Structure struct; + + try { + gd = deserializeFrom(inputStream); + struct = gd.getStructure(); + Letters letters = struct.getLetters(); + + // creates list of letters + frequency + + for (int i = 0; i < letters.getLetter().size(); i++) { + this.letters.add(i, letters.getLetter().get(i)); + frequencyLetter.put( this.letters.get(i).getSign().get(0), this.letters.get(i).getFrequency()); + + + } + } catch (JAXBException e) { + e.printStackTrace(); + } + + //init board size + + try { + gd = deserializeFrom(inputStream); + struct = gd.getStructure(); + boardSize = struct.getBoardSize(); + + } catch (JAXBException e) { + e.printStackTrace(); + } + + // init num of cube wigs + try { + gd = deserializeFrom(inputStream); + struct = gd.getStructure(); + this.numOfCubeWigs = struct.getCubeFacets(); + + } catch (JAXBException e) { + e.printStackTrace(); + } + + + + + // init num of tries + try { + gd = deserializeFrom(inputStream); + struct = gd.getStructure(); + this.numOfTries = struct.getRetriesNumber(); + + } catch (JAXBException e) { + e.printStackTrace(); + } + + } + private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); + Unmarshaller u = jc.createUnmarshaller(); + return (GameDescriptor) u.unmarshal(in); + + } +} + + + + + + /* + GameDescriptor gd; + Structure struct; + InputStream inputStream = GameDataFromXml.class.getResourceAsStream("/resources/master.xml"); + try { + gd = deserializeFrom(inputStream); + struct = gd.getStructure(); + Letters letters = struct.getLetters(); + + // creats list of letters + for (int i = 0; i < letters.getLetter().size(); i++) { + //System.out.println("letter number" + i + ": " + letters.getLetter().get(i).getSign()); + letters.getLetter().add(i, letters.getLetter().get(i)); + } + } catch (JAXBException e) { + e.printStackTrace(); + } + + //init board size + try { + gd = deserializeFrom(inputStream); + + } catch (JAXBException e) { + e.printStackTrace(); + } + + struct = gd.getStructure(); + + boardSize = struct.getBoardSize(); + } + + + private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); + Unmarshaller u = jc.createUnmarshaller(); + return (GameDescriptor)u.unmarshal(in); + }*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + /* + + + + + public int getLeftBoxTiles(){ + return this.leftBoxTiles; + } + + public boolean isValid() + { + Structure struct; + + return true; + + } + + + : all illiegele issues + xml loading + txt file in dictionary library + */ +} \ No newline at end of file diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java new file mode 100644 index 0000000..086e13f --- /dev/null +++ b/GameEngine/src/engine/GameEngine.java @@ -0,0 +1,33 @@ +package engine; + + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +public class GameEngine { + + private GameDataFromXml data; + // private GameInformation info; + private Player player; + + + + + public void loadXml(String pathToXml) { + // TODO + } + + + public boolean isValidXml(String pathToXml) { + String extension = pathToXml.substring(pathToXml.lastIndexOf(".") + 1, pathToXml.length()); + if ((extension != "xml") || (extension != ".xml")) + return false; + return true; + } + public boolean isDictionaryInRightPos(){ + return true; + } + + +} diff --git a/GameEngine/src/Player.java b/GameEngine/src/engine/Player.java similarity index 93% rename from GameEngine/src/Player.java rename to GameEngine/src/engine/Player.java index 94979ab..85b827c 100644 --- a/GameEngine/src/Player.java +++ b/GameEngine/src/engine/Player.java @@ -1,3 +1,5 @@ +package engine; + import java.util.Collection; import java.util.HashMap; import java.util.Map; diff --git a/GameEngine/src/Statistic.java b/GameEngine/src/engine/Statistic.java similarity index 86% rename from GameEngine/src/Statistic.java rename to GameEngine/src/engine/Statistic.java index c678ef0..a64990c 100644 --- a/GameEngine/src/Statistic.java +++ b/GameEngine/src/engine/Statistic.java @@ -1,3 +1,6 @@ +package engine; + + import java.util.List; public class Statistic { @@ -6,7 +9,7 @@ public class Statistic { private int numOfTurns; private int leftBoxTiles; private float time; //TODO: calculate - private GameDataFromXml gameData; + private GameDataFromXml gameData; Statistic(List input_Player){ diff --git a/GameEngine/src/engine/jabx/SimpleJAXBMain.java b/GameEngine/src/engine/jabx/SimpleJAXBMain.java new file mode 100644 index 0000000..7d9c0f5 --- /dev/null +++ b/GameEngine/src/engine/jabx/SimpleJAXBMain.java @@ -0,0 +1,5 @@ +package engine.jabx; + +/** + * Created by נוי on 23/04/2017. + */ diff --git a/GameEngine/src/engine/jabx/schema/SchemaBasedJAXBMain.java b/GameEngine/src/engine/jabx/schema/SchemaBasedJAXBMain.java new file mode 100644 index 0000000..f5bc56a --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/SchemaBasedJAXBMain.java @@ -0,0 +1,47 @@ + +package engine.jabx.schema; + + +//import examples.jaxb.schema.generated.Countries; + +import engine.jabx.schema.generated.GameDescriptor; +import engine.jabx.schema.generated.Letters; +import engine.jabx.schema.generated.Letter; +import engine.jabx.schema.generated.Structure; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.InputStream; + +public class SchemaBasedJAXBMain { + + private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jabx.schema.generated"; + + public static void main(String[] args) { + InputStream inputStream = SchemaBasedJAXBMain.class.getResourceAsStream("/resources/master.xml"); + try { + GameDescriptor gd = deserializeFromletter(inputStream); + Structure struct = gd.getStructure(); + Letters letters = struct.getLetters(); + // System.out.println("sign of first letter is: " + letters.getLetter().get(0).getSign()); + for(int i = 0; i < letters.getLetter().size(); i++){ + System.out.println("letter number" + i + ": " + letters.getLetter().get(i).getSign()); + } + System.out.println("Board size:" + struct.getBoardSize() ); + + } catch (JAXBException e) { + e.printStackTrace(); + } + } + private static GameDescriptor deserializeFromletter(InputStream in) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); + Unmarshaller u = jc.createUnmarshaller(); + return (GameDescriptor)u.unmarshal(in); + } + + + + +} + diff --git a/GameEngine/src/engine/jabx/schema/generated/DynamicPlayers.java b/GameEngine/src/engine/jabx/schema/generated/DynamicPlayers.java new file mode 100644 index 0000000..c5dd07d --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/DynamicPlayers.java @@ -0,0 +1,97 @@ + +package engine.jabx.schema.generated; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <attribute name="total-players" use="required">
+ *         <simpleType>
+ *           <restriction base="{http://www.w3.org/2001/XMLSchema}byte">
+ *             <minInclusive value="2"/>
+ *             <maxInclusive value="6"/>
+ *           </restriction>
+ *         </simpleType>
+ *       </attribute>
+ *       <attribute name="game-title" use="required">
+ *         <simpleType>
+ *           <list itemType="{http://www.w3.org/2001/XMLSchema}string" />
+ *         </simpleType>
+ *       </attribute>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "DynamicPlayers") +public class DynamicPlayers { + + @XmlAttribute(name = "total-players", required = true) + protected byte totalPlayers; + @XmlAttribute(name = "game-title", required = true) + protected List gameTitle; + + /** + * Gets the value of the totalPlayers property. + * + */ + public byte getTotalPlayers() { + return totalPlayers; + } + + /** + * Sets the value of the totalPlayers property. + * + */ + public void setTotalPlayers(byte value) { + this.totalPlayers = value; + } + + /** + * Gets the value of the gameTitle property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the gameTitle property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getGameTitle().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getGameTitle() { + if (gameTitle == null) { + gameTitle = new ArrayList(); + } + return this.gameTitle; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/GameDescriptor.java b/GameEngine/src/engine/jabx/schema/generated/GameDescriptor.java new file mode 100644 index 0000000..9b9937b --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/GameDescriptor.java @@ -0,0 +1,148 @@ + +package engine.jabx.schema.generated; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{}GameType"/>
+ *         <element ref="{}Structure"/>
+ *         <element ref="{}Players" minOccurs="0"/>
+ *         <element ref="{}DynamicPlayers" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "gameType", + "structure", + "players", + "dynamicPlayers" +}) +@XmlRootElement(name = "GameDescriptor") +public class GameDescriptor { + + @XmlElement(name = "GameType", required = true) + protected GameType gameType; + @XmlElement(name = "Structure", required = true) + protected Structure structure; + @XmlElement(name = "Players") + protected Players players; + @XmlElement(name = "DynamicPlayers") + protected DynamicPlayers dynamicPlayers; + + /** + * Gets the value of the gameType property. + * + * @return + * possible object is + * {@link GameType } + * + */ + public GameType getGameType() { + return gameType; + } + + /** + * Sets the value of the gameType property. + * + * @param value + * allowed object is + * {@link GameType } + * + */ + public void setGameType(GameType value) { + this.gameType = value; + } + + /** + * Gets the value of the structure property. + * + * @return + * possible object is + * {@link Structure } + * + */ + public Structure getStructure() { + return structure; + } + + /** + * Sets the value of the structure property. + * + * @param value + * allowed object is + * {@link Structure } + * + */ + public void setStructure(Structure value) { + this.structure = value; + } + + /** + * Gets the value of the players property. + * + * @return + * possible object is + * {@link Players } + * + */ + public Players getPlayers() { + return players; + } + + /** + * Sets the value of the players property. + * + * @param value + * allowed object is + * {@link Players } + * + */ + public void setPlayers(Players value) { + this.players = value; + } + + /** + * Gets the value of the dynamicPlayers property. + * + * @return + * possible object is + * {@link DynamicPlayers } + * + */ + public DynamicPlayers getDynamicPlayers() { + return dynamicPlayers; + } + + /** + * Sets the value of the dynamicPlayers property. + * + * @param value + * allowed object is + * {@link DynamicPlayers } + * + */ + public void setDynamicPlayers(DynamicPlayers value) { + this.dynamicPlayers = value; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/GameType.java b/GameEngine/src/engine/jabx/schema/generated/GameType.java new file mode 100644 index 0000000..c2f4a92 --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/GameType.java @@ -0,0 +1,123 @@ + +package engine.jabx.schema.generated; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <simpleContent>
+ *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *       <attribute name="winner-according-to" use="required">
+ *         <simpleType>
+ *           <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *             <enumeration value="WordCount"/>
+ *             <enumeration value="WordScore"/>
+ *           </restriction>
+ *         </simpleType>
+ *       </attribute>
+ *       <attribute name="gold-fish-mode" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *     </extension>
+ *   </simpleContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "value" +}) +@XmlRootElement(name = "GameType") +public class GameType { + + @XmlValue + protected String value; + @XmlAttribute(name = "winner-according-to", required = true) + protected String winnerAccordingTo; + @XmlAttribute(name = "gold-fish-mode") + protected Boolean goldFishMode; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the winnerAccordingTo property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWinnerAccordingTo() { + return winnerAccordingTo; + } + + /** + * Sets the value of the winnerAccordingTo property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWinnerAccordingTo(String value) { + this.winnerAccordingTo = value; + } + + /** + * Gets the value of the goldFishMode property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isGoldFishMode() { + return goldFishMode; + } + + /** + * Sets the value of the goldFishMode property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setGoldFishMode(Boolean value) { + this.goldFishMode = value; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/Letter.java b/GameEngine/src/engine/jabx/schema/generated/Letter.java new file mode 100644 index 0000000..8c764e8 --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/Letter.java @@ -0,0 +1,111 @@ + +package engine.jabx.schema.generated; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlList; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <all>
+ *         <element ref="{}Sign"/>
+ *         <element ref="{}Score"/>
+ *         <element ref="{}Frequency"/>
+ *       </all>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + +}) +@XmlRootElement(name = "Letter") +public class Letter { + + @XmlList + @XmlElement(name = "Sign", required = true) + protected List sign; + @XmlElement(name = "Score") + protected byte score; + @XmlElement(name = "Frequency") + protected double frequency; + + /** + * Gets the value of the sign property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the sign property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getSign().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getSign() { + if (sign == null) { + sign = new ArrayList(); + } + return this.sign; + } + + /** + * Gets the value of the score property. + * + */ + public byte getScore() { + return score; + } + + /** + * Sets the value of the score property. + * + */ + public void setScore(byte value) { + this.score = value; + } + + /** + * Gets the value of the frequency property. + * + */ + public double getFrequency() { + return frequency; + } + + /** + * Sets the value of the frequency property. + * + */ + public void setFrequency(double value) { + this.frequency = value; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/Letters.java b/GameEngine/src/engine/jabx/schema/generated/Letters.java new file mode 100644 index 0000000..177fc60 --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/Letters.java @@ -0,0 +1,91 @@ + +package engine.jabx.schema.generated; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{}Letter" maxOccurs="unbounded"/>
+ *       </sequence>
+ *       <attribute name="target-deck-size" use="required" type="{http://www.w3.org/2001/XMLSchema}short" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "letter" +}) +@XmlRootElement(name = "Letters") +public class Letters { + + @XmlElement(name = "Letter", required = true) + protected List letter; + @XmlAttribute(name = "target-deck-size", required = true) + protected short targetDeckSize; + + /** + * Gets the value of the letter property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the letter property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getLetter().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Letter } + * + * + */ + public List getLetter() { + if (letter == null) { + letter = new ArrayList(); + } + return this.letter; + } + + /** + * Gets the value of the targetDeckSize property. + * + */ + public short getTargetDeckSize() { + return targetDeckSize; + } + + /** + * Sets the value of the targetDeckSize property. + * + */ + public void setTargetDeckSize(short value) { + this.targetDeckSize = value; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/ObjectFactory.java b/GameEngine/src/engine/jabx/schema/generated/ObjectFactory.java new file mode 100644 index 0000000..c05c088 --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/ObjectFactory.java @@ -0,0 +1,177 @@ +package engine.jabx.schema.generated; + +import engine.GameEngine; + +import java.util.List; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBContext; + +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the engine.xml package. + *

An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _Type_QNAME = new QName("", "Type"); + private final static QName _Score_QNAME = new QName("", "Score"); + private final static QName _BoardSize_QNAME = new QName("", "BoardSize"); + private final static QName _Frequency_QNAME = new QName("", "Frequency"); + private final static QName _Sign_QNAME = new QName("", "Sign"); + private final static QName _Name_QNAME = new QName("", "Name"); + private final static QName _DictionaryFileName_QNAME = new QName("", "DictionaryFileName"); + + + + //engine.jabx.schema.generated.ObjectFactory objectFactory = new engine.jabx.schema.generated.ObjectFactory(); + // JAXBContext jaxbContext tring()); + /** + * + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: engine.xml + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Player } + * + */ + public Player createPlayer() { + return new Player(); + } + + /** + * Create an instance of {@link Letters } + * + */ + public Letters createLetters() { + return new Letters(); + } + + /** + * Create an instance of {@link Letter } + * + */ + public Letter createLetter() { + return new Letter(); + } + + /** + * Create an instance of {@link GameType } + * + */ + public GameType createGameType() { + return new GameType(); + } + + /** + * Create an instance of {@link Structure } + * + */ + public Structure createStructure() { + return new Structure(); + } + + /** + * Create an instance of {@link GameDescriptor } + * + */ + public GameDescriptor createGameDescriptor() { + return new GameDescriptor(); + } + + /** + * Create an instance of {@link Players } + * + */ + public Players createPlayers() { + return new Players(); + } + + /** + * Create an instance of {@link DynamicPlayers } + * + */ + public DynamicPlayers createDynamicPlayers() { + return new DynamicPlayers(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Type") + public JAXBElement createType(String value) { + return new JAXBElement(_Type_QNAME, String.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Byte }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Score") + public JAXBElement createScore(Byte value) { + return new JAXBElement(_Score_QNAME, Byte.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Byte }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "BoardSize") + public JAXBElement createBoardSize(Byte value) { + return new JAXBElement(_BoardSize_QNAME, Byte.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Double }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Frequency") + public JAXBElement createFrequency(Double value) { + return new JAXBElement(_Frequency_QNAME, Double.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link List }{@code <}{@link String }{@code >}{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Sign") + public JAXBElement> createSign(List value) { + return new JAXBElement>(_Sign_QNAME, ((Class) List.class), null, ((List ) value)); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link List }{@code <}{@link String }{@code >}{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Name") + public JAXBElement> createName(List value) { + return new JAXBElement>(_Name_QNAME, ((Class) List.class), null, ((List ) value)); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "DictionaryFileName") + public JAXBElement createDictionaryFileName(String value) { + return new JAXBElement(_DictionaryFileName_QNAME, String.class, null, value); + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/Player.java b/GameEngine/src/engine/jabx/schema/generated/Player.java new file mode 100644 index 0000000..a5d4fa9 --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/Player.java @@ -0,0 +1,120 @@ + +package engine.jabx.schema.generated; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlList; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <all>
+ *         <element ref="{}Name"/>
+ *         <element ref="{}Type"/>
+ *       </all>
+ *       <attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}short" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + +}) +@XmlRootElement(name = "Player") +public class Player { + + @XmlList + @XmlElement(name = "Name", required = true) + protected List name; + @XmlElement(name = "Type", required = true) + protected String type; + @XmlAttribute(name = "id", required = true) + protected short id; + + /** + * Gets the value of the name property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the name property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getName().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getName() { + if (name == null) { + name = new ArrayList(); + } + return this.name; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Gets the value of the id property. + * + */ + public short getId() { + return id; + } + + /** + * Sets the value of the id property. + * + */ + public void setId(short value) { + this.id = value; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/Players.java b/GameEngine/src/engine/jabx/schema/generated/Players.java new file mode 100644 index 0000000..95f4421 --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/Players.java @@ -0,0 +1,71 @@ + +package engine.jabx.schema.generated; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{}Player" maxOccurs="6" minOccurs="2"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "player" +}) +@XmlRootElement(name = "Players") +public class Players { + + @XmlElement(name = "Player", required = true) + protected List player; + + /** + * Gets the value of the player property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the player property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getPlayer().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Player } + * + * + */ + public List getPlayer() { + if (player == null) { + player = new ArrayList(); + } + return this.player; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/STGameType.java b/GameEngine/src/engine/jabx/schema/generated/STGameType.java new file mode 100644 index 0000000..b4084cb --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/STGameType.java @@ -0,0 +1,48 @@ + +package engine.jabx.schema.generated; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for ST_GameType. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="ST_GameType">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="Basic"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "ST_GameType") +@XmlEnum +public enum STGameType { + + @XmlEnumValue("Basic") + BASIC("Basic"); + private final String value; + + STGameType(String v) { + value = v; + } + + public String value() { + return value; + } + + public static STGameType fromValue(String v) { + for (STGameType c: STGameType.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/Structure.java b/GameEngine/src/engine/jabx/schema/generated/Structure.java new file mode 100644 index 0000000..0cff857 --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/Structure.java @@ -0,0 +1,157 @@ + +package engine.jabx.schema.generated; + +import engine.jabx.schema.generated.Letters; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <all>
+ *         <element ref="{}DictionaryFileName"/>
+ *         <element ref="{}Letters"/>
+ *         <element ref="{}BoardSize"/>
+ *         <element name="RetriesNumber" type="{http://www.w3.org/2001/XMLSchema}byte"/>
+ *         <element name="CubeFacets">
+ *           <simpleType>
+ *             <restriction base="{http://www.w3.org/2001/XMLSchema}byte">
+ *               <minInclusive value="6"/>
+ *               <maxInclusive value="12"/>
+ *             </restriction>
+ *           </simpleType>
+ *         </element>
+ *       </all>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + +}) +@XmlRootElement(name = "Structure") +public class Structure { + + @XmlElement(name = "DictionaryFileName", required = true) + protected String dictionaryFileName; + @XmlElement(name = "Letters", required = true) + protected Letters letters; + @XmlElement(name = "BoardSize") + protected byte boardSize; + @XmlElement(name = "RetriesNumber") + protected byte retriesNumber; + @XmlElement(name = "CubeFacets") + protected byte cubeFacets; + + /** + * Gets the value of the dictionaryFileName property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDictionaryFileName() { + return dictionaryFileName; + } + + /** + * Sets the value of the dictionaryFileName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDictionaryFileName(String value) { + this.dictionaryFileName = value; + } + + /** + * Gets the value of the letters property. + * + * @return + * possible object is + * {@link Letters } + * + */ + public Letters getLetters() { + return letters; + } + + /** + * Sets the value of the letters property. + * + * @param value + * allowed object is + * {@link Letters } + * + */ + public void setLetters(Letters value) { + this.letters = value; + } + + /** + * Gets the value of the boardSize property. + * + */ + public byte getBoardSize() { + return boardSize; + } + + /** + * Sets the value of the boardSize property. + * + */ + public void setBoardSize(byte value) { + this.boardSize = value; + } + + /** + * Gets the value of the retriesNumber property. + * + */ + public byte getRetriesNumber() { + return retriesNumber; + } + + /** + * Sets the value of the retriesNumber property. + * + */ + public void setRetriesNumber(byte value) { + this.retriesNumber = value; + } + + /** + * Gets the value of the cubeFacets property. + * + */ + public byte getCubeFacets() { + return cubeFacets; + } + + /** + * Sets the value of the cubeFacets property. + * + */ + public void setCubeFacets(byte value) { + this.cubeFacets = value; + } + +} diff --git a/GameEngine/src/engine/jabx/schema/generated/Wordiada.xsd b/GameEngine/src/engine/jabx/schema/generated/Wordiada.xsd new file mode 100644 index 0000000..79f91ef --- /dev/null +++ b/GameEngine/src/engine/jabx/schema/generated/Wordiada.xsd @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GameEngine/src/resources/Wordiada.xsd b/GameEngine/src/resources/Wordiada.xsd new file mode 100644 index 0000000..79f91ef --- /dev/null +++ b/GameEngine/src/resources/Wordiada.xsd @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ddacdb1569510a4d3beb4cd1226683f3a5b441f7 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 23 Apr 2017 18:00:48 +0300 Subject: [PATCH 06/62] Add menus --- ConsoleUI/src/{ => consoleui}/RunGame.java | 1 + 1 file changed, 1 insertion(+) rename ConsoleUI/src/{ => consoleui}/RunGame.java (85%) diff --git a/ConsoleUI/src/RunGame.java b/ConsoleUI/src/consoleui/RunGame.java similarity index 85% rename from ConsoleUI/src/RunGame.java rename to ConsoleUI/src/consoleui/RunGame.java index 1e7d9f9..b87e7a7 100644 --- a/ConsoleUI/src/RunGame.java +++ b/ConsoleUI/src/consoleui/RunGame.java @@ -1,3 +1,4 @@ +package consoleui; public class RunGame { From e20ff17d794d8765f9388798438b3b617e3b993f Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 23 Apr 2017 18:00:48 +0300 Subject: [PATCH 07/62] Add menus --- ConsoleUI/src/ConsoleUI.java | 27 ---- ConsoleUI/src/MenuHandler.java | 37 ------ ConsoleUI/src/consoleui/ConsoleHandler.java | 139 ++++++++++++++++++++ ConsoleUI/src/consoleui/ConsoleUI.java | 76 +++++++++++ ConsoleUI/src/{ => consoleui}/RunGame.java | 1 + 5 files changed, 216 insertions(+), 64 deletions(-) delete mode 100644 ConsoleUI/src/ConsoleUI.java delete mode 100644 ConsoleUI/src/MenuHandler.java create mode 100644 ConsoleUI/src/consoleui/ConsoleHandler.java create mode 100644 ConsoleUI/src/consoleui/ConsoleUI.java rename ConsoleUI/src/{ => consoleui}/RunGame.java (85%) diff --git a/ConsoleUI/src/ConsoleUI.java b/ConsoleUI/src/ConsoleUI.java deleted file mode 100644 index f1819bf..0000000 --- a/ConsoleUI/src/ConsoleUI.java +++ /dev/null @@ -1,27 +0,0 @@ -public class ConsoleUI { - public static void main(String[] args) { - GameEngine engine = new GameEngine(); - int selectedMenu; - while((selectedMenu=MenuHandler.showMainMenu()) != 6){ - switch (selectedMenu){ - case 1: - String pathToXml = MenuHandler.getXML(); - try { - engine.loadXml(pathToXml); - } - catch (Exception e) { - System.out.println("Error, " + e.getMessage()); - } - break; - case 2: - break; - case 3: - break; - case 4: - break; - case 5: - break; - } - } - } -} diff --git a/ConsoleUI/src/MenuHandler.java b/ConsoleUI/src/MenuHandler.java deleted file mode 100644 index f85f262..0000000 --- a/ConsoleUI/src/MenuHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -import java.util.Scanner; - -public class MenuHandler { - - public static int showMainMenu() { - int selectedMenuItem; - Scanner scanner = new Scanner(System.in); - - System.out.println("Please select an option:"); - System.out.println("1. Load game from xml."); - System.out.println("2. Start game."); - System.out.println("3. Show board."); - System.out.println("4. Make a move."); - System.out.println("5. Show statistics."); - System.out.println("6. Exit game."); - - selectedMenuItem = scanner.nextInt(); - if (selectedMenuItem < 1 && selectedMenuItem > 6) { - System.out.println("Wrong menu number (need to bo 1-6)."); - } - - return selectedMenuItem; - } - - public static String getXML() { - Scanner scanner = new Scanner(System.in); - String pathToXml; - - System.out.println("Please enter the path to the XML file:"); - pathToXml = scanner.nextLine(); - if (!pathToXml.toLowerCase().endsWith(".xml")) { - System.out.println("The path entered is not to a XML file!"); - } - - return pathToXml; - } -} diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java new file mode 100644 index 0000000..e1c86f8 --- /dev/null +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -0,0 +1,139 @@ +package consoleui; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class ConsoleHandler { + + public static int showMainMenu() { + int selectedMenuItem; + Scanner scanner = new Scanner(System.in); + + System.out.println("Please select an option:"); + System.out.println("1. Load game from xml."); + System.out.println("2. Start game."); + System.out.println("3. Show board."); + System.out.println("4. Make a move."); + System.out.println("5. Show statistics."); + System.out.println("6. Exit game."); + + selectedMenuItem = scanner.nextInt(); + if (selectedMenuItem < 1 && selectedMenuItem > 6) { + System.out.println("Wrong menu number (need to bo 1-6)."); + } + + return selectedMenuItem; + } + + public static String getXML() { + Scanner scanner = new Scanner(System.in); + String pathToXml; + + System.out.println("Please enter the path to the XML file:"); + pathToXml = scanner.nextLine(); + if (!pathToXml.toLowerCase().endsWith(".xml")) { + System.out.println("The path entered is not to a XML file!"); + } + + return pathToXml; + } + + public static void showGameStatus(Object o) { + // TODO: change 'Object o' to the correct type + System.out.println("Game Stats:\n"); + printBoard(5,5, null); + System.out.println("The number of cards remaining in the pot: " + 5); + System.out.println("Current player: " + "Player1"); + } + + public static void printBoard(int x, int y, Object o) { + // TODO: change the signature of the function and fill with correct data + int numOfRows = y; + int numOfCols = x; + int col, row; + String line; + String boarderLine = numOfRows > 9 ? "-----" : "---"; + for (col = 0; col < numOfCols; col++) { + boarderLine += "--"; + } + System.out.println("Current Board:\n"); + boardIndices(numOfCols, numOfRows); + System.out.println(boarderLine); + // print board + for (row = 0; row < numOfRows; row++) { + line = numOfRows > 9 && row < 9 ? " " : ""; + line += (row + 1) + "|"; + for (col = 0; col < numOfCols; col++) { + line += " |"; + } + line += row + 1; + System.out.println(line); + System.out.println(boarderLine); + } + boardIndices(numOfCols, numOfRows); + } + + private static void boardIndices(int numOfCols, int numOfRows) { + int col; + String line; + String lineStart = numOfRows > 9 ? " |" : " |"; + // Print top indices + line = lineStart; + if (numOfRows > 9) { + for (col = 1; col <= numOfCols; col++) { + line += col % 10 == 0 ? col / 10 + "|" : " |"; + } + System.out.println(line); + } + line = lineStart; + for (col = 0; col < numOfCols; col++) { + line += (col + 1) % 10 + "|"; + } + System.out.println(line); + } + + public static List getPoints(int numOfValues) { + Scanner scanner = new Scanner(System.in); + List points = new ArrayList<>(); + System.out.println("Please enter "+ numOfValues + "coordinates."); + System.out.println("The format is: row col. example: 5 5\n"); + for (int i = 0; i < numOfValues; i++) { + System.out.println(); + int point[] = {-1,-1}; + point[0] = scanner.nextInt(); + point[1] = scanner.nextInt(); + points.add(point); + } + return points; + } + + public static String getWord(int tryNum, int maxTries) { + String word; + Scanner scanner = new Scanner(System.in); + + System.out.println("Try #" + tryNum + " out of " + maxTries + ":"); + System.out.println("Please enter a word built from the letters above:"); + word = scanner.next(); + return word.toUpperCase(); + } + + public static void showStatistics(Object o) { + //TODO: fix object and data + System.out.println("Game Statistics:\n"); + System.out.println("Turns played: " + 12); + System.out.println("Time passed from game start: " + "12:40"); + System.out.println("Number of cards left: " + 30); + for (int i = 0; i < 12; i++) { + //TODO: fix for + System.out.println("\t" + ('A' + i) + " - " + 4 + "/" + 30); + } + for (int i = 0; i < 2; i++) { + System.out.println("Player " + "Ido"); + System.out.println(" Score: " + 5000); + for (int j = 0; j < 3; j++) { + System.out.println("umbrella" + ": " + 34 + "/" + 12398); + } + } + } +} diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java new file mode 100644 index 0000000..98c0edd --- /dev/null +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -0,0 +1,76 @@ +package consoleui; + +import java.util.List; + +public class ConsoleUI { + public static void main(String[] args) { + GameEngine engine = new GameEngine(); + int selectedMenu; + boolean needInput = true; + while((selectedMenu= ConsoleHandler.showMainMenu()) != 6){ + switch (selectedMenu) { + case 1: + String pathToXml = null; + while (needInput) { + pathToXml = ConsoleHandler.getXML(); + try { + engine.loadXml(pathToXml); + needInput = false; + } catch (Exception e) { + System.out.println("Error, " + e.getMessage()); + } + } + System.out.println("XML file " + pathToXml + " loaded successfully!"); + needInput = true; + break; + case 2: + if (!engine.isXmlLoaded()) { + System.out.println("No xml game file was loaded.\n" + + "Please select 1 first to load at least one xml file."); + } + else if (engine.isStarted()) { + System.out.println("The game was already started...\n" + + "Please DON'T use this option again."); + } + else { + engine.startGame(); + } + break; + case 3: + ConsoleHandler.showGameStatus(engine.getStat()); + break; + case 4: + int diceValue = engine.getDiceValue(), tries; + List points = ConsoleHandler.getPoints(diceValue); + engine.updateBoard(points); + Object o = engine.getBoard(); + ConsoleHandler.printBoard(5, 7, o); + int maxTries = engine.getRetriesAmount(); + for (tries = 0; tries < maxTries; tries++) { + String word = ConsoleHandler.getWord(tries + 1, maxTries); + if (engine.isWordValid(word, tries)) { + System.out.println("The word " + word + " is correct!\n"); + break; + } + System.out.println("Incorrect word!\n"); + } + if (tries == maxTries) { + System.out.println("\nNo more retries!"); + } + System.out.println("Changing to next player..."); + ConsoleHandler.showGameStatus(engine.getStat()); + break; + case 5: + Object ob = engine.getStatistics(); + ConsoleHandler.showStatistics(ob); + break; + } + } + + System.out.println("Game ended."); + Object o = engine.getBoard(); + ConsoleHandler.printBoard(5, 7, o); + Object ob = engine.getStatistics(); + ConsoleHandler.showStatistics(ob); + } +} diff --git a/ConsoleUI/src/RunGame.java b/ConsoleUI/src/consoleui/RunGame.java similarity index 85% rename from ConsoleUI/src/RunGame.java rename to ConsoleUI/src/consoleui/RunGame.java index 1e7d9f9..b87e7a7 100644 --- a/ConsoleUI/src/RunGame.java +++ b/ConsoleUI/src/consoleui/RunGame.java @@ -1,3 +1,4 @@ +package consoleui; public class RunGame { From a6a525d051fd3766a6c903943cbee3417d7f5e95 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Mon, 24 Apr 2017 09:47:57 +0300 Subject: [PATCH 08/62] gamefatafromxml + gameengine (validation funcs) --- GameEngine/src/engine/GameDataFromXml.java | 109 +++++++---- GameEngine/src/engine/GameEngine.java | 47 ++++- GameEngine/src/engine/Statistic.java | 2 +- GameEngine/src/engine/jabx/sdf.java | 7 + GameEngine/src/engine/xml/DynamicPlayers.java | 97 ++++++++++ GameEngine/src/engine/xml/GameDescriptor.java | 148 +++++++++++++++ GameEngine/src/engine/xml/GameType.java | 123 +++++++++++++ GameEngine/src/engine/xml/Letter.java | 111 ++++++++++++ GameEngine/src/engine/xml/Letters.java | 91 ++++++++++ GameEngine/src/engine/xml/ObjectFactory.java | 170 ++++++++++++++++++ GameEngine/src/engine/xml/Player.java | 120 +++++++++++++ GameEngine/src/engine/xml/Players.java | 71 ++++++++ GameEngine/src/engine/xml/STGameType.java | 48 +++++ GameEngine/src/engine/xml/Structure.java | 155 ++++++++++++++++ master (2).xml | 154 ++++++++++++++++ 15 files changed, 1413 insertions(+), 40 deletions(-) create mode 100644 GameEngine/src/engine/jabx/sdf.java create mode 100644 GameEngine/src/engine/xml/DynamicPlayers.java create mode 100644 GameEngine/src/engine/xml/GameDescriptor.java create mode 100644 GameEngine/src/engine/xml/GameType.java create mode 100644 GameEngine/src/engine/xml/Letter.java create mode 100644 GameEngine/src/engine/xml/Letters.java create mode 100644 GameEngine/src/engine/xml/ObjectFactory.java create mode 100644 GameEngine/src/engine/xml/Player.java create mode 100644 GameEngine/src/engine/xml/Players.java create mode 100644 GameEngine/src/engine/xml/STGameType.java create mode 100644 GameEngine/src/engine/xml/Structure.java create mode 100644 master (2).xml diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 720f605..b4e4108 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -3,11 +3,12 @@ import java.io.FileNotFoundException; import java.io.InputStream; import java.sql.Struct; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.lang.Character; import java.lang.String; +import java.math.RoundingMode; +import java.math.BigDecimal; + import engine.jabx.schema.generated.GameDescriptor; @@ -23,16 +24,65 @@ public class GameDataFromXml { Map frequencyLetter = new HashMap(); + Map ratiofrequencyLetter = new HashMap(); + Map frequencyWord = new HashMap(); - List letters; + List letters = new ArrayList(); + + private int boardSize; private int numOfCubeWigs; private int numOfTries; private int totalTiles; private int leftBoxTiles; + String dictFileName; private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jabx.schema.generated"; + // test: + + public static void main(String[] argv){ + int freqratio = 0; + GameDataFromXml g = new GameDataFromXml(); + g.initializingDataFromXml("ABC"); + System.out.println("board size: "+ g.getBoardSize()); + System.out.println("num of cubs: " + g.getNumOfCubeWigs() ); + for(int i: g.getRatiofrequencyLetter().values()) + System.out.println(i); + + for (int i=0; i getRatiofrequencyLetter() { + return ratiofrequencyLetter; + } + + public int getBoardSize() { + return boardSize; + } + + public int getNumOfCubeWigs() { + return numOfCubeWigs; + } + + public int getNumOfTries() { + return numOfTries; + } + + public List getLetters() { + return letters; + } + + public Map getFrequencyLetter() { + return frequencyLetter; + } + public void initializingDataFromXml(String pathToXml) { @@ -46,8 +96,6 @@ public void initializingDataFromXml(String pathToXml) { } catch (FileNotFoundException e) { e.printStackTrace(); }*/ - - inputStream = GameDataFromXml.class.getResourceAsStream("/resources/master.xml"); Structure struct; @@ -61,47 +109,37 @@ public void initializingDataFromXml(String pathToXml) { for (int i = 0; i < letters.getLetter().size(); i++) { this.letters.add(i, letters.getLetter().get(i)); frequencyLetter.put( this.letters.get(i).getSign().get(0), this.letters.get(i).getFrequency()); - - } - } catch (JAXBException e) { - e.printStackTrace(); - } - - //init board size - - try { - gd = deserializeFrom(inputStream); - struct = gd.getStructure(); + //init board size boardSize = struct.getBoardSize(); - - } catch (JAXBException e) { - e.printStackTrace(); - } - - // init num of cube wigs - try { - gd = deserializeFrom(inputStream); - struct = gd.getStructure(); + //init num of wings this.numOfCubeWigs = struct.getCubeFacets(); + //init num of tries + this.numOfTries = struct.getRetriesNumber(); + dictFileName = struct.getDictionaryFileName(); + calcRatiofrequencyLetter(frequencyLetter); } catch (JAXBException e) { e.printStackTrace(); } + } + public String getDictFileName() { + return dictFileName; + } + public void calcRatiofrequencyLetter(Map frequencyletter){ - - // init num of tries - try { - gd = deserializeFrom(inputStream); - struct = gd.getStructure(); - this.numOfTries = struct.getRetriesNumber(); - - } catch (JAXBException e) { - e.printStackTrace(); + double totalfreq = 0; + int ratiofreq; + for(Double freq : frequencyletter.values()){ + totalfreq += freq; } + for(Map.Entry item : frequencyletter.entrySet()){ + ratiofreq = (int)Math.ceil((item.getValue()/totalfreq)*100); + this.ratiofrequencyLetter.put(item.getKey(), ratiofreq); + } } private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); @@ -198,4 +236,3 @@ public boolean isValid() : all illiegele issues + xml loading + txt file in dictionary library */ -} \ No newline at end of file diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 086e13f..6cbf343 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -1,18 +1,27 @@ package engine; + +import engine.jabx.schema.generated.Letter; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import java.lang.Character; +import java.lang.String; + + public class GameEngine { - private GameDataFromXml data; // private GameInformation info; private Player player; + private GameDataFromXml gdfx; - + GameEngine(String pathToXml){ + gdfx.initializingDataFromXml(pathToXml); + } public void loadXml(String pathToXml) { // TODO @@ -25,9 +34,41 @@ public boolean isValidXml(String pathToXml) { return false; return true; } - public boolean isDictionaryInRightPos(){ + + // call this func after calling the one above + public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml){ + pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" + while(!pathToXml.endsWith("\\")){ + pathToXml = pathToXml.substring(0,pathToXml.length() - 1); + } + if(pathToDictFile == pathToXml + gdfx.getDictFileName() + ".txt" ) + return true; + return false; + } + + public boolean isValidBoardSize(byte size){ + if((size >= 5) && (size <= 50)) + return true; + return false; + } + + public boolean isAllLettersApperOne(){ + boolean isMoreThanOnce = false; + for(int i = 0; i < gdfx.getLetters().size(); i++){ + Letter l = gdfx.getLetters().get(i); + String c = gdfx.getLetters().get(i).getSign().get(0); + gdfx.getLetters().remove(i); + isMoreThanOnce = gdfx.getLetters().contains(c); + gdfx.getLetters().add(i,l); + //appears more than once + if(isMoreThanOnce) + return false; + } return true; } + + + } diff --git a/GameEngine/src/engine/Statistic.java b/GameEngine/src/engine/Statistic.java index a64990c..933c05d 100644 --- a/GameEngine/src/engine/Statistic.java +++ b/GameEngine/src/engine/Statistic.java @@ -15,7 +15,7 @@ public class Statistic { Statistic(List input_Player){ players.addAll(input_Player) ; numOfTurns = 0; - leftBoxTiles = gameData.getLeftBoxTiles(); + //leftBoxTiles = gameData.getLeftBoxTiles(); } } \ No newline at end of file diff --git a/GameEngine/src/engine/jabx/sdf.java b/GameEngine/src/engine/jabx/sdf.java new file mode 100644 index 0000000..013deb3 --- /dev/null +++ b/GameEngine/src/engine/jabx/sdf.java @@ -0,0 +1,7 @@ +package engine.jabx; + +/** + * Created by נוי on 23/04/2017. + */ +public class sdf { +} diff --git a/GameEngine/src/engine/xml/DynamicPlayers.java b/GameEngine/src/engine/xml/DynamicPlayers.java new file mode 100644 index 0000000..96951c8 --- /dev/null +++ b/GameEngine/src/engine/xml/DynamicPlayers.java @@ -0,0 +1,97 @@ + +package engine.xml; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <attribute name="total-players" use="required">
+ *         <simpleType>
+ *           <restriction base="{http://www.w3.org/2001/XMLSchema}byte">
+ *             <minInclusive value="2"/>
+ *             <maxInclusive value="6"/>
+ *           </restriction>
+ *         </simpleType>
+ *       </attribute>
+ *       <attribute name="game-title" use="required">
+ *         <simpleType>
+ *           <list itemType="{http://www.w3.org/2001/XMLSchema}string" />
+ *         </simpleType>
+ *       </attribute>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "") +@XmlRootElement(name = "DynamicPlayers") +public class DynamicPlayers { + + @XmlAttribute(name = "total-players", required = true) + protected byte totalPlayers; + @XmlAttribute(name = "game-title", required = true) + protected List gameTitle; + + /** + * Gets the value of the totalPlayers property. + * + */ + public byte getTotalPlayers() { + return totalPlayers; + } + + /** + * Sets the value of the totalPlayers property. + * + */ + public void setTotalPlayers(byte value) { + this.totalPlayers = value; + } + + /** + * Gets the value of the gameTitle property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the gameTitle property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getGameTitle().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getGameTitle() { + if (gameTitle == null) { + gameTitle = new ArrayList(); + } + return this.gameTitle; + } + +} diff --git a/GameEngine/src/engine/xml/GameDescriptor.java b/GameEngine/src/engine/xml/GameDescriptor.java new file mode 100644 index 0000000..11dc953 --- /dev/null +++ b/GameEngine/src/engine/xml/GameDescriptor.java @@ -0,0 +1,148 @@ + +package engine.xml; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{}GameType"/>
+ *         <element ref="{}Structure"/>
+ *         <element ref="{}Players" minOccurs="0"/>
+ *         <element ref="{}DynamicPlayers" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "gameType", + "structure", + "players", + "dynamicPlayers" +}) +@XmlRootElement(name = "GameDescriptor") +public class GameDescriptor { + + @XmlElement(name = "GameType", required = true) + protected GameType gameType; + @XmlElement(name = "Structure", required = true) + protected Structure structure; + @XmlElement(name = "Players") + protected Players players; + @XmlElement(name = "DynamicPlayers") + protected DynamicPlayers dynamicPlayers; + + /** + * Gets the value of the gameType property. + * + * @return + * possible object is + * {@link GameType } + * + */ + public GameType getGameType() { + return gameType; + } + + /** + * Sets the value of the gameType property. + * + * @param value + * allowed object is + * {@link GameType } + * + */ + public void setGameType(GameType value) { + this.gameType = value; + } + + /** + * Gets the value of the structure property. + * + * @return + * possible object is + * {@link Structure } + * + */ + public Structure getStructure() { + return structure; + } + + /** + * Sets the value of the structure property. + * + * @param value + * allowed object is + * {@link Structure } + * + */ + public void setStructure(Structure value) { + this.structure = value; + } + + /** + * Gets the value of the players property. + * + * @return + * possible object is + * {@link Players } + * + */ + public Players getPlayers() { + return players; + } + + /** + * Sets the value of the players property. + * + * @param value + * allowed object is + * {@link Players } + * + */ + public void setPlayers(Players value) { + this.players = value; + } + + /** + * Gets the value of the dynamicPlayers property. + * + * @return + * possible object is + * {@link DynamicPlayers } + * + */ + public DynamicPlayers getDynamicPlayers() { + return dynamicPlayers; + } + + /** + * Sets the value of the dynamicPlayers property. + * + * @param value + * allowed object is + * {@link DynamicPlayers } + * + */ + public void setDynamicPlayers(DynamicPlayers value) { + this.dynamicPlayers = value; + } + +} diff --git a/GameEngine/src/engine/xml/GameType.java b/GameEngine/src/engine/xml/GameType.java new file mode 100644 index 0000000..0599799 --- /dev/null +++ b/GameEngine/src/engine/xml/GameType.java @@ -0,0 +1,123 @@ + +package engine.xml; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlValue; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <simpleContent>
+ *     <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ *       <attribute name="winner-according-to" use="required">
+ *         <simpleType>
+ *           <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *             <enumeration value="WordCount"/>
+ *             <enumeration value="WordScore"/>
+ *           </restriction>
+ *         </simpleType>
+ *       </attribute>
+ *       <attribute name="gold-fish-mode" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *     </extension>
+ *   </simpleContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "value" +}) +@XmlRootElement(name = "GameType") +public class GameType { + + @XmlValue + protected String value; + @XmlAttribute(name = "winner-according-to", required = true) + protected String winnerAccordingTo; + @XmlAttribute(name = "gold-fish-mode") + protected Boolean goldFishMode; + + /** + * Gets the value of the value property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getValue() { + return value; + } + + /** + * Sets the value of the value property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setValue(String value) { + this.value = value; + } + + /** + * Gets the value of the winnerAccordingTo property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getWinnerAccordingTo() { + return winnerAccordingTo; + } + + /** + * Sets the value of the winnerAccordingTo property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setWinnerAccordingTo(String value) { + this.winnerAccordingTo = value; + } + + /** + * Gets the value of the goldFishMode property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isGoldFishMode() { + return goldFishMode; + } + + /** + * Sets the value of the goldFishMode property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setGoldFishMode(Boolean value) { + this.goldFishMode = value; + } + +} diff --git a/GameEngine/src/engine/xml/Letter.java b/GameEngine/src/engine/xml/Letter.java new file mode 100644 index 0000000..e655be1 --- /dev/null +++ b/GameEngine/src/engine/xml/Letter.java @@ -0,0 +1,111 @@ + +package engine.xml; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlList; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <all>
+ *         <element ref="{}Sign"/>
+ *         <element ref="{}Score"/>
+ *         <element ref="{}Frequency"/>
+ *       </all>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + +}) +@XmlRootElement(name = "Letter") +public class Letter { + + @XmlList + @XmlElement(name = "Sign", required = true) + protected List sign; + @XmlElement(name = "Score") + protected byte score; + @XmlElement(name = "Frequency") + protected double frequency; + + /** + * Gets the value of the sign property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the sign property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getSign().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getSign() { + if (sign == null) { + sign = new ArrayList(); + } + return this.sign; + } + + /** + * Gets the value of the score property. + * + */ + public byte getScore() { + return score; + } + + /** + * Sets the value of the score property. + * + */ + public void setScore(byte value) { + this.score = value; + } + + /** + * Gets the value of the frequency property. + * + */ + public double getFrequency() { + return frequency; + } + + /** + * Sets the value of the frequency property. + * + */ + public void setFrequency(double value) { + this.frequency = value; + } + +} diff --git a/GameEngine/src/engine/xml/Letters.java b/GameEngine/src/engine/xml/Letters.java new file mode 100644 index 0000000..a672146 --- /dev/null +++ b/GameEngine/src/engine/xml/Letters.java @@ -0,0 +1,91 @@ + +package engine.xml; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{}Letter" maxOccurs="unbounded"/>
+ *       </sequence>
+ *       <attribute name="target-deck-size" use="required" type="{http://www.w3.org/2001/XMLSchema}short" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "letter" +}) +@XmlRootElement(name = "Letters") +public class Letters { + + @XmlElement(name = "Letter", required = true) + protected List letter; + @XmlAttribute(name = "target-deck-size", required = true) + protected short targetDeckSize; + + /** + * Gets the value of the letter property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the letter property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getLetter().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Letter } + * + * + */ + public List getLetter() { + if (letter == null) { + letter = new ArrayList(); + } + return this.letter; + } + + /** + * Gets the value of the targetDeckSize property. + * + */ + public short getTargetDeckSize() { + return targetDeckSize; + } + + /** + * Sets the value of the targetDeckSize property. + * + */ + public void setTargetDeckSize(short value) { + this.targetDeckSize = value; + } + +} diff --git a/GameEngine/src/engine/xml/ObjectFactory.java b/GameEngine/src/engine/xml/ObjectFactory.java new file mode 100644 index 0000000..742a488 --- /dev/null +++ b/GameEngine/src/engine/xml/ObjectFactory.java @@ -0,0 +1,170 @@ + +package engine.xml; + +import java.util.List; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the engine.xml package. + *

An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _Type_QNAME = new QName("", "Type"); + private final static QName _Score_QNAME = new QName("", "Score"); + private final static QName _BoardSize_QNAME = new QName("", "BoardSize"); + private final static QName _Frequency_QNAME = new QName("", "Frequency"); + private final static QName _Sign_QNAME = new QName("", "Sign"); + private final static QName _Name_QNAME = new QName("", "Name"); + private final static QName _DictionaryFileName_QNAME = new QName("", "DictionaryFileName"); + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: engine.xml + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Player } + * + */ + public Player createPlayer() { + return new Player(); + } + + /** + * Create an instance of {@link Letters } + * + */ + public Letters createLetters() { + return new Letters(); + } + + /** + * Create an instance of {@link Letter } + * + */ + public Letter createLetter() { + return new Letter(); + } + + /** + * Create an instance of {@link GameType } + * + */ + public GameType createGameType() { + return new GameType(); + } + + /** + * Create an instance of {@link Structure } + * + */ + public Structure createStructure() { + return new Structure(); + } + + /** + * Create an instance of {@link GameDescriptor } + * + */ + public GameDescriptor createGameDescriptor() { + return new GameDescriptor(); + } + + /** + * Create an instance of {@link Players } + * + */ + public Players createPlayers() { + return new Players(); + } + + /** + * Create an instance of {@link DynamicPlayers } + * + */ + public DynamicPlayers createDynamicPlayers() { + return new DynamicPlayers(); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Type") + public JAXBElement createType(String value) { + return new JAXBElement(_Type_QNAME, String.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Byte }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Score") + public JAXBElement createScore(Byte value) { + return new JAXBElement(_Score_QNAME, Byte.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Byte }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "BoardSize") + public JAXBElement createBoardSize(Byte value) { + return new JAXBElement(_BoardSize_QNAME, Byte.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link Double }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Frequency") + public JAXBElement createFrequency(Double value) { + return new JAXBElement(_Frequency_QNAME, Double.class, null, value); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link List }{@code <}{@link String }{@code >}{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Sign") + public JAXBElement> createSign(List value) { + return new JAXBElement>(_Sign_QNAME, ((Class) List.class), null, ((List ) value)); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link List }{@code <}{@link String }{@code >}{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "Name") + public JAXBElement> createName(List value) { + return new JAXBElement>(_Name_QNAME, ((Class) List.class), null, ((List ) value)); + } + + /** + * Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}} + * + */ + @XmlElementDecl(namespace = "", name = "DictionaryFileName") + public JAXBElement createDictionaryFileName(String value) { + return new JAXBElement(_DictionaryFileName_QNAME, String.class, null, value); + } + +} diff --git a/GameEngine/src/engine/xml/Player.java b/GameEngine/src/engine/xml/Player.java new file mode 100644 index 0000000..f0853f0 --- /dev/null +++ b/GameEngine/src/engine/xml/Player.java @@ -0,0 +1,120 @@ + +package engine.xml; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlList; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <all>
+ *         <element ref="{}Name"/>
+ *         <element ref="{}Type"/>
+ *       </all>
+ *       <attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}short" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + +}) +@XmlRootElement(name = "Player") +public class Player { + + @XmlList + @XmlElement(name = "Name", required = true) + protected List name; + @XmlElement(name = "Type", required = true) + protected String type; + @XmlAttribute(name = "id", required = true) + protected short id; + + /** + * Gets the value of the name property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the name property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getName().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List getName() { + if (name == null) { + name = new ArrayList(); + } + return this.name; + } + + /** + * Gets the value of the type property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getType() { + return type; + } + + /** + * Sets the value of the type property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setType(String value) { + this.type = value; + } + + /** + * Gets the value of the id property. + * + */ + public short getId() { + return id; + } + + /** + * Sets the value of the id property. + * + */ + public void setId(short value) { + this.id = value; + } + +} diff --git a/GameEngine/src/engine/xml/Players.java b/GameEngine/src/engine/xml/Players.java new file mode 100644 index 0000000..8e5b1e8 --- /dev/null +++ b/GameEngine/src/engine/xml/Players.java @@ -0,0 +1,71 @@ + +package engine.xml; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element ref="{}Player" maxOccurs="6" minOccurs="2"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "player" +}) +@XmlRootElement(name = "Players") +public class Players { + + @XmlElement(name = "Player", required = true) + protected List player; + + /** + * Gets the value of the player property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the player property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getPlayer().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link Player } + * + * + */ + public List getPlayer() { + if (player == null) { + player = new ArrayList(); + } + return this.player; + } + +} diff --git a/GameEngine/src/engine/xml/STGameType.java b/GameEngine/src/engine/xml/STGameType.java new file mode 100644 index 0000000..82774aa --- /dev/null +++ b/GameEngine/src/engine/xml/STGameType.java @@ -0,0 +1,48 @@ + +package engine.xml; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for ST_GameType. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="ST_GameType">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="Basic"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "ST_GameType") +@XmlEnum +public enum STGameType { + + @XmlEnumValue("Basic") + BASIC("Basic"); + private final String value; + + STGameType(String v) { + value = v; + } + + public String value() { + return value; + } + + public static STGameType fromValue(String v) { + for (STGameType c: STGameType.values()) { + if (c.value.equals(v)) { + return c; + } + } + throw new IllegalArgumentException(v); + } + +} diff --git a/GameEngine/src/engine/xml/Structure.java b/GameEngine/src/engine/xml/Structure.java new file mode 100644 index 0000000..a40950b --- /dev/null +++ b/GameEngine/src/engine/xml/Structure.java @@ -0,0 +1,155 @@ + +package engine.xml; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for anonymous complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType>
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <all>
+ *         <element ref="{}DictionaryFileName"/>
+ *         <element ref="{}Letters"/>
+ *         <element ref="{}BoardSize"/>
+ *         <element name="RetriesNumber" type="{http://www.w3.org/2001/XMLSchema}byte"/>
+ *         <element name="CubeFacets">
+ *           <simpleType>
+ *             <restriction base="{http://www.w3.org/2001/XMLSchema}byte">
+ *               <minInclusive value="6"/>
+ *               <maxInclusive value="12"/>
+ *             </restriction>
+ *           </simpleType>
+ *         </element>
+ *       </all>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + +}) +@XmlRootElement(name = "Structure") +public class Structure { + + @XmlElement(name = "DictionaryFileName", required = true) + protected String dictionaryFileName; + @XmlElement(name = "Letters", required = true) + protected Letters letters; + @XmlElement(name = "BoardSize") + protected byte boardSize; + @XmlElement(name = "RetriesNumber") + protected byte retriesNumber; + @XmlElement(name = "CubeFacets") + protected byte cubeFacets; + + /** + * Gets the value of the dictionaryFileName property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDictionaryFileName() { + return dictionaryFileName; + } + + /** + * Sets the value of the dictionaryFileName property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDictionaryFileName(String value) { + this.dictionaryFileName = value; + } + + /** + * Gets the value of the letters property. + * + * @return + * possible object is + * {@link Letters } + * + */ + public Letters getLetters() { + return letters; + } + + /** + * Sets the value of the letters property. + * + * @param value + * allowed object is + * {@link Letters } + * + */ + public void setLetters(Letters value) { + this.letters = value; + } + + /** + * Gets the value of the boardSize property. + * + */ + public byte getBoardSize() { + return boardSize; + } + + /** + * Sets the value of the boardSize property. + * + */ + public void setBoardSize(byte value) { + this.boardSize = value; + } + + /** + * Gets the value of the retriesNumber property. + * + */ + public byte getRetriesNumber() { + return retriesNumber; + } + + /** + * Sets the value of the retriesNumber property. + * + */ + public void setRetriesNumber(byte value) { + this.retriesNumber = value; + } + + /** + * Gets the value of the cubeFacets property. + * + */ + public byte getCubeFacets() { + return cubeFacets; + } + + /** + * Sets the value of the cubeFacets property. + * + */ + public void setCubeFacets(byte value) { + this.cubeFacets = value; + } + +} diff --git a/master (2).xml b/master (2).xml new file mode 100644 index 0000000..d599823 --- /dev/null +++ b/master (2).xml @@ -0,0 +1,154 @@ + + + + Basic + + war-and-piece.txt + + + E + 1 + 12.7 + + + T + 2 + 9.05 + + + A + 3 + 8.16 + + + O + 4 + 7.5 + + + I + 5 + 6.9 + + + N + 6 + 6.7 + + + S + 7 + 6.3 + + + H + 8 + 6 + + + R + 9 + 5.9 + + + D + 10 + 4.25 + + + L + 11 + 4 + + + C + 12 + 2.8 + + + U + 13 + 2.75 + + + M + 14 + 2.4 + + + W + 15 + 2.3 + + + F + 16 + 2.2 + + + G + 17 + 2 + + + Y + 18 + 1.9 + + + P + 19 + 1.9 + + + B + 20 + 1.5 + + + V + 21 + 0.9 + + + K + 22 + 0.7 + + + J + 23 + 0.15 + + + X + 24 + 0.15 + + + Q + 25 + 0.09 + + + Z + 26 + 0.07 + + + 7 + 2 + 6 + + + + Mushon + Human + + + Nachtze + Computer + + + + From 3472b5a70eade7450e4aa724edc3a3cfa083a4b9 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Mon, 24 Apr 2017 20:26:13 +0300 Subject: [PATCH 09/62] package exceptions + all validations ---> check in game engine --- GameEngine/src/engine/GameDataFromXml.java | 82 +++++++++++++++---- GameEngine/src/engine/GameEngine.java | 66 +++++---------- .../exceptions/InvalidInputException.java | 19 +++++ .../exceptions/NotXmlFileException.java | 21 +++++ .../engine/exceptions/WrongPathException.java | 18 ++++ 5 files changed, 148 insertions(+), 58 deletions(-) create mode 100644 GameEngine/src/engine/exceptions/InvalidInputException.java create mode 100644 GameEngine/src/engine/exceptions/NotXmlFileException.java create mode 100644 GameEngine/src/engine/exceptions/WrongPathException.java diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index b4e4108..b96feba 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -1,16 +1,23 @@ package engine; + import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; + +import java.io.*; +//import java.io.FileNotFoundException; +import java.lang.*; +//import java.io.InputStream; import java.sql.Struct; import java.util.*; import java.lang.Character; import java.lang.String; import java.math.RoundingMode; import java.math.BigDecimal; +import java.lang.Exception; +import engine.exceptions.*; - +import com.sun.org.apache.xpath.internal.SourceTree; +import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; import engine.jabx.schema.generated.GameDescriptor; import engine.jabx.schema.generated.Letter; import engine.jabx.schema.generated.Letters; @@ -35,7 +42,8 @@ public class GameDataFromXml { private int numOfTries; private int totalTiles; private int leftBoxTiles; - String dictFileName; + private String dictFileName; + private short targerDeckSize; //כמות אריחים private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jabx.schema.generated"; @@ -58,37 +66,33 @@ public static void main(String[] argv){ } + // get and set funcs: + public short getTargerDeckSize() { return targerDeckSize; } public Map getRatiofrequencyLetter() { return ratiofrequencyLetter; } - public int getBoardSize() { return boardSize; } - public int getNumOfCubeWigs() { return numOfCubeWigs; } - public int getNumOfTries() { return numOfTries; } - public List getLetters() { return letters; } - public Map getFrequencyLetter() { return frequencyLetter; } + public String getDictFileName() { return dictFileName; } public void initializingDataFromXml(String pathToXml) { - GameDescriptor gd; InputStream inputStream = null; - // TODO: delete note after tests /* try { @@ -116,17 +120,17 @@ public void initializingDataFromXml(String pathToXml) { this.numOfCubeWigs = struct.getCubeFacets(); //init num of tries this.numOfTries = struct.getRetriesNumber(); + //init dictionart file name dictFileName = struct.getDictionaryFileName(); calcRatiofrequencyLetter(frequencyLetter); + //init targer deck size + this.targerDeckSize = struct.getLetters().getTargetDeckSize(); } catch (JAXBException e) { e.printStackTrace(); } } - public String getDictFileName() { - return dictFileName; - } public void calcRatiofrequencyLetter(Map frequencyletter){ @@ -145,8 +149,58 @@ private static GameDescriptor deserializeFrom(InputStream in) throws JAXBExcepti JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); Unmarshaller u = jc.createUnmarshaller(); return (GameDescriptor) u.unmarshal(in); + } + + // check Validation functions: + + public boolean isValidXml(String pathToXml) throws NotXmlFileException { + String extension = pathToXml.substring(pathToXml.lastIndexOf(".") + 1, pathToXml.length()); + if ((extension != "xml") || (extension != ".xml")){ + throw new NotXmlFileException("ITS NOT XML FILE!"); + } + else + return true; + } + + + // call this func after calling the one above + + public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) throws WrongPathException{ + + pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" + while (!pathToXml.endsWith("\\")) { + pathToXml = pathToXml.substring(0, pathToXml.length() - 1); + } + if (pathToDictFile == pathToXml + "dictionary\\" + this.getDictFileName() + ".txt") + return true; + else { + throw new WrongPathException("THE PATH: " + pathToDictFile + " IS NOT THE VALID PATH TO DICTIONARY FILE!"); + } } + + public boolean isValidBoardSize(int size) throws InvalidInputException{ + if((size >= 5) && (size <= 50)) + return true; + else + throw new InvalidInputException("BOARD SIZE" + size + " IS OUT OF RANGE!"); + } + + public boolean isAllLettersApperOne() throws InvalidInputException{ + boolean isMoreThanOnce = false; + for(int i = 0; i < this.getLetters().size(); i++){ + Letter l = this.getLetters().get(i); + String c = this.getLetters().get(i).getSign().get(0); + this.getLetters().remove(i); + isMoreThanOnce = this.getLetters().contains(c); + this.getLetters().add(i,l); + //appears more than once + if(isMoreThanOnce) + throw new InvalidInputException("THE SIGN: " + c + "APPEARS MORE THAN ONCE!"); + } + return true; + } + } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 6cbf343..a016339 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -1,15 +1,13 @@ package engine; - -import engine.jabx.schema.generated.Letter; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - import java.lang.Character; + import java.lang.String; +import engine.exceptions.*; public class GameEngine { @@ -18,57 +16,37 @@ public class GameEngine { private Player player; private GameDataFromXml gdfx; - + //Cto'r GameEngine(String pathToXml){ - gdfx.initializingDataFromXml(pathToXml); - } - - public void loadXml(String pathToXml) { - // TODO - } + gdfx.initializingDataFromXml(pathToXml); - public boolean isValidXml(String pathToXml) { - String extension = pathToXml.substring(pathToXml.lastIndexOf(".") + 1, pathToXml.length()); - if ((extension != "xml") || (extension != ".xml")) - return false; - return true; - } - - // call this func after calling the one above - public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml){ - pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" - while(!pathToXml.endsWith("\\")){ - pathToXml = pathToXml.substring(0,pathToXml.length() - 1); + //check validation: + try{ + gdfx.isAllLettersApperOne(); + gdfx.isDictionaryInRightPos(gdfx.getDictFileName(), pathToXml); + gdfx.isValidBoardSize(gdfx.getBoardSize()); + gdfx.isValidXml(pathToXml); + } + catch(InvalidInputException e){ + //TODO: ask ido + } + catch(WrongPathException e){ + //TODO: ask ido + } + catch(NotXmlFileException e){ + //TODO: ask ido } - if(pathToDictFile == pathToXml + gdfx.getDictFileName() + ".txt" ) - return true; - return false; - } - public boolean isValidBoardSize(byte size){ - if((size >= 5) && (size <= 50)) - return true; - return false; } - public boolean isAllLettersApperOne(){ - boolean isMoreThanOnce = false; - for(int i = 0; i < gdfx.getLetters().size(); i++){ - Letter l = gdfx.getLetters().get(i); - String c = gdfx.getLetters().get(i).getSign().get(0); - gdfx.getLetters().remove(i); - isMoreThanOnce = gdfx.getLetters().contains(c); - gdfx.getLetters().add(i,l); - //appears more than once - if(isMoreThanOnce) - return false; - } - return true; + public void loadXml(String pathToXml) { + // TODO } + } diff --git a/GameEngine/src/engine/exceptions/InvalidInputException.java b/GameEngine/src/engine/exceptions/InvalidInputException.java new file mode 100644 index 0000000..b9e55a0 --- /dev/null +++ b/GameEngine/src/engine/exceptions/InvalidInputException.java @@ -0,0 +1,19 @@ +package engine.exceptions; + +/** + * Created by נוי on 24/04/2017. + */ +public class InvalidInputException extends Exception { + + public InvalidInputException () {} + public InvalidInputException (String message) { + super (message); + } + public InvalidInputException (Throwable cause) { + super (cause); + } + public InvalidInputException (String message, Throwable cause) { + super (message, cause); + } + +} diff --git a/GameEngine/src/engine/exceptions/NotXmlFileException.java b/GameEngine/src/engine/exceptions/NotXmlFileException.java new file mode 100644 index 0000000..7afff62 --- /dev/null +++ b/GameEngine/src/engine/exceptions/NotXmlFileException.java @@ -0,0 +1,21 @@ +package engine.exceptions; +import java.lang.String; +import java.lang.Throwable; + +/** + * Created by נוי on 24/04/2017. + */ +public class NotXmlFileException extends Exception { + + public NotXmlFileException () {} + public NotXmlFileException (String message) { + super (message); + } + public NotXmlFileException (Throwable cause) { + super (cause); + } + public NotXmlFileException (String message, Throwable cause) { + super (message, cause); + } +} + diff --git a/GameEngine/src/engine/exceptions/WrongPathException.java b/GameEngine/src/engine/exceptions/WrongPathException.java new file mode 100644 index 0000000..9d5227d --- /dev/null +++ b/GameEngine/src/engine/exceptions/WrongPathException.java @@ -0,0 +1,18 @@ +package engine.exceptions; + +/** + * Created by נוי on 24/04/2017. + */ +public class WrongPathException extends Exception { + + public WrongPathException () {} + public WrongPathException (String message) { + super (message); + } + public WrongPathException (Throwable cause) { + super (cause); + } + public WrongPathException (String message, Throwable cause) { + super (message, cause); + } +} From fbf7497fcf2eb5b17d5cc12d5592342256ba2f19 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 26 Apr 2017 11:36:43 +0300 Subject: [PATCH 10/62] Start add to statistics and update ui functions --- ConsoleUI/src/consoleui/ConsoleHandler.java | 12 +- ConsoleUI/src/consoleui/ConsoleUI.java | 109 ++++++++++-------- ConsoleUI/src/consoleui/RunGame.java | 6 +- GameEngine/src/engine/Dictionary.java | 61 ++++++++++ GameEngine/src/engine/GameEngine.java | 43 ++++++- GameEngine/src/engine/Statistic.java | 21 ---- GameEngine/src/engine/Statistics.java | 33 ++++++ .../DictionaryNotFoundException.java | 14 +++ 8 files changed, 220 insertions(+), 79 deletions(-) create mode 100644 GameEngine/src/engine/Dictionary.java delete mode 100644 GameEngine/src/engine/Statistic.java create mode 100644 GameEngine/src/engine/Statistics.java create mode 100644 GameEngine/src/engine/exceptions/DictionaryNotFoundException.java diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index e1c86f8..6acd3b7 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -3,7 +3,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Scanner; +import engine.Statistics; +//TODO: fix access permissions public class ConsoleHandler { public static int showMainMenu() { @@ -118,12 +120,12 @@ public static String getWord(int tryNum, int maxTries) { return word.toUpperCase(); } - public static void showStatistics(Object o) { - //TODO: fix object and data + public static void showStatistics(Statistics stat) { System.out.println("Game Statistics:\n"); - System.out.println("Turns played: " + 12); - System.out.println("Time passed from game start: " + "12:40"); - System.out.println("Number of cards left: " + 30); + System.out.println("Turns played: " + stat.getNumOfTurns()); + long time = stat.getTime(); + System.out.println("Time passed from game start: " + time / 60 + ":" + time % 60); + System.out.println("Number of cards left: " + stat.getLeftBoxTiles()); for (int i = 0; i < 12; i++) { //TODO: fix for System.out.println("\t" + ('A' + i) + " - " + 4 + "/" + 30); diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 98c0edd..ff69fdc 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -1,68 +1,30 @@ package consoleui; import java.util.List; +import engine.GameEngine; +import engine.Statistics; public class ConsoleUI { + private static GameEngine engine = new GameEngine(); public static void main(String[] args) { - GameEngine engine = new GameEngine(); int selectedMenu; - boolean needInput = true; while((selectedMenu= ConsoleHandler.showMainMenu()) != 6){ switch (selectedMenu) { case 1: - String pathToXml = null; - while (needInput) { - pathToXml = ConsoleHandler.getXML(); - try { - engine.loadXml(pathToXml); - needInput = false; - } catch (Exception e) { - System.out.println("Error, " + e.getMessage()); - } - } - System.out.println("XML file " + pathToXml + " loaded successfully!"); - needInput = true; + getXml(); break; case 2: - if (!engine.isXmlLoaded()) { - System.out.println("No xml game file was loaded.\n" + - "Please select 1 first to load at least one xml file."); - } - else if (engine.isStarted()) { - System.out.println("The game was already started...\n" + - "Please DON'T use this option again."); - } - else { - engine.startGame(); - } + startGame(); break; case 3: ConsoleHandler.showGameStatus(engine.getStat()); break; case 4: - int diceValue = engine.getDiceValue(), tries; - List points = ConsoleHandler.getPoints(diceValue); - engine.updateBoard(points); - Object o = engine.getBoard(); - ConsoleHandler.printBoard(5, 7, o); - int maxTries = engine.getRetriesAmount(); - for (tries = 0; tries < maxTries; tries++) { - String word = ConsoleHandler.getWord(tries + 1, maxTries); - if (engine.isWordValid(word, tries)) { - System.out.println("The word " + word + " is correct!\n"); - break; - } - System.out.println("Incorrect word!\n"); - } - if (tries == maxTries) { - System.out.println("\nNo more retries!"); - } - System.out.println("Changing to next player..."); - ConsoleHandler.showGameStatus(engine.getStat()); + playTurn(); break; case 5: - Object ob = engine.getStatistics(); - ConsoleHandler.showStatistics(ob); + Statistics stat = engine.getStatistics(); + ConsoleHandler.showStatistics(stat); break; } } @@ -70,7 +32,58 @@ else if (engine.isStarted()) { System.out.println("Game ended."); Object o = engine.getBoard(); ConsoleHandler.printBoard(5, 7, o); - Object ob = engine.getStatistics(); - ConsoleHandler.showStatistics(ob); + Statistics stat = engine.getStatistics(); + ConsoleHandler.showStatistics(stat); + } + + private static void getXml() { + boolean needInput = true; + String pathToXml = null; + while (needInput) { + pathToXml = ConsoleHandler.getXML(); + try { + engine.loadXml(pathToXml); + needInput = false; + } catch (Exception e) { + System.out.println("Error, " + e.getMessage()); + } + } + System.out.println("XML file " + pathToXml + " loaded successfully!"); + } + + private static void startGame(){ + if (!engine.isXmlLoaded()) { + System.out.println("No xml game file was loaded.\n" + + "Please select 1 first to load at least one xml file."); + } + else if (engine.isStarted()) { + System.out.println("The game was already started...\n" + + "Please DON'T use this option again."); + } + else { + engine.startGame(); + } + } + + private static void playTurn() { + int diceValue = engine.getDiceValue(), tries; + List points = ConsoleHandler.getPoints(diceValue); + engine.updateBoard(points); + Object o = engine.getBoard(); + ConsoleHandler.printBoard(5, 7, o); + int maxTries = engine.getMaxRetries(); + for (tries = 0; tries < maxTries; tries++) { + String word = ConsoleHandler.getWord(tries + 1, maxTries); + if (engine.isWordValid(word, tries)) { + System.out.println("The word " + word + " is correct!\n"); + break; + } + System.out.println("Incorrect word!\n"); + } + if (tries == maxTries) { + System.out.println("\nNo more retries!"); + } + System.out.println("Changing to next player..."); + ConsoleHandler.showGameStatus(engine.getStat()); } } diff --git a/ConsoleUI/src/consoleui/RunGame.java b/ConsoleUI/src/consoleui/RunGame.java index b87e7a7..454bdc7 100644 --- a/ConsoleUI/src/consoleui/RunGame.java +++ b/ConsoleUI/src/consoleui/RunGame.java @@ -2,10 +2,10 @@ public class RunGame { - private GameEngine ge; + //private GameEngine ge; - public void run(){ + /*public void run(){ ge.startGame(); - } + }*/ } diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java new file mode 100644 index 0000000..5a54e24 --- /dev/null +++ b/GameEngine/src/engine/Dictionary.java @@ -0,0 +1,61 @@ +package engine; + +import engine.exceptions.DictionaryNotFoundException; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class Dictionary { + public static void main(String[] args) { + Dictionary dic; + try { + dic = new Dictionary("C:\\Users\\Ido\\Downloads\\war and piece.txt"); + } catch (DictionaryNotFoundException e) { + System.out.println("Dictionary not found..."); + return; + } + + dic.getNumberOfWords(); + } + + private long numberOfWords = 0; + private Map words = new HashMap<>(); + + Dictionary(String pathToDict) throws DictionaryNotFoundException { + Scanner scanner = null; + try { + scanner = new Scanner(new File(pathToDict)); + } catch (FileNotFoundException e) { + throw new DictionaryNotFoundException(e.getMessage()); + } + + String currentWord; + String toRemove = " !?,.:;\\-_=+*\"'\\(\\)\\{\\}\\[\\]%$"; + while (scanner.hasNext()) { + currentWord = scanner.next(); + currentWord = currentWord.replaceAll("[" + toRemove +"]", ""); + if (currentWord.length() >= 2) { + if (!words.containsKey(currentWord)){ + words.put(currentWord, 0L); + } + words.put(currentWord, words.get(currentWord) + 1); + numberOfWords++; + } + } + } + + public boolean hasWord(String word) { + return words.containsKey(word); + } + + public long getNumberOfWords() { + return numberOfWords; + } + + public long getWordAmount(String word) { + return words.get(word); + } +} diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 086e13f..9b38d70 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -4,6 +4,9 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.util.List; public class GameEngine { @@ -15,7 +18,6 @@ public class GameEngine { public void loadXml(String pathToXml) { - // TODO } @@ -25,9 +27,46 @@ public boolean isValidXml(String pathToXml) { return false; return true; } - public boolean isDictionaryInRightPos(){ + private boolean isDictionaryInRightPos(String dic) { return true; } + public boolean isXmlLoaded() { + return true; + } + + public boolean isStarted() { + return false; + } + + public void startGame() { + } + + public Object getStat() { + return new Integer(1); + } + + public int getDiceValue() { + return 0; + } + + public void updateBoard(List points) { + } + + public Object getBoard() { + return new Integer(1); + } + + public int getMaxRetries() { + return 1; + } + + public boolean isWordValid(String word, int tries) { + return true; + } + + public Statistics getStatistics() { + return new Statistics(null, System.currentTimeMillis(), 0, 0); + } } diff --git a/GameEngine/src/engine/Statistic.java b/GameEngine/src/engine/Statistic.java deleted file mode 100644 index a64990c..0000000 --- a/GameEngine/src/engine/Statistic.java +++ /dev/null @@ -1,21 +0,0 @@ -package engine; - - -import java.util.List; - -public class Statistic { - - private List players ; - private int numOfTurns; - private int leftBoxTiles; - private float time; //TODO: calculate - private GameDataFromXml gameData; - - - Statistic(List input_Player){ - players.addAll(input_Player) ; - numOfTurns = 0; - leftBoxTiles = gameData.getLeftBoxTiles(); - } - -} \ No newline at end of file diff --git a/GameEngine/src/engine/Statistics.java b/GameEngine/src/engine/Statistics.java new file mode 100644 index 0000000..4f219b6 --- /dev/null +++ b/GameEngine/src/engine/Statistics.java @@ -0,0 +1,33 @@ +package engine; + + +import java.util.List; + +public class Statistics { + + private List players ; + private int numOfTurns; + private int leftBoxTiles; + private long time; //TODO: calculate + private GameDataFromXml gameData; + + Statistics(List input_Player, long secondsPassed, int TurnsPlayed, int cardsLeft){ + players.addAll(input_Player) ; + time = secondsPassed; + numOfTurns = TurnsPlayed; + leftBoxTiles = cardsLeft; + } + + public long getTime() { + return time; + } + + public int getNumOfTurns() { + return numOfTurns; + } + + public int getLeftBoxTiles() { + return leftBoxTiles; + } + +} \ No newline at end of file diff --git a/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java new file mode 100644 index 0000000..4d38982 --- /dev/null +++ b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java @@ -0,0 +1,14 @@ +package engine.exceptions; + +import java.io.FileNotFoundException; + +public class DictionaryNotFoundException extends FileNotFoundException { + + public DictionaryNotFoundException () { + super(); + } + + public DictionaryNotFoundException (String message) { + super (message); + } +} From 58159ffae6718e251c30905da93d264084a2343d Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 26 Apr 2017 12:31:12 +0300 Subject: [PATCH 11/62] Renamed jabx folder to jaxb and fixed all references --- GameEngine/src/engine/GameDataFromXml.java | 26 +++++++------------ .../engine/{jabx => jaxb}/SimpleJAXBMain.java | 2 +- .../schema/SchemaBasedJAXBMain.java | 11 ++++---- .../schema/generated/DynamicPlayers.java | 2 +- .../schema/generated/GameDescriptor.java | 2 +- .../schema/generated/GameType.java | 2 +- .../schema/generated/Letter.java | 2 +- .../schema/generated/Letters.java | 2 +- .../schema/generated/ObjectFactory.java | 7 ++--- .../schema/generated/Player.java | 2 +- .../schema/generated/Players.java | 2 +- .../schema/generated/STGameType.java | 2 +- .../schema/generated/Structure.java | 4 +-- .../schema/generated/Wordiada.xsd | 0 GameEngine/src/engine/{jabx => jaxb}/sdf.java | 2 +- 15 files changed, 27 insertions(+), 41 deletions(-) rename GameEngine/src/engine/{jabx => jaxb}/SimpleJAXBMain.java (68%) rename GameEngine/src/engine/{jabx => jaxb}/schema/SchemaBasedJAXBMain.java (84%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/DynamicPlayers.java (98%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/GameDescriptor.java (98%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/GameType.java (98%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/Letter.java (98%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/Letters.java (98%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/ObjectFactory.java (95%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/Player.java (98%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/Players.java (97%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/STGameType.java (96%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/Structure.java (97%) rename GameEngine/src/engine/{jabx => jaxb}/schema/generated/Wordiada.xsd (100%) rename GameEngine/src/engine/{jabx => jaxb}/sdf.java (75%) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index b96feba..ed318ca 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -1,27 +1,19 @@ package engine; -import java.io.FileInputStream; - import java.io.*; //import java.io.FileNotFoundException; import java.lang.*; //import java.io.InputStream; -import java.sql.Struct; import java.util.*; -import java.lang.Character; import java.lang.String; -import java.math.RoundingMode; -import java.math.BigDecimal; -import java.lang.Exception; + import engine.exceptions.*; -import com.sun.org.apache.xpath.internal.SourceTree; -import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; -import engine.jabx.schema.generated.GameDescriptor; -import engine.jabx.schema.generated.Letter; -import engine.jabx.schema.generated.Letters; -import engine.jabx.schema.generated.Structure; +import engine.jaxb.schema.generated.GameDescriptor; +import engine.jaxb.schema.generated.Letter; +import engine.jaxb.schema.generated.Letters; +import engine.jaxb.schema.generated.Structure; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -43,9 +35,9 @@ public class GameDataFromXml { private int totalTiles; private int leftBoxTiles; private String dictFileName; - private short targerDeckSize; //כמות אריחים + private short targetDeckSize; //כמות אריחים - private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jabx.schema.generated"; + private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; // test: @@ -68,7 +60,7 @@ public static void main(String[] argv){ // get and set funcs: - public short getTargerDeckSize() { return targerDeckSize; } + public short getTargetDeckSize() { return targetDeckSize; } public Map getRatiofrequencyLetter() { return ratiofrequencyLetter; } @@ -124,7 +116,7 @@ public void initializingDataFromXml(String pathToXml) { dictFileName = struct.getDictionaryFileName(); calcRatiofrequencyLetter(frequencyLetter); //init targer deck size - this.targerDeckSize = struct.getLetters().getTargetDeckSize(); + this.targetDeckSize = struct.getLetters().getTargetDeckSize(); } catch (JAXBException e) { e.printStackTrace(); diff --git a/GameEngine/src/engine/jabx/SimpleJAXBMain.java b/GameEngine/src/engine/jaxb/SimpleJAXBMain.java similarity index 68% rename from GameEngine/src/engine/jabx/SimpleJAXBMain.java rename to GameEngine/src/engine/jaxb/SimpleJAXBMain.java index 7d9c0f5..8ec45f4 100644 --- a/GameEngine/src/engine/jabx/SimpleJAXBMain.java +++ b/GameEngine/src/engine/jaxb/SimpleJAXBMain.java @@ -1,4 +1,4 @@ -package engine.jabx; +package engine.jaxb; /** * Created by נוי on 23/04/2017. diff --git a/GameEngine/src/engine/jabx/schema/SchemaBasedJAXBMain.java b/GameEngine/src/engine/jaxb/schema/SchemaBasedJAXBMain.java similarity index 84% rename from GameEngine/src/engine/jabx/schema/SchemaBasedJAXBMain.java rename to GameEngine/src/engine/jaxb/schema/SchemaBasedJAXBMain.java index f5bc56a..236dc28 100644 --- a/GameEngine/src/engine/jabx/schema/SchemaBasedJAXBMain.java +++ b/GameEngine/src/engine/jaxb/schema/SchemaBasedJAXBMain.java @@ -1,13 +1,12 @@ -package engine.jabx.schema; +package engine.jaxb.schema; //import examples.jaxb.schema.generated.Countries; -import engine.jabx.schema.generated.GameDescriptor; -import engine.jabx.schema.generated.Letters; -import engine.jabx.schema.generated.Letter; -import engine.jabx.schema.generated.Structure; +import engine.jaxb.schema.generated.GameDescriptor; +import engine.jaxb.schema.generated.Letters; +import engine.jaxb.schema.generated.Structure; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -16,7 +15,7 @@ public class SchemaBasedJAXBMain { - private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jabx.schema.generated"; + private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; public static void main(String[] args) { InputStream inputStream = SchemaBasedJAXBMain.class.getResourceAsStream("/resources/master.xml"); diff --git a/GameEngine/src/engine/jabx/schema/generated/DynamicPlayers.java b/GameEngine/src/engine/jaxb/schema/generated/DynamicPlayers.java similarity index 98% rename from GameEngine/src/engine/jabx/schema/generated/DynamicPlayers.java rename to GameEngine/src/engine/jaxb/schema/generated/DynamicPlayers.java index c5dd07d..d99a154 100644 --- a/GameEngine/src/engine/jabx/schema/generated/DynamicPlayers.java +++ b/GameEngine/src/engine/jaxb/schema/generated/DynamicPlayers.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import java.util.ArrayList; import java.util.List; diff --git a/GameEngine/src/engine/jabx/schema/generated/GameDescriptor.java b/GameEngine/src/engine/jaxb/schema/generated/GameDescriptor.java similarity index 98% rename from GameEngine/src/engine/jabx/schema/generated/GameDescriptor.java rename to GameEngine/src/engine/jaxb/schema/generated/GameDescriptor.java index 9b9937b..c34fa23 100644 --- a/GameEngine/src/engine/jabx/schema/generated/GameDescriptor.java +++ b/GameEngine/src/engine/jaxb/schema/generated/GameDescriptor.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/GameEngine/src/engine/jabx/schema/generated/GameType.java b/GameEngine/src/engine/jaxb/schema/generated/GameType.java similarity index 98% rename from GameEngine/src/engine/jabx/schema/generated/GameType.java rename to GameEngine/src/engine/jaxb/schema/generated/GameType.java index c2f4a92..533858e 100644 --- a/GameEngine/src/engine/jabx/schema/generated/GameType.java +++ b/GameEngine/src/engine/jaxb/schema/generated/GameType.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/GameEngine/src/engine/jabx/schema/generated/Letter.java b/GameEngine/src/engine/jaxb/schema/generated/Letter.java similarity index 98% rename from GameEngine/src/engine/jabx/schema/generated/Letter.java rename to GameEngine/src/engine/jaxb/schema/generated/Letter.java index 8c764e8..518a460 100644 --- a/GameEngine/src/engine/jabx/schema/generated/Letter.java +++ b/GameEngine/src/engine/jaxb/schema/generated/Letter.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import java.util.ArrayList; import java.util.List; diff --git a/GameEngine/src/engine/jabx/schema/generated/Letters.java b/GameEngine/src/engine/jaxb/schema/generated/Letters.java similarity index 98% rename from GameEngine/src/engine/jabx/schema/generated/Letters.java rename to GameEngine/src/engine/jaxb/schema/generated/Letters.java index 177fc60..be3d394 100644 --- a/GameEngine/src/engine/jabx/schema/generated/Letters.java +++ b/GameEngine/src/engine/jaxb/schema/generated/Letters.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import java.util.ArrayList; import java.util.List; diff --git a/GameEngine/src/engine/jabx/schema/generated/ObjectFactory.java b/GameEngine/src/engine/jaxb/schema/generated/ObjectFactory.java similarity index 95% rename from GameEngine/src/engine/jabx/schema/generated/ObjectFactory.java rename to GameEngine/src/engine/jaxb/schema/generated/ObjectFactory.java index c05c088..3357aa8 100644 --- a/GameEngine/src/engine/jabx/schema/generated/ObjectFactory.java +++ b/GameEngine/src/engine/jaxb/schema/generated/ObjectFactory.java @@ -1,10 +1,7 @@ -package engine.jabx.schema.generated; - -import engine.GameEngine; +package engine.jaxb.schema.generated; import java.util.List; import javax.xml.bind.JAXBElement; -import javax.xml.bind.JAXBContext; import javax.xml.bind.annotation.XmlElementDecl; import javax.xml.bind.annotation.XmlRegistry; @@ -37,7 +34,7 @@ public class ObjectFactory { - //engine.jabx.schema.generated.ObjectFactory objectFactory = new engine.jabx.schema.generated.ObjectFactory(); + //engine.jaxb.schema.generated.ObjectFactory objectFactory = new engine.jaxb.schema.generated.ObjectFactory(); // JAXBContext jaxbContext tring()); /** * diff --git a/GameEngine/src/engine/jabx/schema/generated/Player.java b/GameEngine/src/engine/jaxb/schema/generated/Player.java similarity index 98% rename from GameEngine/src/engine/jabx/schema/generated/Player.java rename to GameEngine/src/engine/jaxb/schema/generated/Player.java index a5d4fa9..facbeb2 100644 --- a/GameEngine/src/engine/jabx/schema/generated/Player.java +++ b/GameEngine/src/engine/jaxb/schema/generated/Player.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import java.util.ArrayList; import java.util.List; diff --git a/GameEngine/src/engine/jabx/schema/generated/Players.java b/GameEngine/src/engine/jaxb/schema/generated/Players.java similarity index 97% rename from GameEngine/src/engine/jabx/schema/generated/Players.java rename to GameEngine/src/engine/jaxb/schema/generated/Players.java index 95f4421..fd1fde2 100644 --- a/GameEngine/src/engine/jabx/schema/generated/Players.java +++ b/GameEngine/src/engine/jaxb/schema/generated/Players.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import java.util.ArrayList; import java.util.List; diff --git a/GameEngine/src/engine/jabx/schema/generated/STGameType.java b/GameEngine/src/engine/jaxb/schema/generated/STGameType.java similarity index 96% rename from GameEngine/src/engine/jabx/schema/generated/STGameType.java rename to GameEngine/src/engine/jaxb/schema/generated/STGameType.java index b4084cb..001ff0a 100644 --- a/GameEngine/src/engine/jabx/schema/generated/STGameType.java +++ b/GameEngine/src/engine/jaxb/schema/generated/STGameType.java @@ -1,5 +1,5 @@ -package engine.jabx.schema.generated; +package engine.jaxb.schema.generated; import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; diff --git a/GameEngine/src/engine/jabx/schema/generated/Structure.java b/GameEngine/src/engine/jaxb/schema/generated/Structure.java similarity index 97% rename from GameEngine/src/engine/jabx/schema/generated/Structure.java rename to GameEngine/src/engine/jaxb/schema/generated/Structure.java index 0cff857..ee10ade 100644 --- a/GameEngine/src/engine/jabx/schema/generated/Structure.java +++ b/GameEngine/src/engine/jaxb/schema/generated/Structure.java @@ -1,7 +1,5 @@ -package engine.jabx.schema.generated; - -import engine.jabx.schema.generated.Letters; +package engine.jaxb.schema.generated; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; diff --git a/GameEngine/src/engine/jabx/schema/generated/Wordiada.xsd b/GameEngine/src/engine/jaxb/schema/generated/Wordiada.xsd similarity index 100% rename from GameEngine/src/engine/jabx/schema/generated/Wordiada.xsd rename to GameEngine/src/engine/jaxb/schema/generated/Wordiada.xsd diff --git a/GameEngine/src/engine/jabx/sdf.java b/GameEngine/src/engine/jaxb/sdf.java similarity index 75% rename from GameEngine/src/engine/jabx/sdf.java rename to GameEngine/src/engine/jaxb/sdf.java index 013deb3..54ac442 100644 --- a/GameEngine/src/engine/jabx/sdf.java +++ b/GameEngine/src/engine/jaxb/sdf.java @@ -1,4 +1,4 @@ -package engine.jabx; +package engine.jaxb; /** * Created by נוי on 23/04/2017. From 59c279409528abaa2c0e086e26bacf951fae721b Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 26 Apr 2017 20:15:46 +0300 Subject: [PATCH 12/62] Add board and edited files --- GameEngine/src/engine/Board.java | 23 +++++++++++ GameEngine/src/engine/Dictionary.java | 15 ++++++- GameEngine/src/engine/GameEngine.java | 41 +++++++++++++------ .../engine/exceptions/BoardSizeException.java | 25 +++++++++++ 4 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 GameEngine/src/engine/Board.java create mode 100644 GameEngine/src/engine/exceptions/BoardSizeException.java diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java new file mode 100644 index 0000000..b3ca1db --- /dev/null +++ b/GameEngine/src/engine/Board.java @@ -0,0 +1,23 @@ +package engine; + +import engine.exceptions.BoardSizeException; + +import java.util.HashMap; +import java.util.Map; + +public class Board { + private short size; + private Map board = new HashMap<>(); + + public Board(short size) throws BoardSizeException{ + if (size < 5 || size > 50) { + throw new BoardSizeException(size, (short)5, (short)50); + } + } + + public Map getBoard() { + return new HashMap<>(board); + } + + +} diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 5a54e24..3264190 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -18,7 +18,14 @@ public static void main(String[] args) { return; } - dic.getNumberOfWords(); + Map words = dic.getWords(); + long totalWords = dic.getNumberOfWords(), myCount = 0; + for (String word: words.keySet()) { + long val = words.get(word); + myCount += val; + System.out.println(word + ": " + val); + } + System.out.println("Total: " + totalWords + "\nMy count: " + myCount); } private long numberOfWords = 0; @@ -36,7 +43,7 @@ public static void main(String[] args) { String toRemove = " !?,.:;\\-_=+*\"'\\(\\)\\{\\}\\[\\]%$"; while (scanner.hasNext()) { currentWord = scanner.next(); - currentWord = currentWord.replaceAll("[" + toRemove +"]", ""); + currentWord = currentWord.replaceAll("[" + toRemove +"]", "").toUpperCase(); if (currentWord.length() >= 2) { if (!words.containsKey(currentWord)){ words.put(currentWord, 0L); @@ -58,4 +65,8 @@ public long getNumberOfWords() { public long getWordAmount(String word) { return words.get(word); } + + public Map getWords() { + return words; + } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 3ffe2f9..bb942f9 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -2,25 +2,31 @@ import java.lang.String; import engine.exceptions.*; + +import java.util.ArrayList; import java.util.List; +import java.util.Random; public class GameEngine { // private GameInformation info; private Player player; - private GameDataFromXml gdfx; + private List gdfx = new ArrayList<>(); + private GameDataFromXml currentGameData; + private boolean isGameStarted = false; + private int diceValue; //Cto'r GameEngine(String pathToXml){ - gdfx.initializingDataFromXml(pathToXml); - + GameDataFromXml gd = new GameDataFromXml(); + gd.initializingDataFromXml(pathToXml); //check validation: try{ - gdfx.isAllLettersApperOne(); - gdfx.isDictionaryInRightPos(gdfx.getDictFileName(), pathToXml); - gdfx.isValidBoardSize(gdfx.getBoardSize()); - gdfx.isValidXml(pathToXml); + gd.isAllLettersApperOne(); + gd.isDictionaryInRightPos(gd.getDictFileName(), pathToXml); + gd.isValidBoardSize(gd.getBoardSize()); + gd.isValidXml(pathToXml); } catch(InvalidInputException e){ //TODO: ask ido @@ -31,21 +37,23 @@ public class GameEngine { catch(NotXmlFileException e){ //TODO: ask ido } - + gdfx.add(gd); } public void loadXml(String pathToXml) { } public boolean isXmlLoaded() { - return true; + return !gdfx.isEmpty(); } public boolean isStarted() { - return false; + return isGameStarted; } public void startGame() { + currentGameData = gdfx.get(0); + isGameStarted = true; } public Object getStat() { @@ -53,7 +61,9 @@ public Object getStat() { } public int getDiceValue() { - return 0; + Random random = new Random(); + diceValue = random.nextInt(currentGameData.getNumOfCubeWigs() - 2) + 2; + return diceValue; } public void updateBoard(List points) { @@ -68,7 +78,14 @@ public int getMaxRetries() { } public boolean isWordValid(String word, int tries) { - return true; + if (tries <= currentGameData.getNumOfTries()) { + if (true) { //TODO: check in dictionary + //TODO: update user + return true; + } + return false; + } + return false; //TODO: throw NumOfRetriesException } public Statistics getStatistics() { diff --git a/GameEngine/src/engine/exceptions/BoardSizeException.java b/GameEngine/src/engine/exceptions/BoardSizeException.java new file mode 100644 index 0000000..c1eb8b0 --- /dev/null +++ b/GameEngine/src/engine/exceptions/BoardSizeException.java @@ -0,0 +1,25 @@ +package engine.exceptions; + +public class BoardSizeException extends Exception { + private short size; + private short minSize; + private short maxSize; + public BoardSizeException() {} + public BoardSizeException(short size, short minSize, short maxSize) { + this.size = size; + this.maxSize = maxSize; + this.minSize = minSize; + } + + public short getSize() { + return size; + } + + public short getMinSize() { + return minSize; + } + + public short getMaxSize() { + return maxSize; + } +} From 34954e3d2f285e09445b742dfbbfac45f8068146 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Fri, 28 Apr 2017 19:00:23 +0300 Subject: [PATCH 13/62] update Statistics class and print --- ConsoleUI/src/consoleui/ConsoleHandler.java | 25 ++++++---- GameEngine/src/engine/Statistics.java | 55 ++++++++++++++++++--- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 6acd3b7..480f6ea 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -120,21 +120,28 @@ public static String getWord(int tryNum, int maxTries) { return word.toUpperCase(); } - public static void showStatistics(Statistics stat) { + public static void showStatistics(Statistics stats) { System.out.println("Game Statistics:\n"); - System.out.println("Turns played: " + stat.getNumOfTurns()); - long time = stat.getTime(); + // number of turns + System.out.println("Turns played: " + stats.getNumOfTurns()); + // total time played + long time = stats.getTime(); System.out.println("Time passed from game start: " + time / 60 + ":" + time % 60); - System.out.println("Number of cards left: " + stat.getLeftBoxTiles()); + // cards left + int cardsLeft = stats.getLeftBoxTiles(); + System.out.println("Number of cards left: " + cardsLeft); for (int i = 0; i < 12; i++) { //TODO: fix for System.out.println("\t" + ('A' + i) + " - " + 4 + "/" + 30); } - for (int i = 0; i < 2; i++) { - System.out.println("Player " + "Ido"); - System.out.println(" Score: " + 5000); - for (int j = 0; j < 3; j++) { - System.out.println("umbrella" + ": " + 34 + "/" + 12398); + // players + long totalWords = stats.getTotalWords(); + for (Statistics.PlayerData player: stats.getPlayers()) { + System.out.println("Player " + player.getName()); + System.out.println(" Score: " + player.getScore()); + System.out.println(" Words:"); + for (String word: player.getWords()) { + System.out.println("\t" + word + ": " + stats.getWordCount(word) + "/" + totalWords); } } } diff --git a/GameEngine/src/engine/Statistics.java b/GameEngine/src/engine/Statistics.java index 4f219b6..a2ffa65 100644 --- a/GameEngine/src/engine/Statistics.java +++ b/GameEngine/src/engine/Statistics.java @@ -1,25 +1,53 @@ package engine; - +import java.util.ArrayList; import java.util.List; public class Statistics { - private List players ; + private List players ; private int numOfTurns; private int leftBoxTiles; - private long time; //TODO: calculate + private long playTime; //TODO: calculate private GameDataFromXml gameData; + private Dictionary dict; + + public class PlayerData { + private Player player; + + private PlayerData(Player p) { + player = p; + } + + public String getName() { + return player.getName(); + } - Statistics(List input_Player, long secondsPassed, int TurnsPlayed, int cardsLeft){ - players.addAll(input_Player) ; - time = secondsPassed; - numOfTurns = TurnsPlayed; + public List getWords() { + + return player.getWords(); + } + + public float getScore() { + return player.getScore(); + } + } + + Statistics(List inputPlayer, long playTime, int turnsPlayed, int cardsLeft, GameDataFromXml gd, + Dictionary dic){ + players = new ArrayList<>(); + for (Player player: inputPlayer) { + players.add(new PlayerData(player)); + } + this.playTime = playTime; + numOfTurns = turnsPlayed; leftBoxTiles = cardsLeft; + gameData = gd; + dict = dic; } public long getTime() { - return time; + return playTime; } public int getNumOfTurns() { @@ -30,4 +58,15 @@ public int getLeftBoxTiles() { return leftBoxTiles; } + public List getPlayers() { + return players; + } + + public long getTotalWords() { + return dict.getNumberOfWords(); + } + + public long getWordCount(String word) { + return dict.hasWord(word) ? dict.getWordAmount(word) : 0; + } } \ No newline at end of file From 572e56be5f124a6ebdcfbeed07e80327ca65891c Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 11:32:18 +0300 Subject: [PATCH 14/62] update Dictionary, add Status and fix co-responding UI references, including board print --- ConsoleUI/src/consoleui/ConsoleHandler.java | 21 +++-- ConsoleUI/src/consoleui/ConsoleUI.java | 27 ++++--- GameEngine/src/engine/Dictionary.java | 89 ++++++++++++++++++--- GameEngine/src/engine/Player.java | 32 ++++++-- GameEngine/src/engine/Statistics.java | 4 +- GameEngine/src/engine/Status.java | 25 ++++++ 6 files changed, 161 insertions(+), 37 deletions(-) create mode 100644 GameEngine/src/engine/Status.java diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 480f6ea..7d6b46e 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Scanner; import engine.Statistics; +import engine.Status; //TODO: fix access permissions public class ConsoleHandler { @@ -41,18 +42,17 @@ public static String getXML() { return pathToXml; } - public static void showGameStatus(Object o) { - // TODO: change 'Object o' to the correct type - System.out.println("Game Stats:\n"); - printBoard(5,5, null); - System.out.println("The number of cards remaining in the pot: " + 5); - System.out.println("Current player: " + "Player1"); + public static void showGameStatus(Status status) { + System.out.println("Game Status:\n"); + printBoard(status.getBoard()); + System.out.println("The number of cards remaining in the pot: " + status.getLeftTiles()); + System.out.println("Current player: " + status.getPlayerName()); } - public static void printBoard(int x, int y, Object o) { + public static void printBoard(char[][] board) { // TODO: change the signature of the function and fill with correct data - int numOfRows = y; - int numOfCols = x; + int numOfRows = board.length; + int numOfCols = board.length; int col, row; String line; String boarderLine = numOfRows > 9 ? "-----" : "---"; @@ -67,7 +67,7 @@ public static void printBoard(int x, int y, Object o) { line = numOfRows > 9 && row < 9 ? " " : ""; line += (row + 1) + "|"; for (col = 0; col < numOfCols; col++) { - line += " |"; + line += board[row][col] + "|"; } line += row + 1; System.out.println(line); @@ -80,7 +80,6 @@ private static void boardIndices(int numOfCols, int numOfRows) { int col; String line; String lineStart = numOfRows > 9 ? " |" : " |"; - // Print top indices line = lineStart; if (numOfRows > 9) { for (col = 1; col <= numOfCols; col++) { diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index ff69fdc..0456999 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -3,9 +3,12 @@ import java.util.List; import engine.GameEngine; import engine.Statistics; +import engine.Status; +import engine.exceptions.BoardSizeException; public class ConsoleUI { - private static GameEngine engine = new GameEngine(); + // TODO: fix exceptions + private static GameEngine engine = new GameEngine("D:\\share\\Wordiada\\GameEngine\\src\\resources\\master.xml"); public static void main(String[] args) { int selectedMenu; while((selectedMenu= ConsoleHandler.showMainMenu()) != 6){ @@ -17,7 +20,7 @@ public static void main(String[] args) { startGame(); break; case 3: - ConsoleHandler.showGameStatus(engine.getStat()); + ConsoleHandler.showGameStatus(engine.getStatus()); break; case 4: playTurn(); @@ -29,9 +32,9 @@ public static void main(String[] args) { } } - System.out.println("Game ended."); - Object o = engine.getBoard(); - ConsoleHandler.printBoard(5, 7, o); + System.out.println("---- Game ended ----"); + char[][] board = engine.getBoard(); + ConsoleHandler.printBoard(board); Statistics stat = engine.getStatistics(); ConsoleHandler.showStatistics(stat); } @@ -61,7 +64,13 @@ else if (engine.isStarted()) { "Please DON'T use this option again."); } else { - engine.startGame(); + try { + engine.startGame(); + } catch (BoardSizeException e) { + System.out.println("XML not valid!"); + System.out.println("Expected size is between " + e.getMinSize() + " to " + e.getMaxSize()); + System.out.println("Got: " + e.getSize()); + } } } @@ -69,8 +78,8 @@ private static void playTurn() { int diceValue = engine.getDiceValue(), tries; List points = ConsoleHandler.getPoints(diceValue); engine.updateBoard(points); - Object o = engine.getBoard(); - ConsoleHandler.printBoard(5, 7, o); + char[][] board = engine.getBoard(); + ConsoleHandler.printBoard(board); int maxTries = engine.getMaxRetries(); for (tries = 0; tries < maxTries; tries++) { String word = ConsoleHandler.getWord(tries + 1, maxTries); @@ -84,6 +93,6 @@ private static void playTurn() { System.out.println("\nNo more retries!"); } System.out.println("Changing to next player..."); - ConsoleHandler.showGameStatus(engine.getStat()); + ConsoleHandler.showGameStatus(engine.getStatus()); } } diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 3264190..34b97a2 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -9,6 +9,7 @@ import java.util.Scanner; public class Dictionary { + /* TODO: remove public static void main(String[] args) { Dictionary dic; try { @@ -18,21 +19,73 @@ public static void main(String[] args) { return; } - Map words = dic.getWords(); + Map words = dic.getWords(); long totalWords = dic.getNumberOfWords(), myCount = 0; for (String word: words.keySet()) { - long val = words.get(word); - myCount += val; - System.out.println(word + ": " + val); + Word word1 = words.get(word); + long count = word1.getCount(); + myCount += count; + System.out.println(word + ": " + count + ", " + word1.getFrequency()); } System.out.println("Total: " + totalWords + "\nMy count: " + myCount); } + */ private long numberOfWords = 0; - private Map words = new HashMap<>(); + private Map words = new HashMap<>(); + + private class Word { + private String word; + private long count = 0; + private float frequency; + + private Word(String word) { + this.word = word; + count = 1; + } + + private long getCount() { + return count; + } + + private float getFrequency() { + return frequency; + } + + private void setFrequency(float value) { + frequency = value; + } + + private void advanceCount() { + count++; + } + + @Override + public int hashCode() { + int hash = 13; + hash = 71 * hash + word.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj == this){ + return true; + } + if (!(obj instanceof Word)) { + return false; + } + + final Word other = (Word) obj; + return !((this.word == null) ? (other.word != null) : !this.word.equals(other.word)); + } + } Dictionary(String pathToDict) throws DictionaryNotFoundException { - Scanner scanner = null; + Scanner scanner; try { scanner = new Scanner(new File(pathToDict)); } catch (FileNotFoundException e) { @@ -40,18 +93,21 @@ public static void main(String[] args) { } String currentWord; - String toRemove = " !?,.:;\\-_=+*\"'\\(\\)\\{\\}\\[\\]%$"; + String toRemove = " !?,.:;-_=+*\"'\\(\\)\\{\\}\\[\\]%$"; while (scanner.hasNext()) { currentWord = scanner.next(); currentWord = currentWord.replaceAll("[" + toRemove +"]", "").toUpperCase(); if (currentWord.length() >= 2) { if (!words.containsKey(currentWord)){ - words.put(currentWord, 0L); + words.put(currentWord, new Word(currentWord)); + } + else { + words.get(currentWord).advanceCount(); } - words.put(currentWord, words.get(currentWord) + 1); numberOfWords++; } } + calcFrequency(); } public boolean hasWord(String word) { @@ -63,10 +119,21 @@ public long getNumberOfWords() { } public long getWordAmount(String word) { - return words.get(word); + return words.get(word).getCount(); } public Map getWords() { - return words; + Map map = new HashMap<>(); + for (Word word: words.values()) { + map.put(word.word, word.getCount()); + } + return map; + } + + private void calcFrequency() { + for (Word word: words.values()) { + float freq = word.getCount() / numberOfWords * 100; + word.setFrequency(freq); + } } } diff --git a/GameEngine/src/engine/Player.java b/GameEngine/src/engine/Player.java index 85b827c..7ec5d4c 100644 --- a/GameEngine/src/engine/Player.java +++ b/GameEngine/src/engine/Player.java @@ -1,13 +1,35 @@ package engine; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; public class Player { private String name; private float score; - private Map numOfWords = new HashMap (); + private List words; + + public Player(String name) { + this.name = name; + score = 0; + words = new ArrayList<>(); + } + + public void updateScore(String word, float score) { + this.score += score; + words.add(word); + } + + public String getName() { + return name; + } + + public float getScore() { + return score; + } + + public List getWords() { + List l = new ArrayList<>(); + l.addAll(words); + return l; + } } diff --git a/GameEngine/src/engine/Statistics.java b/GameEngine/src/engine/Statistics.java index a2ffa65..365c8b5 100644 --- a/GameEngine/src/engine/Statistics.java +++ b/GameEngine/src/engine/Statistics.java @@ -8,10 +8,12 @@ public class Statistics { private List players ; private int numOfTurns; private int leftBoxTiles; - private long playTime; //TODO: calculate + private long playTime; private GameDataFromXml gameData; private Dictionary dict; + //TODO: add letters left in box of cards + public class PlayerData { private Player player; diff --git a/GameEngine/src/engine/Status.java b/GameEngine/src/engine/Status.java new file mode 100644 index 0000000..8b3cd6c --- /dev/null +++ b/GameEngine/src/engine/Status.java @@ -0,0 +1,25 @@ +package engine; + +public class Status { + private int leftTiles; + private String playerName; + private char[][] board; + + Status(char[][] board, String playerName, int leftTiles) { + this.board = board; + this.leftTiles = leftTiles; + this.playerName = playerName; + } + + public int getLeftTiles() { + return leftTiles; + } + + public String getPlayerName() { + return playerName; + } + + public char[][] getBoard() { + return board; + } +} From 094383b71dc4430847b09e77bef48f94835ca055 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 15:02:41 +0300 Subject: [PATCH 15/62] fix ConsoleHandler class access permissions --- ConsoleUI/src/consoleui/ConsoleHandler.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 7d6b46e..dbec31d 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -6,10 +6,9 @@ import engine.Statistics; import engine.Status; -//TODO: fix access permissions -public class ConsoleHandler { +class ConsoleHandler { - public static int showMainMenu() { + static int showMainMenu() { int selectedMenuItem; Scanner scanner = new Scanner(System.in); @@ -29,7 +28,7 @@ public static int showMainMenu() { return selectedMenuItem; } - public static String getXML() { + static String getXML() { Scanner scanner = new Scanner(System.in); String pathToXml; @@ -42,14 +41,14 @@ public static String getXML() { return pathToXml; } - public static void showGameStatus(Status status) { + static void showGameStatus(Status status) { System.out.println("Game Status:\n"); printBoard(status.getBoard()); System.out.println("The number of cards remaining in the pot: " + status.getLeftTiles()); System.out.println("Current player: " + status.getPlayerName()); } - public static void printBoard(char[][] board) { + static void printBoard(char[][] board) { // TODO: change the signature of the function and fill with correct data int numOfRows = board.length; int numOfCols = board.length; @@ -94,7 +93,7 @@ private static void boardIndices(int numOfCols, int numOfRows) { System.out.println(line); } - public static List getPoints(int numOfValues) { + static List getPoints(int numOfValues) { Scanner scanner = new Scanner(System.in); List points = new ArrayList<>(); System.out.println("Please enter "+ numOfValues + "coordinates."); @@ -109,7 +108,7 @@ public static List getPoints(int numOfValues) { return points; } - public static String getWord(int tryNum, int maxTries) { + static String getWord(int tryNum, int maxTries) { String word; Scanner scanner = new Scanner(System.in); @@ -119,7 +118,7 @@ public static String getWord(int tryNum, int maxTries) { return word.toUpperCase(); } - public static void showStatistics(Statistics stats) { + static void showStatistics(Statistics stats) { System.out.println("Game Statistics:\n"); // number of turns System.out.println("Turns played: " + stats.getNumOfTurns()); From 6c528bf78382929c1a951b5df306b89322109fbb Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 15:05:08 +0300 Subject: [PATCH 16/62] changed showGameStatus func so now can be shown after xml load --- ConsoleUI/src/consoleui/ConsoleHandler.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index dbec31d..a90f4b9 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -41,11 +41,18 @@ static String getXML() { return pathToXml; } - static void showGameStatus(Status status) { + static void showGameStatus(Status status, boolean needFullPrint) { System.out.println("Game Status:\n"); printBoard(status.getBoard()); - System.out.println("The number of cards remaining in the pot: " + status.getLeftTiles()); - System.out.println("Current player: " + status.getPlayerName()); + String line = "The number of cards "; + if (needFullPrint) { + line += "remaining "; + } + line += "in the pot: " + status.getLeftTiles(); + System.out.println(line); + if (needFullPrint) { + System.out.println("Current player: " + status.getPlayerName()); + } } static void printBoard(char[][] board) { From cbe2bc58d17bea0fd1e45e8970289233f6c1af3c Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 15:07:51 +0300 Subject: [PATCH 17/62] changed the variable type of the board print from String to StringBuilder --- ConsoleUI/src/consoleui/ConsoleHandler.java | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index a90f4b9..603caa4 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -60,22 +60,25 @@ static void printBoard(char[][] board) { int numOfRows = board.length; int numOfCols = board.length; int col, row; - String line; - String boarderLine = numOfRows > 9 ? "-----" : "---"; + StringBuilder line = new StringBuilder(); + StringBuilder boarderLine = new StringBuilder(numOfRows > 9 ? "-----" : "---"); + String tmpStr; for (col = 0; col < numOfCols; col++) { - boarderLine += "--"; + boarderLine.append("--"); } System.out.println("Current Board:\n"); boardIndices(numOfCols, numOfRows); System.out.println(boarderLine); // print board for (row = 0; row < numOfRows; row++) { - line = numOfRows > 9 && row < 9 ? " " : ""; - line += (row + 1) + "|"; + line.append(numOfRows > 9 && row < 9 ? " " : ""); + tmpStr = (row + 1) + "|"; + line.append(tmpStr); for (col = 0; col < numOfCols; col++) { - line += board[row][col] + "|"; + tmpStr = board[row][col] + "|"; + line.append(tmpStr); } - line += row + 1; + line.append(row + 1); System.out.println(line); System.out.println(boarderLine); } @@ -84,18 +87,19 @@ static void printBoard(char[][] board) { private static void boardIndices(int numOfCols, int numOfRows) { int col; - String line; - String lineStart = numOfRows > 9 ? " |" : " |"; - line = lineStart; + StringBuilder line = new StringBuilder(); + String tmpStr, lineStart = numOfRows > 9 ? " |" : " |"; + line.append(lineStart); if (numOfRows > 9) { for (col = 1; col <= numOfCols; col++) { - line += col % 10 == 0 ? col / 10 + "|" : " |"; + line.append(col % 10 == 0 ? col / 10 + "|" : " |"); } System.out.println(line); } - line = lineStart; + line.append(lineStart); for (col = 0; col < numOfCols; col++) { - line += (col + 1) % 10 + "|"; + tmpStr = (col + 1) % 10 + "|"; + line.append(tmpStr); } System.out.println(line); } From 5a0f0a2816779776d74e0c530f76ba896a2c46ed Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 15:13:24 +0300 Subject: [PATCH 18/62] add message in getPoints func and update ConsoleUI class w/ all needed changes --- ConsoleUI/src/consoleui/ConsoleHandler.java | 5 ++++- ConsoleUI/src/consoleui/ConsoleUI.java | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 603caa4..1af011a 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -104,9 +104,12 @@ private static void boardIndices(int numOfCols, int numOfRows) { System.out.println(line); } - static List getPoints(int numOfValues) { + static List getPoints(int numOfValues, boolean sizeWasTooShort) { Scanner scanner = new Scanner(System.in); List points = new ArrayList<>(); + if (sizeWasTooShort) { + System.out.println("The number of coordinates is too short! Try again...\n"); + } System.out.println("Please enter "+ numOfValues + "coordinates."); System.out.println("The format is: row col. example: 5 5\n"); for (int i = 0; i < numOfValues; i++) { diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 0456999..deffb18 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -3,7 +3,6 @@ import java.util.List; import engine.GameEngine; import engine.Statistics; -import engine.Status; import engine.exceptions.BoardSizeException; public class ConsoleUI { @@ -20,7 +19,7 @@ public static void main(String[] args) { startGame(); break; case 3: - ConsoleHandler.showGameStatus(engine.getStatus()); + ConsoleHandler.showGameStatus(engine.getStatus(), true); break; case 4: playTurn(); @@ -51,6 +50,7 @@ private static void getXml() { System.out.println("Error, " + e.getMessage()); } } + ConsoleHandler.showGameStatus(engine.getStatus(), false); System.out.println("XML file " + pathToXml + " loaded successfully!"); } @@ -75,9 +75,13 @@ else if (engine.isStarted()) { } private static void playTurn() { + boolean listSizeTooShort = false; + List points; int diceValue = engine.getDiceValue(), tries; - List points = ConsoleHandler.getPoints(diceValue); - engine.updateBoard(points); + do { + points = ConsoleHandler.getPoints(diceValue, listSizeTooShort); + listSizeTooShort = !engine.updateBoard(points); + } while(listSizeTooShort); char[][] board = engine.getBoard(); ConsoleHandler.printBoard(board); int maxTries = engine.getMaxRetries(); @@ -93,6 +97,6 @@ private static void playTurn() { System.out.println("\nNo more retries!"); } System.out.println("Changing to next player..."); - ConsoleHandler.showGameStatus(engine.getStatus()); + ConsoleHandler.showGameStatus(engine.getStatus(), true); } } From 056aea014aaf9c0c5914c14084a7615fe6ee8cf5 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 30 Apr 2017 15:14:11 +0300 Subject: [PATCH 19/62] board + gamedatatoxml + gameengine --- GameEngine/src/engine/Board.java | 135 +++++++++- GameEngine/src/engine/Dictionary.java | 12 + GameEngine/src/engine/GameDataFromXml.java | 239 ++++++++---------- GameEngine/src/engine/GameEngine.java | 7 +- .../exceptions/NotEnoughLettersException.java | 23 ++ 5 files changed, 271 insertions(+), 145 deletions(-) create mode 100644 GameEngine/src/engine/exceptions/NotEnoughLettersException.java diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index b3ca1db..883422f 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -1,23 +1,144 @@ package engine; +import com.sun.org.apache.xpath.internal.SourceTree; +import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; import engine.exceptions.BoardSizeException; +import engine.jaxb.schema.generated.Letter; +import java.util.Random; +import engine.jaxb.*; import java.util.HashMap; import java.util.Map; +import java.util.*; +import engine.jaxb.sdf; public class Board { + + public class Point{ + private int x; + private int y; + + Point(int _x, int _y){ + x = _x; + y = _y; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + } + private class Cell{ + boolean isShown; + String sign; + + Cell(String _sign, boolean _isShown) { + isShown = _isShown; + sign = _sign; + } + + } + private short size; - private Map board = new HashMap<>(); + Cell [][] board; + // Map ShownLetters = new HashMap<>(); + Map > initLettrs = new HashMap<>(); + + public Cell [][] getBoard() {return board;} + + + //test: + public static void main(String [] argv){ + Board b = new Board((short)6); + b.printBoard(b.getBoard()); + System.out.print('\r'); + + } - public Board(short size) throws BoardSizeException{ - if (size < 5 || size > 50) { - throw new BoardSizeException(size, (short)5, (short)50); + + //C'tor + Board(short _size, List letters, int totalAmountLetters){ + + int x,y; + Cell toAdd; + Point p; + List usedPoints =new ArrayList<>(); + this.board = new Cell[_size][_size]; + size = _size; + + //(x,y) point in the board + Random xy = new Random(); + //if less or equal amount letters than board + if(totalAmountLetters <= _size * _size) + { + for(GameDataFromXml.DataLetter letter : letters){ + toAdd =new Cell(letter.getLetter().getSign().get(0), false); + List empty = new ArrayList<>(); + initLettrs.put(toAdd, empty ); + + for(int i = 0 ; i < letter.getAmount(); i++){ + do { + x = xy.nextInt(size); + y = xy.nextInt(size); + p = new Point(x,y); + } while (initLettrs.containsValue(p)); + initLettrs.get(toAdd).add(p); + } + } } + //more letters than board size + else{ + + + } + } - public Map getBoard() { - return new HashMap<>(board); + public void setBoard(Cell[][] board) { + this.board = board; } +/* + public void printLetterInBoard(char sign){ + System.out.println(String.format("%-30s","h")); + }*/ -} + public void printBoard(char[][] board) + { + //התקרה + for(int i =0; i < size; i++){ + System.out.print("-------"); + } + System.out.println(); + + for(int j =0; j < size * 2; j++) { + + //colums + if(j % 2 == 0) { + for (int i = 0; i < size + 1; i++) { + char ch = 'a'; + System.out.print("| " + ch + " "); + } + System.out.println(); + for (int i = 0; i < size + 1; i++) { + System.out.print("| "); + } + System.out.println(); + } + + //rows + else{ + for(int i =0; i < size; i++){ + System.out.print("-------"); + } + System.out.println(); + } + + } + + + } +} \ No newline at end of file diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 3264190..2b8057d 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -2,8 +2,10 @@ import engine.exceptions.DictionaryNotFoundException; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileReader; import java.util.HashMap; import java.util.Map; import java.util.Scanner; @@ -31,6 +33,7 @@ public static void main(String[] args) { private long numberOfWords = 0; private Map words = new HashMap<>(); + Dictionary(String pathToDict) throws DictionaryNotFoundException { Scanner scanner = null; try { @@ -54,6 +57,15 @@ public static void main(String[] args) { } } + + public void calcFrequencyWord(String pathToDictFile){ + + + + + } + + public boolean hasWord(String word) { return words.containsKey(word); } diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index ed318ca..86be53f 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -22,64 +22,94 @@ public class GameDataFromXml { - Map frequencyLetter = new HashMap(); - Map ratiofrequencyLetter = new HashMap(); + public class DataLetter{ + private Letter letter; // sign , score, freq + private int amount = 0; + + DataLetter(Letter l){ + letter = l; + } + public Letter getLetter() { + return letter; + } + + public void setAmount(int amount) { + this.amount = amount; + } - Map frequencyWord = new HashMap(); - List letters = new ArrayList(); + public int getAmount() { + return amount; + } + public void setLetter(Letter letter) { + this.letter = letter; + } + } + List letters = new ArrayList<>(); + + public int totalAmountOfLetters = 0; private int boardSize; private int numOfCubeWigs; private int numOfTries; - private int totalTiles; - private int leftBoxTiles; + private int leftTargetDeckSize; //בקופה private String dictFileName; - private short targetDeckSize; //כמות אריחים - + private short totalTargetDeckSize; //כמות אריחים + //private int totalWordsInDict;----> moved to dictionary class private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; // test: - public static void main(String[] argv){ + public static void main(String[] argv) { int freqratio = 0; GameDataFromXml g = new GameDataFromXml(); g.initializingDataFromXml("ABC"); - System.out.println("board size: "+ g.getBoardSize()); - System.out.println("num of cubs: " + g.getNumOfCubeWigs() ); - for(int i: g.getRatiofrequencyLetter().values()) + System.out.println("board size: " + g.getBoardSize()); + System.out.println("num of cubs: " + g.getNumOfCubeWigs()); + for (int i : g.getRatiofrequencyLetter().values()) System.out.println(i); - for (int i=0; i getRatiofrequencyLetter() { - return ratiofrequencyLetter; + public short getTargetDeckSize() { + return totalTargetDeckSize; } + + // public Map getRatiofrequencyLetter() { + // return ratiofrequencyLetter; + // } + public int getBoardSize() { return boardSize; } + public int getNumOfCubeWigs() { return numOfCubeWigs; } + public int getNumOfTries() { return numOfTries; } - public List getLetters() { + + public List getLetters() { return letters; } - public Map getFrequencyLetter() { - return frequencyLetter; + + // public Map getFrequencyLetter() { + // return frequencyLetter; + //} + + public String getDictFileName() { + return dictFileName; } - public String getDictFileName() { return dictFileName; } public void initializingDataFromXml(String pathToXml) { @@ -96,16 +126,23 @@ public void initializingDataFromXml(String pathToXml) { Structure struct; try { + double totalFreq = 0; gd = deserializeFrom(inputStream); struct = gd.getStructure(); - Letters letters = struct.getLetters(); - // creates list of letters + frequency + // creates list of data letters + + for (int i = 0; i < struct.getLetters().getLetter().size(); i++) { + this.letters.add(i,new DataLetter(struct.getLetters().getLetter().get(i))); + totalFreq += this.letters.get(i).getLetter().getFrequency(); + } - for (int i = 0; i < letters.getLetter().size(); i++) { - this.letters.add(i, letters.getLetter().get(i)); - frequencyLetter.put( this.letters.get(i).getSign().get(0), this.letters.get(i).getFrequency()); + for(int i = 0; i < letters.size(); i++){ + double freq = letters.get(i).getLetter().getFrequency(); + letters.get(i).setAmount((int) ((Math.ceil(freq / 100 )) * totalFreq)); + totalAmountOfLetters += letters.get(i).amount; } + //init board size boardSize = struct.getBoardSize(); //init num of wings @@ -114,29 +151,36 @@ public void initializingDataFromXml(String pathToXml) { this.numOfTries = struct.getRetriesNumber(); //init dictionart file name dictFileName = struct.getDictionaryFileName(); - calcRatiofrequencyLetter(frequencyLetter); //init targer deck size - this.targetDeckSize = struct.getLetters().getTargetDeckSize(); + this.totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); + // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי } catch (JAXBException e) { e.printStackTrace(); } } + // NO NEED: - public void calcRatiofrequencyLetter(Map frequencyletter){ + // calc functions: +/* + public void calcRatiofrequencyLetter(Map frequencyletter) { double totalfreq = 0; int ratiofreq; - for(Double freq : frequencyletter.values()){ + for (Double freq : frequencyletter.values()) { totalfreq += freq; } - for(Map.Entry item : frequencyletter.entrySet()){ - ratiofreq = (int)Math.ceil((item.getValue()/totalfreq)*100); + for (Map.Entry item : frequencyletter.entrySet()) { + ratiofreq = (int) Math.ceil((item.getValue() / totalfreq) * 100); this.ratiofrequencyLetter.put(item.getKey(), ratiofreq); } } +*/ + + //creats the xml details: + private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); Unmarshaller u = jc.createUnmarshaller(); @@ -145,140 +189,63 @@ private static GameDescriptor deserializeFrom(InputStream in) throws JAXBExcepti // check Validation functions: - public boolean isValidXml(String pathToXml) throws NotXmlFileException { + public boolean isValidXml(String pathToXml) throws NotXmlFileException { - String extension = pathToXml.substring(pathToXml.lastIndexOf(".") + 1, pathToXml.length()); - if ((extension != "xml") || (extension != ".xml")){ - throw new NotXmlFileException("ITS NOT XML FILE!"); - } - else + String extension = pathToXml.substring(pathToXml.lastIndexOf(".") + 1, pathToXml.length()); + if ((extension != "xml") || (extension != ".xml")) { + throw new NotXmlFileException("ITS NOT XML FILE!"); + } else return true; } // call this func after calling the one above - public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) throws WrongPathException{ + public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) throws WrongPathException { - pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" - while (!pathToXml.endsWith("\\")) { - pathToXml = pathToXml.substring(0, pathToXml.length() - 1); - } - if (pathToDictFile == pathToXml + "dictionary\\" + this.getDictFileName() + ".txt") - return true; - else { - throw new WrongPathException("THE PATH: " + pathToDictFile + " IS NOT THE VALID PATH TO DICTIONARY FILE!"); - } + pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" + while (!pathToXml.endsWith("\\")) { + pathToXml = pathToXml.substring(0, pathToXml.length() - 1); + } + if (pathToDictFile == pathToXml + "dictionary\\" + this.getDictFileName() + ".txt") + return true; + else { + throw new WrongPathException("THE PATH: " + pathToDictFile + " IS NOT THE VALID PATH TO DICTIONARY FILE!"); + } } - public boolean isValidBoardSize(int size) throws InvalidInputException{ - if((size >= 5) && (size <= 50)) + public boolean isValidBoardSize(int size) throws InvalidInputException { + if ((size >= 5) && (size <= 50)) return true; else throw new InvalidInputException("BOARD SIZE" + size + " IS OUT OF RANGE!"); } - public boolean isAllLettersApperOne() throws InvalidInputException{ + public boolean isAllLettersApperOne() throws InvalidInputException { boolean isMoreThanOnce = false; - for(int i = 0; i < this.getLetters().size(); i++){ + for (int i = 0; i < this.getLetters().size(); i++) { Letter l = this.getLetters().get(i); String c = this.getLetters().get(i).getSign().get(0); this.getLetters().remove(i); isMoreThanOnce = this.getLetters().contains(c); - this.getLetters().add(i,l); + this.getLetters().add(i, l); //appears more than once - if(isMoreThanOnce) + if (isMoreThanOnce) throw new InvalidInputException("THE SIGN: " + c + "APPEARS MORE THAN ONCE!"); } return true; } -} - - - - - - /* - GameDescriptor gd; - Structure struct; - InputStream inputStream = GameDataFromXml.class.getResourceAsStream("/resources/master.xml"); - try { - gd = deserializeFrom(inputStream); - struct = gd.getStructure(); - Letters letters = struct.getLetters(); - - // creats list of letters - for (int i = 0; i < letters.getLetter().size(); i++) { - //System.out.println("letter number" + i + ": " + letters.getLetter().get(i).getSign()); - letters.getLetter().add(i, letters.getLetter().get(i)); - } - } catch (JAXBException e) { - e.printStackTrace(); + public boolean isEnoughLettersForBoard() throws NotEnoughLettersException { + if (this.letters.size() < this.boardSize * this.boardSize) { + throw new NotEnoughLettersException(this.boardSize * this.boardSize, this.letters.size()); } - - //init board size - try { - gd = deserializeFrom(inputStream); - - } catch (JAXBException e) { - e.printStackTrace(); - } - - struct = gd.getStructure(); - - boardSize = struct.getBoardSize(); + return true; } +} - private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { - JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); - Unmarshaller u = jc.createUnmarshaller(); - return (GameDescriptor)u.unmarshal(in); - }*/ - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - public int getLeftBoxTiles(){ - return this.leftBoxTiles; - } - - public boolean isValid() - { - Structure struct; - return true; - } - : all illiegele issues + xml loading + txt file in dictionary library - */ diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index bb942f9..d83a28e 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -15,10 +15,15 @@ public class GameEngine { private GameDataFromXml currentGameData; private boolean isGameStarted = false; private int diceValue; + private Board board; //Cto'r GameEngine(String pathToXml){ + //TODO: check with ido if there is a need for ctor + } + + public void loadXml(String pathToXml) { GameDataFromXml gd = new GameDataFromXml(); gd.initializingDataFromXml(pathToXml); //check validation: @@ -40,8 +45,6 @@ public class GameEngine { gdfx.add(gd); } - public void loadXml(String pathToXml) { - } public boolean isXmlLoaded() { return !gdfx.isEmpty(); diff --git a/GameEngine/src/engine/exceptions/NotEnoughLettersException.java b/GameEngine/src/engine/exceptions/NotEnoughLettersException.java new file mode 100644 index 0000000..ef52c58 --- /dev/null +++ b/GameEngine/src/engine/exceptions/NotEnoughLettersException.java @@ -0,0 +1,23 @@ +package engine.exceptions; + + +public class NotEnoughLettersException extends Exception { + private int expectedAmount; + private int currentAmount; + + public NotEnoughLettersException() {} + public NotEnoughLettersException(int expected, int current){ + this.currentAmount = current; + this.expectedAmount = expected; + } + + public NotEnoughLettersException(String message) { + super (message); + } + public NotEnoughLettersException(Throwable cause) { + super (cause); + } + public NotEnoughLettersException(String message, Throwable cause) { + super(message, cause); + } +} From 7c7c24955a4789318304a86fd977cfa0cbef2e5a Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 30 Apr 2017 15:45:25 +0300 Subject: [PATCH 20/62] update board class --- GameEngine/src/engine/Board.java | 59 ++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index 883422f..df43db6 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -43,39 +43,28 @@ private class Cell{ } private short size; - Cell [][] board; - // Map ShownLetters = new HashMap<>(); - Map > initLettrs = new HashMap<>(); + Cell [][] board; // for priting + Map > initLettrs = new HashMap<>(); public Cell [][] getBoard() {return board;} - //test: - public static void main(String [] argv){ - Board b = new Board((short)6); - b.printBoard(b.getBoard()); - System.out.print('\r'); - - } - - //C'tor Board(short _size, List letters, int totalAmountLetters){ int x,y; - Cell toAdd; + Letter toAdd; Point p; - List usedPoints =new ArrayList<>(); this.board = new Cell[_size][_size]; size = _size; //(x,y) point in the board Random xy = new Random(); - //if less or equal amount letters than board - if(totalAmountLetters <= _size * _size) + //if equal amount letters to board size + if(totalAmountLetters == _size * _size) { for(GameDataFromXml.DataLetter letter : letters){ - toAdd =new Cell(letter.getLetter().getSign().get(0), false); + toAdd = letter.getLetter(); List empty = new ArrayList<>(); initLettrs.put(toAdd, empty ); @@ -86,11 +75,34 @@ public static void main(String [] argv){ p = new Point(x,y); } while (initLettrs.containsValue(p)); initLettrs.get(toAdd).add(p); - } + board[y][x] = new Cell(toAdd.getSign().get(0),false); + } } } //more letters than board size else{ + int numOfInsertions = 0; + while (numOfInsertions <= size*size){ + for(int i =0; i< letters.size(); i++){ + GameDataFromXml.DataLetter letter = letters.get(i); + if(numOfInsertions <= size*size){ + toAdd = letter.getLetter(); + List empty = new ArrayList<>(); + initLettrs.put(toAdd, empty ); + do { + x = xy.nextInt(size); + y = xy.nextInt(size); + p = new Point(x,y); + } while (initLettrs.containsValue(p)); + initLettrs.get(toAdd).add(p); + board[y][x] = new Cell(toAdd.getSign().get(0),false); + numOfInsertions ++; + } + + } + + } + } @@ -100,12 +112,20 @@ public static void main(String [] argv){ public void setBoard(Cell[][] board) { this.board = board; } + + + + + + + + //TODO: remove /* public void printLetterInBoard(char sign){ System.out.println(String.format("%-30s","h")); }*/ - +/* public void printBoard(char[][] board) { //התקרה @@ -141,4 +161,5 @@ public void printBoard(char[][] board) } + */ } \ No newline at end of file From 80f4f7364f1790e4192807c2328ddcc617fb8589 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 30 Apr 2017 16:58:02 +0300 Subject: [PATCH 21/62] update board and GameDataFromXml --- GameEngine/src/engine/Board.java | 51 ++++++++++++++-------- GameEngine/src/engine/GameDataFromXml.java | 13 +++--- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index df43db6..bae1630 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -43,6 +43,7 @@ private class Cell{ } private short size; + List kupa = new ArrayList<>(); Cell [][] board; // for priting Map > initLettrs = new HashMap<>(); @@ -69,44 +70,54 @@ private class Cell{ initLettrs.put(toAdd, empty ); for(int i = 0 ; i < letter.getAmount(); i++){ + boolean toContinue = false; do { x = xy.nextInt(size); y = xy.nextInt(size); p = new Point(x,y); - } while (initLettrs.containsValue(p)); + for (List listPoints : initLettrs.values()){ + if (listPoints.contains(p)) + toContinue = true; + } + } while (toContinue); initLettrs.get(toAdd).add(p); board[y][x] = new Cell(toAdd.getSign().get(0),false); + letter.setAmount(letter.getAmount() - 1); } } } - //more letters than board size + //more letters than board size - need for kupa else{ int numOfInsertions = 0; while (numOfInsertions <= size*size){ for(int i =0; i< letters.size(); i++){ GameDataFromXml.DataLetter letter = letters.get(i); if(numOfInsertions <= size*size){ - toAdd = letter.getLetter(); - List empty = new ArrayList<>(); - initLettrs.put(toAdd, empty ); - do { - x = xy.nextInt(size); - y = xy.nextInt(size); - p = new Point(x,y); - } while (initLettrs.containsValue(p)); - initLettrs.get(toAdd).add(p); - board[y][x] = new Cell(toAdd.getSign().get(0),false); - numOfInsertions ++; + if(letter.getAmount()>0){ + toAdd = letter.getLetter(); + List empty = new ArrayList<>(); + initLettrs.put(toAdd, empty ); + do { + x = xy.nextInt(size); + y = xy.nextInt(size); + p = new Point(x,y); + } while (initLettrs.containsValue(p)); + initLettrs.get(toAdd).add(p); + board[y][x] = new Cell(toAdd.getSign().get(0),false); + numOfInsertions ++; + letter.setAmount(letter.getAmount() - 1); + } } - } - } - - + //build the kupa + for(GameDataFromXml.DataLetter letter : letters){ + for(int i =0; i< letter.getAmount(); i++){ + kupa.add(i, letter); + } + } } - } public void setBoard(Cell[][] board) { @@ -119,6 +130,10 @@ public void setBoard(Cell[][] board) { + + + + //TODO: remove /* public void printLetterInBoard(char sign){ diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 86be53f..787fa0f 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -48,7 +48,7 @@ public void setLetter(Letter letter) { List letters = new ArrayList<>(); - public int totalAmountOfLetters = 0; + private int totalAmountOfLetters = 0; private int boardSize; private int numOfCubeWigs; private int numOfTries; @@ -59,7 +59,7 @@ public void setLetter(Letter letter) { private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; // test: - +/* public static void main(String[] argv) { int freqratio = 0; GameDataFromXml g = new GameDataFromXml(); @@ -75,7 +75,7 @@ public static void main(String[] argv) { " Ratio frequency: " + freqratio); } - } + }*/ // get and set funcs: @@ -111,6 +111,9 @@ public String getDictFileName() { return dictFileName; } + public int getTotalAmountOfLetters() { + return totalAmountOfLetters; + } public void initializingDataFromXml(String pathToXml) { GameDescriptor gd; @@ -224,8 +227,8 @@ public boolean isValidBoardSize(int size) throws InvalidInputException { public boolean isAllLettersApperOne() throws InvalidInputException { boolean isMoreThanOnce = false; for (int i = 0; i < this.getLetters().size(); i++) { - Letter l = this.getLetters().get(i); - String c = this.getLetters().get(i).getSign().get(0); + DataLetter l = this.getLetters().get(i); + String c = this.getLetters().get(i).getLetter().getSign().get(0); this.getLetters().remove(i); isMoreThanOnce = this.getLetters().contains(c); this.getLetters().add(i, l); From 246ce7bd6edd05bfe5930eb836fcb249156bf58c Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 16:59:22 +0300 Subject: [PATCH 22/62] update Dictionary and GameEngine --- GameEngine/src/engine/Dictionary.java | 2 -- GameEngine/src/engine/GameEngine.java | 51 +++++++++++++++++++++------ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 81aac3b..5a9b05b 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -2,10 +2,8 @@ import engine.exceptions.DictionaryNotFoundException; -import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.util.HashMap; import java.util.Map; import java.util.Scanner; diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index d83a28e..2f33c65 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -10,7 +10,9 @@ public class GameEngine { // private GameInformation info; - private Player player; + private Player currentPlayer; + private int nextPlayerNumber = 1; + private List players; private List gdfx = new ArrayList<>(); private GameDataFromXml currentGameData; private boolean isGameStarted = false; @@ -54,44 +56,73 @@ public boolean isStarted() { return isGameStarted; } - public void startGame() { + public void startGame() throws BoardSizeException { currentGameData = gdfx.get(0); + players = new ArrayList<>(); + /*for (engine.jaxb.schema.generated.Player p: currentGameData.getPlayers()) { //TODO: add function + players.add(new Player(p.getName().get(0))); + }*/ + currentPlayer = players.get(0); + board = new Board(currentGameData.getBoardSize(), + currentGameData.getLetters(), + currentGameData.getToalAmountOfLetters()); isGameStarted = true; } - public Object getStat() { - return new Integer(1); + public Status getStatus() { + //TODO: uncomment + //return new Status(board.getBoard(), currentPlayer.getName(), currentGameData.getNumOfTries()); + return new Status(new char[4][4], currentPlayer.getName(), currentGameData.getNumOfTries()); } public int getDiceValue() { Random random = new Random(); - diceValue = random.nextInt(currentGameData.getNumOfCubeWigs() - 2) + 2; + diceValue = random.nextInt(currentGameData.getNumOfCubeWigs() - 1) + 2; return diceValue; } - public void updateBoard(List points) { + public boolean updateBoard(List points) { + if (points.size() != diceValue) { + return false; + } + board.update(points); + return true; } - public Object getBoard() { - return new Integer(1); + public char[][] getBoard() { + //TODO: uncomment + //return board.getBoard(); + return new char[4][4]; + } public int getMaxRetries() { - return 1; + return currentGameData.getNumOfTries(); + } public boolean isWordValid(String word, int tries) { if (tries <= currentGameData.getNumOfTries()) { if (true) { //TODO: check in dictionary //TODO: update user + int score = 0; + // TODO: calculate score + currentPlayer.updateScore(word, score); + nextPlayer(); return true; } return false; } + nextPlayer(); return false; //TODO: throw NumOfRetriesException } + private void nextPlayer() { + currentPlayer = players.get(nextPlayerNumber); + nextPlayerNumber = (nextPlayerNumber + 1) & players.size(); + } + public Statistics getStatistics() { - return new Statistics(null, System.currentTimeMillis(), 0, 0); + return new Statistics(null, System.currentTimeMillis(), 0, 0, null, null); } } From 5f114a8584b7b0d65f981c913578d3bb3b7ef574 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 30 Apr 2017 17:08:30 +0300 Subject: [PATCH 23/62] update board and GameDataFromXml --- GameEngine/src/engine/GameDataFromXml.java | 2 +- GameEngine/src/engine/GameEngine.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 787fa0f..9b57ad3 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -87,7 +87,7 @@ public short getTargetDeckSize() { // return ratiofrequencyLetter; // } - public int getBoardSize() { + public short getBoardSize() { return boardSize; } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 2f33c65..c892244 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -65,7 +65,7 @@ public void startGame() throws BoardSizeException { currentPlayer = players.get(0); board = new Board(currentGameData.getBoardSize(), currentGameData.getLetters(), - currentGameData.getToalAmountOfLetters()); + currentGameData.getTotalAmountOfLetters()); isGameStarted = true; } From 0e0f53e87edd8c3de66d570953b8ea33984397f9 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 30 Apr 2017 17:08:30 +0300 Subject: [PATCH 24/62] update board and GameDataFromXml --- GameEngine/src/engine/Board.java | 2 ++ GameEngine/src/engine/GameDataFromXml.java | 4 ++-- GameEngine/src/engine/GameEngine.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index bae1630..bfcbd86 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -125,7 +125,9 @@ public void setBoard(Cell[][] board) { } + public void update(List points) { + } diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 787fa0f..e138834 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -49,7 +49,7 @@ public void setLetter(Letter letter) { List letters = new ArrayList<>(); private int totalAmountOfLetters = 0; - private int boardSize; + private short boardSize; private int numOfCubeWigs; private int numOfTries; private int leftTargetDeckSize; //בקופה @@ -87,7 +87,7 @@ public short getTargetDeckSize() { // return ratiofrequencyLetter; // } - public int getBoardSize() { + public short getBoardSize() { return boardSize; } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 2f33c65..c892244 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -65,7 +65,7 @@ public void startGame() throws BoardSizeException { currentPlayer = players.get(0); board = new Board(currentGameData.getBoardSize(), currentGameData.getLetters(), - currentGameData.getToalAmountOfLetters()); + currentGameData.getTotalAmountOfLetters()); isGameStarted = true; } From 160b74121bc3106b38dee11a93daa84883c67089 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 30 Apr 2017 20:57:05 +0300 Subject: [PATCH 25/62] update files --- GameEngine/src/engine/Board.java | 19 +++++--- GameEngine/src/engine/Dictionary.java | 8 ---- GameEngine/src/engine/GameDataFromXml.java | 45 ++----------------- GameEngine/src/engine/GameEngine.java | 13 +++++- .../OutOfBoardBoandriesException.java | 16 +++++++ 5 files changed, 42 insertions(+), 59 deletions(-) create mode 100644 GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index bfcbd86..7a0416e 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -1,16 +1,12 @@ package engine; -import com.sun.org.apache.xpath.internal.SourceTree; -import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; -import engine.exceptions.BoardSizeException; +import engine.exceptions.OutOfBoardBoandriesException; import engine.jaxb.schema.generated.Letter; import java.util.Random; -import engine.jaxb.*; import java.util.HashMap; import java.util.Map; import java.util.*; -import engine.jaxb.sdf; public class Board { @@ -45,7 +41,7 @@ private class Cell{ private short size; List kupa = new ArrayList<>(); Cell [][] board; // for priting - Map > initLettrs = new HashMap<>(); + Map > initLettrs = new HashMap<>(); //for changes during the game public Cell [][] getBoard() {return board;} @@ -125,8 +121,17 @@ public void setBoard(Cell[][] board) { } - public void update(List points) { + public void update(List points) throws OutOfBoardBoandriesException{ + //check valid point + for(int[] optionalPoints : points){ + if(optionalPoints[0] > size || optionalPoints[0] < 1 || optionalPoints[1] > size || optionalPoints[1] < 1){ + throw new OutOfBoardBoandriesException(); + } + else{ + board[optionalPoints[0]][optionalPoints[1]].isShown = true; + } + } } diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 5a9b05b..bae9057 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -112,14 +112,6 @@ public boolean equals(Object obj) { } - public void calcFrequencyWord(String pathToDictFile){ - - - - - } - - public boolean hasWord(String word) { return words.containsKey(word); } diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index e138834..faf4ae9 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -32,89 +32,51 @@ public class DataLetter{ public Letter getLetter() { return letter; } - public void setAmount(int amount) { this.amount = amount; } - public int getAmount() { return amount; } - public void setLetter(Letter letter) { this.letter = letter; } } List letters = new ArrayList<>(); - private int totalAmountOfLetters = 0; private short boardSize; private int numOfCubeWigs; private int numOfTries; - private int leftTargetDeckSize; //בקופה private String dictFileName; private short totalTargetDeckSize; //כמות אריחים - //private int totalWordsInDict;----> moved to dictionary class private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; - // test: -/* - public static void main(String[] argv) { - int freqratio = 0; - GameDataFromXml g = new GameDataFromXml(); - g.initializingDataFromXml("ABC"); - System.out.println("board size: " + g.getBoardSize()); - System.out.println("num of cubs: " + g.getNumOfCubeWigs()); - for (int i : g.getRatiofrequencyLetter().values()) - System.out.println(i); - - for (int i = 0; i < g.getLetters().size(); i++) { - freqratio = g.getRatiofrequencyLetter().get(g.getLetters().get(i).getSign().get(0)); - System.out.println("letter " + (i + 1) + ": " + g.getLetters().get(i).getSign().get(0) + " frequency: " + g.getFrequencyLetter().get(g.getLetters().get(i).getSign().get(0)) + - " Ratio frequency: " + freqratio); - } - - }*/ - // get and set funcs: public short getTargetDeckSize() { return totalTargetDeckSize; } - - // public Map getRatiofrequencyLetter() { - // return ratiofrequencyLetter; - // } - public short getBoardSize() { return boardSize; } - public int getNumOfCubeWigs() { return numOfCubeWigs; } - public int getNumOfTries() { return numOfTries; } - public List getLetters() { return letters; } - - // public Map getFrequencyLetter() { - // return frequencyLetter; - //} - public String getDictFileName() { return dictFileName; } - public int getTotalAmountOfLetters() { return totalAmountOfLetters; } + public void initializingDataFromXml(String pathToXml) { GameDescriptor gd; InputStream inputStream = null; @@ -201,7 +163,6 @@ public boolean isValidXml(String pathToXml) throws NotXmlFileException { return true; } - // call this func after calling the one above public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) throws WrongPathException { @@ -217,11 +178,11 @@ public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) t } } - public boolean isValidBoardSize(int size) throws InvalidInputException { + public boolean isValidBoardSize(short size) throws BoardSizeException { if ((size >= 5) && (size <= 50)) return true; else - throw new InvalidInputException("BOARD SIZE" + size + " IS OUT OF RANGE!"); + throw new BoardSizeException(size, (short)5, (short) 50); } public boolean isAllLettersApperOne() throws InvalidInputException { diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index c892244..faa0abe 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -35,6 +35,9 @@ public void loadXml(String pathToXml) { gd.isValidBoardSize(gd.getBoardSize()); gd.isValidXml(pathToXml); } + catch (InvalidBoardSizeException e){ + e.getWrongSize(); + } catch(InvalidInputException e){ //TODO: ask ido } @@ -85,8 +88,14 @@ public boolean updateBoard(List points) { if (points.size() != diceValue) { return false; } - board.update(points); - return true; + try { + board.update(points); + return true; + } + catch (OutOfBoardBoandriesException e){ + System.out.println("Some of the points you chose are out of boandries!\n Try again."); + return false; + } } public char[][] getBoard() { diff --git a/GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java b/GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java new file mode 100644 index 0000000..34184b2 --- /dev/null +++ b/GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java @@ -0,0 +1,16 @@ +package engine.exceptions; + + +public class OutOfBoardBoandriesException extends Exception { + + public OutOfBoardBoandriesException() {} + public OutOfBoardBoandriesException(String message) { + super (message); + } + public OutOfBoardBoandriesException(Throwable cause) { + super (cause); + } + public OutOfBoardBoandriesException(String message, Throwable cause) { + super (message, cause); + } +} From 8326b8948c28d6c4c0a6bd09c4d66dedffbb5dad Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 20:58:58 +0300 Subject: [PATCH 26/62] update files --- ConsoleUI/src/consoleui/ConsoleHandler.java | 11 ++++---- ConsoleUI/src/consoleui/ConsoleUI.java | 9 ++++++- GameEngine/src/engine/Board.java | 10 ++++++- GameEngine/src/engine/Dictionary.java | 2 +- GameEngine/src/engine/GameDataFromXml.java | 27 ++++++++++++------- GameEngine/src/engine/GameEngine.java | 27 ++++++------------- GameEngine/src/engine/Status.java | 2 +- .../DictionaryNotFoundException.java | 10 ++++--- 8 files changed, 57 insertions(+), 41 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 1af011a..6bfaf2b 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -33,11 +33,12 @@ static String getXML() { String pathToXml; System.out.println("Please enter the path to the XML file:"); - pathToXml = scanner.nextLine(); - if (!pathToXml.toLowerCase().endsWith(".xml")) { - System.out.println("The path entered is not to a XML file!"); - } - + do { + pathToXml = scanner.nextLine(); + if (!pathToXml.toLowerCase().endsWith(".xml")) { + System.out.println("The path entered is not to a XML file!\nPlease try again:"); + } + } while (!pathToXml.toLowerCase().endsWith(".xml")); return pathToXml; } diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index deffb18..7bade7d 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -4,13 +4,16 @@ import engine.GameEngine; import engine.Statistics; import engine.exceptions.BoardSizeException; +import engine.exceptions.DictionaryNotFoundException; +import engine.exceptions.WrongPathException; public class ConsoleUI { // TODO: fix exceptions - private static GameEngine engine = new GameEngine("D:\\share\\Wordiada\\GameEngine\\src\\resources\\master.xml"); + private static GameEngine engine = new GameEngine(); public static void main(String[] args) { int selectedMenu; while((selectedMenu= ConsoleHandler.showMainMenu()) != 6){ + // TODO: handle unloaded xml when choosing options 3-6 switch (selectedMenu) { case 1: getXml(); @@ -46,6 +49,10 @@ private static void getXml() { try { engine.loadXml(pathToXml); needInput = false; + } catch (WrongPathException e) { + System.out.println("Invalid path to XML file.\n"); + } catch (DictionaryNotFoundException e) { + System.out.println("Unable to use dictionary file\n" + e.getFileName() + "\n"); } catch (Exception e) { System.out.println("Error, " + e.getMessage()); } diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index bfcbd86..39aef34 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -47,7 +47,15 @@ private class Cell{ Cell [][] board; // for priting Map > initLettrs = new HashMap<>(); - public Cell [][] getBoard() {return board;} + public char[][] getBoard() { + char[][] board = new char[size][size]; + for (int row = 0; row < size; row++) { + for (int col = 0; col < size; col++) { + board[row][col] = this.board[row][col].sign.toCharArray()[0]; + } + } + return board; + } //C'tor diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 5a9b05b..c0ac804 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -90,7 +90,7 @@ public boolean equals(Object obj) { try { scanner = new Scanner(new File(pathToDict)); } catch (FileNotFoundException e) { - throw new DictionaryNotFoundException(e.getMessage()); + throw new DictionaryNotFoundException(pathToDict); } String currentWord; diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index e138834..bbc74c8 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -57,6 +57,7 @@ public void setLetter(Letter letter) { private short totalTargetDeckSize; //כמות אריחים //private int totalWordsInDict;----> moved to dictionary class private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; + private Board board; // test: /* @@ -115,17 +116,16 @@ public int getTotalAmountOfLetters() { return totalAmountOfLetters; } - public void initializingDataFromXml(String pathToXml) { + public void initializingDataFromXml(String pathToXml) throws WrongPathException { GameDescriptor gd; InputStream inputStream = null; - // TODO: delete note after tests - /* + try { inputStream = new FileInputStream(pathToXml); } catch (FileNotFoundException e) { - e.printStackTrace(); - }*/ - inputStream = GameDataFromXml.class.getResourceAsStream("/resources/master.xml"); + throw new WrongPathException(); + } + //inputStream = GameDataFromXml.class.getResourceAsStream("/resources/master.xml"); Structure struct; try { @@ -142,7 +142,7 @@ public void initializingDataFromXml(String pathToXml) { for(int i = 0; i < letters.size(); i++){ double freq = letters.get(i).getLetter().getFrequency(); - letters.get(i).setAmount((int) ((Math.ceil(freq / 100 )) * totalFreq)); + letters.get(i).setAmount((int) Math.ceil(Math.ceil(freq / totalFreq * 100 ) / 100 * struct.getLetters().getTargetDeckSize())); totalAmountOfLetters += letters.get(i).amount; } @@ -157,12 +157,21 @@ public void initializingDataFromXml(String pathToXml) { //init targer deck size this.totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי + board = new Board(boardSize, letters, totalAmountOfLetters); } catch (JAXBException e) { e.printStackTrace(); } } + public Board getBoard() { + return board; + } + + public void updateBoard(List points) { + board.update(points); + } + // NO NEED: // calc functions: @@ -204,7 +213,7 @@ public boolean isValidXml(String pathToXml) throws NotXmlFileException { // call this func after calling the one above - public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) throws WrongPathException { + public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) throws DictionaryNotFoundException { pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" while (!pathToXml.endsWith("\\")) { @@ -213,7 +222,7 @@ public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) t if (pathToDictFile == pathToXml + "dictionary\\" + this.getDictFileName() + ".txt") return true; else { - throw new WrongPathException("THE PATH: " + pathToDictFile + " IS NOT THE VALID PATH TO DICTIONARY FILE!"); + throw new DictionaryNotFoundException("THE PATH: " + pathToDictFile + " IS NOT THE VALID PATH TO DICTIONARY FILE!"); } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index c892244..cef38dd 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -17,15 +17,8 @@ public class GameEngine { private GameDataFromXml currentGameData; private boolean isGameStarted = false; private int diceValue; - private Board board; - //Cto'r - GameEngine(String pathToXml){ - - //TODO: check with ido if there is a need for ctor - } - - public void loadXml(String pathToXml) { + public void loadXml(String pathToXml) throws WrongPathException, DictionaryNotFoundException { GameDataFromXml gd = new GameDataFromXml(); gd.initializingDataFromXml(pathToXml); //check validation: @@ -36,10 +29,7 @@ public void loadXml(String pathToXml) { gd.isValidXml(pathToXml); } catch(InvalidInputException e){ - //TODO: ask ido - } - catch(WrongPathException e){ - //TODO: ask ido + throw new DictionaryNotFoundException(gd.getDictFileName()); } catch(NotXmlFileException e){ //TODO: ask ido @@ -63,16 +53,15 @@ public void startGame() throws BoardSizeException { players.add(new Player(p.getName().get(0))); }*/ currentPlayer = players.get(0); - board = new Board(currentGameData.getBoardSize(), - currentGameData.getLetters(), - currentGameData.getTotalAmountOfLetters()); isGameStarted = true; } public Status getStatus() { - //TODO: uncomment - //return new Status(board.getBoard(), currentPlayer.getName(), currentGameData.getNumOfTries()); - return new Status(new char[4][4], currentPlayer.getName(), currentGameData.getNumOfTries()); + return new Status( + currentGameData.getBoard().getBoard(), + currentPlayer != null ? currentPlayer.getName() : null, + currentGameData.getNumOfTries()); + //return new Status(new char[4][4], currentPlayer.getName(), currentGameData.getNumOfTries()); } public int getDiceValue() { @@ -85,7 +74,7 @@ public boolean updateBoard(List points) { if (points.size() != diceValue) { return false; } - board.update(points); + currentGameData.updateBoard(points); return true; } diff --git a/GameEngine/src/engine/Status.java b/GameEngine/src/engine/Status.java index 8b3cd6c..eeb312c 100644 --- a/GameEngine/src/engine/Status.java +++ b/GameEngine/src/engine/Status.java @@ -16,7 +16,7 @@ public int getLeftTiles() { } public String getPlayerName() { - return playerName; + return playerName != null ? playerName : ""; } public char[][] getBoard() { diff --git a/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java index 4d38982..42c5cfa 100644 --- a/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java +++ b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java @@ -3,12 +3,14 @@ import java.io.FileNotFoundException; public class DictionaryNotFoundException extends FileNotFoundException { + String fileName; - public DictionaryNotFoundException () { - super(); + public DictionaryNotFoundException (String fileName) { + super (); + fileName = fileName; } - public DictionaryNotFoundException (String message) { - super (message); + public String getFileName() { + return fileName; } } From bc747980e392004532e45f28d8f682bcbe675e06 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 21:15:00 +0300 Subject: [PATCH 27/62] fix problems --- GameEngine/src/engine/Board.java | 6 +++--- GameEngine/src/engine/GameDataFromXml.java | 3 +-- GameEngine/src/engine/GameEngine.java | 21 +++++++------------ .../OutOfBoardBoandriesException.java | 16 -------------- .../OutOfBoardBoundariesException.java | 16 ++++++++++++++ 5 files changed, 28 insertions(+), 34 deletions(-) delete mode 100644 GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java create mode 100644 GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index 6afbd9c..bff69df 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -1,6 +1,6 @@ package engine; -import engine.exceptions.OutOfBoardBoandriesException; +import engine.exceptions.OutOfBoardBoundariesException; import engine.jaxb.schema.generated.Letter; import java.util.Random; @@ -129,12 +129,12 @@ public void setBoard(Cell[][] board) { } - public void update(List points) throws OutOfBoardBoandriesException{ + public void update(List points) throws OutOfBoardBoundariesException { //check valid point for(int[] optionalPoints : points){ if(optionalPoints[0] > size || optionalPoints[0] < 1 || optionalPoints[1] > size || optionalPoints[1] < 1){ - throw new OutOfBoardBoandriesException(); + throw new OutOfBoardBoundariesException(); } else{ board[optionalPoints[0]][optionalPoints[1]].isShown = true; diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 70ede57..1d2b5f6 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -12,7 +12,6 @@ import engine.jaxb.schema.generated.GameDescriptor; import engine.jaxb.schema.generated.Letter; -import engine.jaxb.schema.generated.Letters; import engine.jaxb.schema.generated.Structure; import javax.xml.bind.JAXBContext; @@ -129,7 +128,7 @@ public Board getBoard() { return board; } - public void updateBoard(List points) { + public void updateBoard(List points) throws OutOfBoardBoundariesException { board.update(points); } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 0f29c14..79d115f 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -18,25 +18,20 @@ public class GameEngine { private boolean isGameStarted = false; private int diceValue; - public void loadXml(String pathToXml) throws WrongPathException, DictionaryNotFoundException { + public void loadXml(String pathToXml) + throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException { GameDataFromXml gd = new GameDataFromXml(); gd.initializingDataFromXml(pathToXml); //check validation: + gd.isValidXml(pathToXml); + gd.isDictionaryInRightPos(gd.getDictFileName(), pathToXml); + gd.isValidBoardSize(gd.getBoardSize()); try{ gd.isAllLettersApperOne(); - gd.isDictionaryInRightPos(gd.getDictFileName(), pathToXml); - gd.isValidBoardSize(gd.getBoardSize()); - gd.isValidXml(pathToXml); - } - catch (InvalidBoardSizeException e){ - e.getWrongSize(); } catch(InvalidInputException e){ throw new DictionaryNotFoundException(gd.getDictFileName()); } - catch(NotXmlFileException e){ - //TODO: ask ido - } gdfx.add(gd); } @@ -78,12 +73,12 @@ public boolean updateBoard(List points) { return false; } try { - board.update(points); + currentGameData.updateBoard(points); return true; } - catch (OutOfBoardBoandriesException e){ + catch (OutOfBoardBoundariesException e){ System.out.println("Some of the points you chose are out of boandries!\n Try again."); - return false; + return false; } } diff --git a/GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java b/GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java deleted file mode 100644 index 34184b2..0000000 --- a/GameEngine/src/engine/exceptions/OutOfBoardBoandriesException.java +++ /dev/null @@ -1,16 +0,0 @@ -package engine.exceptions; - - -public class OutOfBoardBoandriesException extends Exception { - - public OutOfBoardBoandriesException() {} - public OutOfBoardBoandriesException(String message) { - super (message); - } - public OutOfBoardBoandriesException(Throwable cause) { - super (cause); - } - public OutOfBoardBoandriesException(String message, Throwable cause) { - super (message, cause); - } -} diff --git a/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java b/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java new file mode 100644 index 0000000..2357760 --- /dev/null +++ b/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java @@ -0,0 +1,16 @@ +package engine.exceptions; + + +public class OutOfBoardBoundariesException extends Exception { + + public OutOfBoardBoundariesException() {} + public OutOfBoardBoundariesException(String message) { + super (message); + } + public OutOfBoardBoundariesException(Throwable cause) { + super (cause); + } + public OutOfBoardBoundariesException(String message, Throwable cause) { + super (message, cause); + } +} From 9c4652bfd1344be2ec4162184a887058f00de364 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Sun, 30 Apr 2017 22:33:52 +0300 Subject: [PATCH 28/62] gameDataToXml - solve bugs --- GameEngine/src/engine/GameDataFromXml.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 1d2b5f6..dc230c0 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -198,7 +198,10 @@ public boolean isAllLettersApperOne() throws InvalidInputException { DataLetter l = this.getLetters().get(i); String c = this.getLetters().get(i).getLetter().getSign().get(0); this.getLetters().remove(i); - isMoreThanOnce = this.getLetters().contains(c); + for(DataLetter toCompare : this.getLetters()){ + if(toCompare.getLetter().getSign().get(0) == c) + isMoreThanOnce = true; + } this.getLetters().add(i, l); //appears more than once if (isMoreThanOnce) From e36e2efd2edf3ddcc1406001c796cfd7a7097cb4 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Sun, 30 Apr 2017 22:41:32 +0300 Subject: [PATCH 29/62] fix run bugs --- ConsoleUI/src/consoleui/ConsoleHandler.java | 8 +------ ConsoleUI/src/consoleui/ConsoleUI.java | 3 +++ GameEngine/src/engine/Board.java | 2 +- GameEngine/src/engine/Dictionary.java | 22 ------------------- GameEngine/src/engine/GameDataFromXml.java | 13 ++++++----- GameEngine/src/engine/GameEngine.java | 8 ++++++- .../DictionaryNotFoundException.java | 4 ++-- 7 files changed, 21 insertions(+), 39 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 6bfaf2b..7746ed6 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -33,13 +33,7 @@ static String getXML() { String pathToXml; System.out.println("Please enter the path to the XML file:"); - do { - pathToXml = scanner.nextLine(); - if (!pathToXml.toLowerCase().endsWith(".xml")) { - System.out.println("The path entered is not to a XML file!\nPlease try again:"); - } - } while (!pathToXml.toLowerCase().endsWith(".xml")); - return pathToXml; + return scanner.nextLine(); } static void showGameStatus(Status status, boolean needFullPrint) { diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 7bade7d..175ec1d 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -5,6 +5,7 @@ import engine.Statistics; import engine.exceptions.BoardSizeException; import engine.exceptions.DictionaryNotFoundException; +import engine.exceptions.NotXmlFileException; import engine.exceptions.WrongPathException; public class ConsoleUI { @@ -53,6 +54,8 @@ private static void getXml() { System.out.println("Invalid path to XML file.\n"); } catch (DictionaryNotFoundException e) { System.out.println("Unable to use dictionary file\n" + e.getFileName() + "\n"); + } catch (NotXmlFileException e) { + System.out.println("The file " + pathToXml + " is not a valid XML.\n"); } catch (Exception e) { System.out.println("Error, " + e.getMessage()); } diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index bff69df..ea15a49 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -47,7 +47,7 @@ public char[][] getBoard() { char[][] board = new char[size][size]; for (int row = 0; row < size; row++) { for (int col = 0; col < size; col++) { - board[row][col] = this.board[row][col].sign.toCharArray()[0]; + board[row][col] = this.board[row][col].isShown ? this.board[row][col].sign.toCharArray()[0] : ' '; } } return board; diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 6eb30f5..4c1a458 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -9,28 +9,6 @@ import java.util.Scanner; public class Dictionary { - /* TODO: remove - public static void main(String[] args) { - Dictionary dic; - try { - dic = new Dictionary("C:\\Users\\Ido\\Downloads\\war and piece.txt"); - } catch (DictionaryNotFoundException e) { - System.out.println("Dictionary not found..."); - return; - } - - Map words = dic.getWords(); - long totalWords = dic.getNumberOfWords(), myCount = 0; - for (String word: words.keySet()) { - Word word1 = words.get(word); - long count = word1.getCount(); - myCount += count; - System.out.println(word + ": " + count + ", " + word1.getFrequency()); - } - System.out.println("Total: " + totalWords + "\nMy count: " + myCount); - } - */ - private long numberOfWords = 0; private Map words = new HashMap<>(); diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 1d2b5f6..e44e50e 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -27,6 +27,7 @@ public class DataLetter{ DataLetter(Letter l){ letter = l; + amount = 0; } public Letter getLetter() { return letter; @@ -162,9 +163,7 @@ private static GameDescriptor deserializeFrom(InputStream in) throws JAXBExcepti // check Validation functions: public boolean isValidXml(String pathToXml) throws NotXmlFileException { - - String extension = pathToXml.substring(pathToXml.lastIndexOf(".") + 1, pathToXml.length()); - if ((extension != "xml") || (extension != ".xml")) { + if (!pathToXml.toLowerCase().endsWith(".xml")) { throw new NotXmlFileException("ITS NOT XML FILE!"); } else return true; @@ -172,16 +171,18 @@ public boolean isValidXml(String pathToXml) throws NotXmlFileException { // call this func after calling the one above - public boolean isDictionaryInRightPos(String pathToDictFile, String pathToXml) throws DictionaryNotFoundException { + public boolean isDictionaryInRightPos(String pathToXml) throws DictionaryNotFoundException { pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" while (!pathToXml.endsWith("\\")) { pathToXml = pathToXml.substring(0, pathToXml.length() - 1); } - if (pathToDictFile == pathToXml + "dictionary\\" + this.getDictFileName() + ".txt") + String pathToDict = pathToXml + "dictionary\\" + dictFileName; + File f = new File(pathToDict); + if (f.exists() && f.isFile()) return true; else { - throw new DictionaryNotFoundException("THE PATH: " + pathToDictFile + " IS NOT THE VALID PATH TO DICTIONARY FILE!"); + throw new DictionaryNotFoundException(pathToDict); } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 79d115f..63593d2 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -24,7 +24,7 @@ public void loadXml(String pathToXml) gd.initializingDataFromXml(pathToXml); //check validation: gd.isValidXml(pathToXml); - gd.isDictionaryInRightPos(gd.getDictFileName(), pathToXml); + gd.isDictionaryInRightPos(pathToXml); gd.isValidBoardSize(gd.getBoardSize()); try{ gd.isAllLettersApperOne(); @@ -55,6 +55,12 @@ public void startGame() throws BoardSizeException { } public Status getStatus() { + if (currentGameData == null) { + GameDataFromXml gd = gdfx.get(gdfx.size() - 1); + return new Status(gd.getBoard().getBoard(), + currentPlayer != null ? currentPlayer.getName() : null, + gd.getNumOfTries()); + } return new Status( currentGameData.getBoard().getBoard(), currentPlayer != null ? currentPlayer.getName() : null, diff --git a/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java index 42c5cfa..e6b6ce3 100644 --- a/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java +++ b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java @@ -3,11 +3,11 @@ import java.io.FileNotFoundException; public class DictionaryNotFoundException extends FileNotFoundException { - String fileName; + private String fileName; public DictionaryNotFoundException (String fileName) { super (); - fileName = fileName; + this.fileName = fileName; } public String getFileName() { From f363e483be4eb43e13e2379507eaaf3531e54e6d Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 01:09:25 +0300 Subject: [PATCH 30/62] fix run bugs --- ConsoleUI/src/consoleui/ConsoleUI.java | 7 +++---- GameEngine/src/engine/Board.java | 7 ++++++- GameEngine/src/engine/GameDataFromXml.java | 4 ++-- GameEngine/src/engine/GameEngine.java | 9 ++------- .../exceptions/DuplicateLetterException.java | 17 +++++++++++++++++ .../exceptions/InvalidInputException.java | 19 ------------------- 6 files changed, 30 insertions(+), 33 deletions(-) create mode 100644 GameEngine/src/engine/exceptions/DuplicateLetterException.java delete mode 100644 GameEngine/src/engine/exceptions/InvalidInputException.java diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 175ec1d..bd8417d 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -3,10 +3,7 @@ import java.util.List; import engine.GameEngine; import engine.Statistics; -import engine.exceptions.BoardSizeException; -import engine.exceptions.DictionaryNotFoundException; -import engine.exceptions.NotXmlFileException; -import engine.exceptions.WrongPathException; +import engine.exceptions.*; public class ConsoleUI { // TODO: fix exceptions @@ -56,6 +53,8 @@ private static void getXml() { System.out.println("Unable to use dictionary file\n" + e.getFileName() + "\n"); } catch (NotXmlFileException e) { System.out.println("The file " + pathToXml + " is not a valid XML.\n"); + } catch (DuplicateLetterException e) { + System.out.println("The letter " + e.getLetter() + " appears more than once.\n"); } catch (Exception e) { System.out.println("Error, " + e.getMessage()); } diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index ea15a49..49ee1c3 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -98,6 +98,7 @@ public char[][] getBoard() { GameDataFromXml.DataLetter letter = letters.get(i); if(numOfInsertions <= size*size){ if(letter.getAmount()>0){ + boolean toContinue = false; toAdd = letter.getLetter(); List empty = new ArrayList<>(); initLettrs.put(toAdd, empty ); @@ -105,7 +106,11 @@ public char[][] getBoard() { x = xy.nextInt(size); y = xy.nextInt(size); p = new Point(x,y); - } while (initLettrs.containsValue(p)); + for (List listPoints : initLettrs.values()){ + if (listPoints.contains(p)) + toContinue = true; + } + } while (toContinue); initLettrs.get(toAdd).add(p); board[y][x] = new Cell(toAdd.getSign().get(0),false); numOfInsertions ++; diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 8ad9fa1..5184d36 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -193,7 +193,7 @@ public boolean isValidBoardSize(short size) throws BoardSizeException { throw new BoardSizeException(size, (short)5, (short) 50); } - public boolean isAllLettersApperOne() throws InvalidInputException { + public boolean isAllLettersAppearOnce() throws DuplicateLetterException { boolean isMoreThanOnce = false; for (int i = 0; i < this.getLetters().size(); i++) { DataLetter l = this.getLetters().get(i); @@ -206,7 +206,7 @@ public boolean isAllLettersApperOne() throws InvalidInputException { this.getLetters().add(i, l); //appears more than once if (isMoreThanOnce) - throw new InvalidInputException("THE SIGN: " + c + "APPEARS MORE THAN ONCE!"); + throw new DuplicateLetterException("THE SIGN: " + c + "APPEARS MORE THAN ONCE!"); } return true; } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 63593d2..c49b30a 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -19,19 +19,14 @@ public class GameEngine { private int diceValue; public void loadXml(String pathToXml) - throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException { + throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException, DuplicateLetterException { GameDataFromXml gd = new GameDataFromXml(); gd.initializingDataFromXml(pathToXml); //check validation: gd.isValidXml(pathToXml); gd.isDictionaryInRightPos(pathToXml); gd.isValidBoardSize(gd.getBoardSize()); - try{ - gd.isAllLettersApperOne(); - } - catch(InvalidInputException e){ - throw new DictionaryNotFoundException(gd.getDictFileName()); - } + gd.isAllLettersAppearOnce(); gdfx.add(gd); } diff --git a/GameEngine/src/engine/exceptions/DuplicateLetterException.java b/GameEngine/src/engine/exceptions/DuplicateLetterException.java new file mode 100644 index 0000000..d6d4d3d --- /dev/null +++ b/GameEngine/src/engine/exceptions/DuplicateLetterException.java @@ -0,0 +1,17 @@ +package engine.exceptions; + +/** + * Created by נוי on 24/04/2017. + */ +public class DuplicateLetterException extends Exception { + String letter; + + public DuplicateLetterException(String letter) { + super (); + this.letter = letter; + } + + public String getLetter() { + return letter; + } +} diff --git a/GameEngine/src/engine/exceptions/InvalidInputException.java b/GameEngine/src/engine/exceptions/InvalidInputException.java deleted file mode 100644 index b9e55a0..0000000 --- a/GameEngine/src/engine/exceptions/InvalidInputException.java +++ /dev/null @@ -1,19 +0,0 @@ -package engine.exceptions; - -/** - * Created by נוי on 24/04/2017. - */ -public class InvalidInputException extends Exception { - - public InvalidInputException () {} - public InvalidInputException (String message) { - super (message); - } - public InvalidInputException (Throwable cause) { - super (cause); - } - public InvalidInputException (String message, Throwable cause) { - super (message, cause); - } - -} From daa0aa9c42ce8c7a0b13639e81af768a690be36b Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 03:06:53 +0300 Subject: [PATCH 31/62] fix board creation --- GameEngine/src/engine/Board.java | 52 ++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index 49ee1c3..3c64226 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -26,6 +26,29 @@ public int getX() { public int getY() { return y; } + + @Override + public int hashCode() { + int hash = 17; + hash = 13 * hash + x + y; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj == this){ + return true; + } + if (!(obj instanceof Point)) { + return false; + } + + final Point other = (Point) obj; + return this.x == other.x && this.y == other.y; + } } private class Cell{ boolean isShown; @@ -39,9 +62,11 @@ private class Cell{ } private short size; - List kupa = new ArrayList<>(); - Cell [][] board; // for priting - Map > initLettrs = new HashMap<>(); //for changes during the game + private List kupa = new ArrayList<>(); + private Cell [][] board; // for priting + private Map > initLettrs = new HashMap<>(); //for changes during the game + static final short MAX_SIZE = 50; + static final short MIN_SIZE = 5; public char[][] getBoard() { char[][] board = new char[size][size]; @@ -70,12 +95,13 @@ public char[][] getBoard() { { for(GameDataFromXml.DataLetter letter : letters){ toAdd = letter.getLetter(); - List empty = new ArrayList<>(); - initLettrs.put(toAdd, empty ); - + if (!initLettrs.containsKey(toAdd)) { + initLettrs.put(toAdd, new ArrayList<>()); + } for(int i = 0 ; i < letter.getAmount(); i++){ - boolean toContinue = false; + boolean toContinue; do { + toContinue = false; x = xy.nextInt(size); y = xy.nextInt(size); p = new Point(x,y); @@ -93,16 +119,18 @@ public char[][] getBoard() { //more letters than board size - need for kupa else{ int numOfInsertions = 0; - while (numOfInsertions <= size*size){ + while (numOfInsertions < size*size){ for(int i =0; i< letters.size(); i++){ GameDataFromXml.DataLetter letter = letters.get(i); - if(numOfInsertions <= size*size){ + if(numOfInsertions < size*size){ if(letter.getAmount()>0){ - boolean toContinue = false; + boolean toContinue; toAdd = letter.getLetter(); - List empty = new ArrayList<>(); - initLettrs.put(toAdd, empty ); + if (!initLettrs.containsKey(toAdd)) { + initLettrs.put(toAdd, new ArrayList<>()); + } do { + toContinue = false; x = xy.nextInt(size); y = xy.nextInt(size); p = new Point(x,y); From bc2b30dc6ec75c2a828936b76c762a5a9f68bda2 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 03:08:30 +0300 Subject: [PATCH 32/62] add more exceptions --- .../exceptions/NotValidXmlFileException.java | 7 ++++++ .../exceptions/NumberOfPlayersException.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 GameEngine/src/engine/exceptions/NotValidXmlFileException.java create mode 100644 GameEngine/src/engine/exceptions/NumberOfPlayersException.java diff --git a/GameEngine/src/engine/exceptions/NotValidXmlFileException.java b/GameEngine/src/engine/exceptions/NotValidXmlFileException.java new file mode 100644 index 0000000..873b622 --- /dev/null +++ b/GameEngine/src/engine/exceptions/NotValidXmlFileException.java @@ -0,0 +1,7 @@ +package engine.exceptions; + +public class NotValidXmlFileException extends Exception{ + public NotValidXmlFileException() { + super(); + } +} diff --git a/GameEngine/src/engine/exceptions/NumberOfPlayersException.java b/GameEngine/src/engine/exceptions/NumberOfPlayersException.java new file mode 100644 index 0000000..4c58f66 --- /dev/null +++ b/GameEngine/src/engine/exceptions/NumberOfPlayersException.java @@ -0,0 +1,24 @@ +package engine.exceptions; + +public class NumberOfPlayersException extends Exception{ + private int actualNumOfPlayers; + private short minPlayers, maxPlayers; + + public NumberOfPlayersException(int numOfPlayers, short minPlayers, short maxPlayers) { + actualNumOfPlayers = numOfPlayers; + this.minPlayers = minPlayers; + this.maxPlayers = maxPlayers; + } + + public int getActualNumOfPlayers() { + return actualNumOfPlayers; + } + + public short getMinPlayers() { + return minPlayers; + } + + public short getMaxPlayers() { + return maxPlayers; + } +} From 45aeb43ed01e3f5d646c3c2b1acb44ea259783f2 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 03:10:12 +0300 Subject: [PATCH 33/62] fix board print after the change to StringBuilder --- ConsoleUI/src/consoleui/ConsoleHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 7746ed6..079e1f1 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -66,7 +66,7 @@ static void printBoard(char[][] board) { System.out.println(boarderLine); // print board for (row = 0; row < numOfRows; row++) { - line.append(numOfRows > 9 && row < 9 ? " " : ""); + line = new StringBuilder(numOfRows > 9 && row < 9 ? " " : ""); tmpStr = (row + 1) + "|"; line.append(tmpStr); for (col = 0; col < numOfCols; col++) { @@ -91,7 +91,7 @@ private static void boardIndices(int numOfCols, int numOfRows) { } System.out.println(line); } - line.append(lineStart); + line = new StringBuilder(lineStart); for (col = 0; col < numOfCols; col++) { tmpStr = (col + 1) % 10 + "|"; line.append(tmpStr); From 8a0b85ae2ef065bc5dbf590e7a980fe1da808598 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 03:11:15 +0300 Subject: [PATCH 34/62] add number of players restrictions as static finals to the class --- GameEngine/src/engine/Player.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GameEngine/src/engine/Player.java b/GameEngine/src/engine/Player.java index 7ec5d4c..72bba5c 100644 --- a/GameEngine/src/engine/Player.java +++ b/GameEngine/src/engine/Player.java @@ -7,6 +7,8 @@ public class Player { private String name; private float score; private List words; + static final short MAX_PLAYERS = 6; + static final short MIN_PLAYERS = 2; public Player(String name) { this.name = name; From 6e1a9f445c5fedb26d04cb5bca9f372207c3485f Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 03:15:24 +0300 Subject: [PATCH 35/62] fix exception throwing and add function to get the players --- GameEngine/src/engine/GameDataFromXml.java | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 5184d36..644758d 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -10,9 +10,8 @@ import engine.exceptions.*; -import engine.jaxb.schema.generated.GameDescriptor; -import engine.jaxb.schema.generated.Letter; -import engine.jaxb.schema.generated.Structure; +import engine.jaxb.schema.generated.*; +import engine.jaxb.schema.generated.Player; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -52,6 +51,7 @@ public void setLetter(Letter letter) { private short totalTargetDeckSize; //כמות אריחים private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; private Board board; + private Players players; // get and set funcs: @@ -77,7 +77,7 @@ public int getTotalAmountOfLetters() { return totalAmountOfLetters; } - public void initializingDataFromXml(String pathToXml) throws WrongPathException { + public void initializingDataFromXml(String pathToXml) throws WrongPathException, NotValidXmlFileException { GameDescriptor gd; InputStream inputStream = null; @@ -119,9 +119,10 @@ public void initializingDataFromXml(String pathToXml) throws WrongPathException this.totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי board = new Board(boardSize, letters, totalAmountOfLetters); + players = gd.getPlayers(); } catch (JAXBException e) { - e.printStackTrace(); + throw new NotValidXmlFileException(); } } @@ -133,6 +134,14 @@ public void updateBoard(List points) throws OutOfBoardBoundariesException board.update(points); } + public List getPlayers() throws NumberOfPlayersException{ + List players = this.players.getPlayer(); + if (players.size() != 2) { + throw new NumberOfPlayersException(players.size(), engine.Player.MIN_PLAYERS, engine.Player.MAX_PLAYERS); + } + return players; + } + // NO NEED: // calc functions: @@ -187,10 +196,10 @@ public boolean isDictionaryInRightPos(String pathToXml) throws DictionaryNotFoun } public boolean isValidBoardSize(short size) throws BoardSizeException { - if ((size >= 5) && (size <= 50)) + if ((size >= Board.MIN_SIZE) && (size <= Board.MAX_SIZE)) return true; else - throw new BoardSizeException(size, (short)5, (short) 50); + throw new BoardSizeException(size, Board.MIN_SIZE, Board.MAX_SIZE); } public boolean isAllLettersAppearOnce() throws DuplicateLetterException { From 41347445ca76cdf1120b74c090a46d2517e9a5f3 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 03:17:11 +0300 Subject: [PATCH 36/62] fix exceptions and functions --- GameEngine/src/engine/GameEngine.java | 29 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index c49b30a..393c688 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -17,9 +17,12 @@ public class GameEngine { private GameDataFromXml currentGameData; private boolean isGameStarted = false; private int diceValue; + private long startTime; + private int numberOfTurns = 0; public void loadXml(String pathToXml) - throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException, DuplicateLetterException { + throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException, + DuplicateLetterException, NotValidXmlFileException { GameDataFromXml gd = new GameDataFromXml(); gd.initializingDataFromXml(pathToXml); //check validation: @@ -39,28 +42,31 @@ public boolean isStarted() { return isGameStarted; } - public void startGame() throws BoardSizeException { + public void startGame() throws NumberOfPlayersException { currentGameData = gdfx.get(0); players = new ArrayList<>(); - /*for (engine.jaxb.schema.generated.Player p: currentGameData.getPlayers()) { //TODO: add function + for (engine.jaxb.schema.generated.Player p: currentGameData.getPlayers()) { //TODO: add function players.add(new Player(p.getName().get(0))); - }*/ + } currentPlayer = players.get(0); isGameStarted = true; + startTime = System.currentTimeMillis(); } public Status getStatus() { if (currentGameData == null) { GameDataFromXml gd = gdfx.get(gdfx.size() - 1); - return new Status(gd.getBoard().getBoard(), + return new Status( + gd.getBoard().getBoard(), currentPlayer != null ? currentPlayer.getName() : null, - gd.getNumOfTries()); + gd.getNumOfTries() + ); } return new Status( currentGameData.getBoard().getBoard(), currentPlayer != null ? currentPlayer.getName() : null, - currentGameData.getNumOfTries()); - //return new Status(new char[4][4], currentPlayer.getName(), currentGameData.getNumOfTries()); + currentGameData.getNumOfTries() + ); } public int getDiceValue() { @@ -84,9 +90,7 @@ public boolean updateBoard(List points) { } public char[][] getBoard() { - //TODO: uncomment - //return board.getBoard(); - return new char[4][4]; + return currentGameData.getBoard().getBoard(); } @@ -114,9 +118,10 @@ public boolean isWordValid(String word, int tries) { private void nextPlayer() { currentPlayer = players.get(nextPlayerNumber); nextPlayerNumber = (nextPlayerNumber + 1) & players.size(); + numberOfTurns++; } public Statistics getStatistics() { - return new Statistics(null, System.currentTimeMillis(), 0, 0, null, null); + return new Statistics(players, System.currentTimeMillis() - startTime, numberOfTurns, 0, currentGameData, null); } } From d21722dcbedb6e9568a1b5b2d34a5f55d2d85d13 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 03:17:39 +0300 Subject: [PATCH 37/62] add and fix exceptions handling --- ConsoleUI/src/consoleui/ConsoleUI.java | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index bd8417d..d7d0e93 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -49,36 +49,43 @@ private static void getXml() { needInput = false; } catch (WrongPathException e) { System.out.println("Invalid path to XML file.\n"); - } catch (DictionaryNotFoundException e) { - System.out.println("Unable to use dictionary file\n" + e.getFileName() + "\n"); } catch (NotXmlFileException e) { - System.out.println("The file " + pathToXml + " is not a valid XML.\n"); + System.out.println("The file \"" + pathToXml + "\" is not an XML file.\n"); + } catch (DictionaryNotFoundException e) { + System.out.println("Unable to use dictionary file \"" + e.getFileName() + "\"\n"); } catch (DuplicateLetterException e) { System.out.println("The letter " + e.getLetter() + " appears more than once.\n"); + } catch (BoardSizeException e) { + System.out.println("XML not valid!"); + System.out.println("Expected size is between " + e.getMinSize() + " to " + e.getMaxSize()); + System.out.println("Got: " + e.getSize()); + } catch (NotValidXmlFileException e) { + System.out.println("The XML file \"" + pathToXml +"\"\n" + + "does not contains the information for Wordiada game.\n"); } catch (Exception e) { System.out.println("Error, " + e.getMessage()); } } ConsoleHandler.showGameStatus(engine.getStatus(), false); - System.out.println("XML file " + pathToXml + " loaded successfully!"); + System.out.println("XML file \"" + pathToXml + "\" loaded successfully!\n"); } private static void startGame(){ if (!engine.isXmlLoaded()) { System.out.println("No xml game file was loaded.\n" + - "Please select 1 first to load at least one xml file."); + "Please select 1 first to load at least one xml file.\n"); } else if (engine.isStarted()) { System.out.println("The game was already started...\n" + - "Please DON'T use this option again."); + "Please DON'T use this option again.\n"); } else { try { engine.startGame(); - } catch (BoardSizeException e) { - System.out.println("XML not valid!"); - System.out.println("Expected size is between " + e.getMinSize() + " to " + e.getMaxSize()); - System.out.println("Got: " + e.getSize()); + } catch (NumberOfPlayersException e) { + System.out.println("The number of players is incorrect.\n" + + "The minimum is " + e.getMinPlayers() + ", the maximum is " + e.getMaxPlayers() + + ", but got " + e.getActualNumOfPlayers() + " players.\n"); } } } From 897e220cc9a0302f2c02265781f3344d45ce51d0 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Mon, 1 May 2017 12:38:43 +0300 Subject: [PATCH 38/62] solve 7 7 point in board --- GameEngine/src/engine/Board.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index 3c64226..e9fca89 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -165,12 +165,15 @@ public void setBoard(Cell[][] board) { public void update(List points) throws OutOfBoardBoundariesException { //check valid point - for(int[] optionalPoints : points){ - if(optionalPoints[0] > size || optionalPoints[0] < 1 || optionalPoints[1] > size || optionalPoints[1] < 1){ + + for(int i = 0; i < points.size(); i++){ + Point point = new Point((points.get(i))[1], (points.get(i))[0]); + + if(point.getX() > size || point.getX() < 1 || point.getY() > size || point.getY() < 1){ throw new OutOfBoardBoundariesException(); } else{ - board[optionalPoints[0]][optionalPoints[1]].isShown = true; + board[point.getY()-1][point.getX()-1].isShown = true; } } } From b0d5dbdddecfb1a7947e12d9c77c6df122a99e1d Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 12:48:09 +0300 Subject: [PATCH 39/62] fix functions and use enum for word check as returned value --- ConsoleUI/src/consoleui/ConsoleHandler.java | 15 +++-- ConsoleUI/src/consoleui/ConsoleUI.java | 71 +++++++++++++++------ GameEngine/src/engine/GameEngine.java | 21 ++++-- GameEngine/src/engine/Statistics.java | 2 +- 4 files changed, 75 insertions(+), 34 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 079e1f1..c66ee2e 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -15,7 +15,7 @@ static int showMainMenu() { System.out.println("Please select an option:"); System.out.println("1. Load game from xml."); System.out.println("2. Start game."); - System.out.println("3. Show board."); + System.out.println("3. Show status."); System.out.println("4. Make a move."); System.out.println("5. Show statistics."); System.out.println("6. Exit game."); @@ -37,7 +37,9 @@ static String getXML() { } static void showGameStatus(Status status, boolean needFullPrint) { - System.out.println("Game Status:\n"); + if (needFullPrint){ + System.out.println("Game Status:\n"); + } printBoard(status.getBoard()); String line = "The number of cards "; if (needFullPrint) { @@ -46,7 +48,7 @@ static void showGameStatus(Status status, boolean needFullPrint) { line += "in the pot: " + status.getLeftTiles(); System.out.println(line); if (needFullPrint) { - System.out.println("Current player: " + status.getPlayerName()); + System.out.println("Current player: " + status.getPlayerName() + "\n"); } } @@ -105,10 +107,9 @@ static List getPoints(int numOfValues, boolean sizeWasTooShort) { if (sizeWasTooShort) { System.out.println("The number of coordinates is too short! Try again...\n"); } - System.out.println("Please enter "+ numOfValues + "coordinates."); - System.out.println("The format is: row col. example: 5 5\n"); + System.out.println("Please enter "+ numOfValues + " coordinates."); + System.out.println("The format is: row col. example: 5 5"); for (int i = 0; i < numOfValues; i++) { - System.out.println(); int point[] = {-1,-1}; point[0] = scanner.nextInt(); point[1] = scanner.nextInt(); @@ -139,7 +140,7 @@ static void showStatistics(Statistics stats) { System.out.println("Number of cards left: " + cardsLeft); for (int i = 0; i < 12; i++) { //TODO: fix for - System.out.println("\t" + ('A' + i) + " - " + 4 + "/" + 30); + System.out.println("\t" + (char)('A' + i) + " - " + 4 + "/" + 30); } // players long totalWords = stats.getTotalWords(); diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index d7d0e93..0824b6e 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -20,26 +20,40 @@ public static void main(String[] args) { startGame(); break; case 3: - ConsoleHandler.showGameStatus(engine.getStatus(), true); + if (isGameStarted()) { + ConsoleHandler.showGameStatus(engine.getStatus(), true); + } break; case 4: - playTurn(); + if (isGameStarted()) { + playTurn(); + } break; case 5: - Statistics stat = engine.getStatistics(); - ConsoleHandler.showStatistics(stat); + if (isGameStarted()) { + Statistics stat = engine.getStatistics(); + ConsoleHandler.showStatistics(stat); + } break; } } System.out.println("---- Game ended ----"); - char[][] board = engine.getBoard(); - ConsoleHandler.printBoard(board); - Statistics stat = engine.getStatistics(); - ConsoleHandler.showStatistics(stat); + if (engine.isStarted()) { + char[][] board = engine.getBoard(); + ConsoleHandler.printBoard(board); + Statistics stat = engine.getStatistics(); + ConsoleHandler.showStatistics(stat); + } } private static void getXml() { + if (engine.isStarted()) { + System.out.println("The game was already started...\n" + + "Unable to load more XML files.\n"); + return; + } + boolean needInput = true; String pathToXml = null; while (needInput) { @@ -86,14 +100,17 @@ else if (engine.isStarted()) { System.out.println("The number of players is incorrect.\n" + "The minimum is " + e.getMinPlayers() + ", the maximum is " + e.getMaxPlayers() + ", but got " + e.getActualNumOfPlayers() + " players.\n"); + return; } + System.out.println("Game started! Have fun :>\n"); } } private static void playTurn() { - boolean listSizeTooShort = false; + boolean listSizeTooShort = false, continueTrying = true; List points; - int diceValue = engine.getDiceValue(), tries; + int diceValue = engine.getDiceValue(), tryNumber; + System.out.println("Dice value is " + diceValue); do { points = ConsoleHandler.getPoints(diceValue, listSizeTooShort); listSizeTooShort = !engine.updateBoard(points); @@ -101,18 +118,34 @@ private static void playTurn() { char[][] board = engine.getBoard(); ConsoleHandler.printBoard(board); int maxTries = engine.getMaxRetries(); - for (tries = 0; tries < maxTries; tries++) { - String word = ConsoleHandler.getWord(tries + 1, maxTries); - if (engine.isWordValid(word, tries)) { - System.out.println("The word " + word + " is correct!\n"); - break; + for (tryNumber = 1; continueTrying && tryNumber <= maxTries; tryNumber++) { + String word = ConsoleHandler.getWord(tryNumber, maxTries); + switch (engine.isWordValid(word, tryNumber)) { + case CORRECT: + System.out.println("The word " + word + " is correct!\n"); + continueTrying = false; + break; + case WRONG: + System.out.println("Incorrect word!\n"); + break; + case TRIES_DEPLITED: + System.out.println("\nNo more retries!"); + continueTrying = false; + break; } - System.out.println("Incorrect word!\n"); - } - if (tries == maxTries) { - System.out.println("\nNo more retries!"); } System.out.println("Changing to next player..."); ConsoleHandler.showGameStatus(engine.getStatus(), true); } + + private static boolean isGameStarted() { + if (engine.isStarted()) { + return true; + } + System.out.println("The game wasn't started.\n" + + "Please select option 2 to start it" + + (!engine.isXmlLoaded() ? ", after loading at least one xml" : "") + + ".\n"); + return false; + } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 393c688..214bf5c 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -19,6 +19,10 @@ public class GameEngine { private int diceValue; private long startTime; private int numberOfTurns = 0; + private int tryNumber; + public enum WordCheck { + CORRECT, WRONG, TRIES_DEPLITED + } public void loadXml(String pathToXml) throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException, @@ -45,12 +49,13 @@ public boolean isStarted() { public void startGame() throws NumberOfPlayersException { currentGameData = gdfx.get(0); players = new ArrayList<>(); - for (engine.jaxb.schema.generated.Player p: currentGameData.getPlayers()) { //TODO: add function + for (engine.jaxb.schema.generated.Player p: currentGameData.getPlayers()) { players.add(new Player(p.getName().get(0))); } currentPlayer = players.get(0); isGameStarted = true; startTime = System.currentTimeMillis(); + tryNumber = 0; } public Status getStatus() { @@ -84,6 +89,7 @@ public boolean updateBoard(List points) { return true; } catch (OutOfBoardBoundariesException e){ + // TODO: handel correctly System.out.println("Some of the points you chose are out of boandries!\n Try again."); return false; } @@ -96,29 +102,30 @@ public char[][] getBoard() { public int getMaxRetries() { return currentGameData.getNumOfTries(); - } - public boolean isWordValid(String word, int tries) { - if (tries <= currentGameData.getNumOfTries()) { + public WordCheck isWordValid(String word, int tries) { + if (tries == tryNumber && tries <= currentGameData.getNumOfTries()) { if (true) { //TODO: check in dictionary //TODO: update user int score = 0; // TODO: calculate score currentPlayer.updateScore(word, score); nextPlayer(); - return true; + return WordCheck.CORRECT; } - return false; + tryNumber++; + return WordCheck.WRONG; } nextPlayer(); - return false; //TODO: throw NumOfRetriesException + return WordCheck.TRIES_DEPLITED; } private void nextPlayer() { currentPlayer = players.get(nextPlayerNumber); nextPlayerNumber = (nextPlayerNumber + 1) & players.size(); numberOfTurns++; + tryNumber = 1; } public Statistics getStatistics() { diff --git a/GameEngine/src/engine/Statistics.java b/GameEngine/src/engine/Statistics.java index 365c8b5..405ef20 100644 --- a/GameEngine/src/engine/Statistics.java +++ b/GameEngine/src/engine/Statistics.java @@ -41,7 +41,7 @@ public float getScore() { for (Player player: inputPlayer) { players.add(new PlayerData(player)); } - this.playTime = playTime; + this.playTime = playTime / 1000; numOfTurns = turnsPlayed; leftBoxTiles = cardsLeft; gameData = gd; From e4d9c126840edfb24cd7e9a270a384975a3f247f Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 13:11:01 +0300 Subject: [PATCH 40/62] add dictionary to gamedata --- GameEngine/src/engine/GameDataFromXml.java | 82 +++++++++++++--------- GameEngine/src/engine/GameEngine.java | 2 +- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 644758d..074104d 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -42,16 +42,18 @@ public void setLetter(Letter letter) { } } - List letters = new ArrayList<>(); + private List letters = new ArrayList<>(); private int totalAmountOfLetters = 0; private short boardSize; private int numOfCubeWigs; private int numOfTries; private String dictFileName; + private String dictFilePath; private short totalTargetDeckSize; //כמות אריחים private final static String JAXB_XML_GAME_PACKAGE_NAME = "engine.jaxb.schema.generated"; private Board board; private Players players; + private Dictionary dictionary; // get and set funcs: @@ -77,7 +79,7 @@ public int getTotalAmountOfLetters() { return totalAmountOfLetters; } - public void initializingDataFromXml(String pathToXml) throws WrongPathException, NotValidXmlFileException { + public void initializingDataFromXml(String pathToXml) throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException { GameDescriptor gd; InputStream inputStream = null; @@ -90,46 +92,52 @@ public void initializingDataFromXml(String pathToXml) throws WrongPathException, Structure struct; try { - double totalFreq = 0; - gd = deserializeFrom(inputStream); - struct = gd.getStructure(); - - // creates list of data letters + gd = deserializeFrom(inputStream);} catch (JAXBException e) { + throw new NotValidXmlFileException(); + } + double totalFreq = 0; + struct = gd.getStructure(); - for (int i = 0; i < struct.getLetters().getLetter().size(); i++) { - this.letters.add(i,new DataLetter(struct.getLetters().getLetter().get(i))); - totalFreq += this.letters.get(i).getLetter().getFrequency(); - } + // creates list of data letters - for(int i = 0; i < letters.size(); i++){ - double freq = letters.get(i).getLetter().getFrequency(); - letters.get(i).setAmount((int) Math.ceil(Math.ceil(freq / totalFreq * 100 ) / 100 * struct.getLetters().getTargetDeckSize())); - totalAmountOfLetters += letters.get(i).amount; - } + for (int i = 0; i < struct.getLetters().getLetter().size(); i++) { + this.letters.add(i,new DataLetter(struct.getLetters().getLetter().get(i))); + totalFreq += this.letters.get(i).getLetter().getFrequency(); + } - //init board size - boardSize = struct.getBoardSize(); - //init num of wings - this.numOfCubeWigs = struct.getCubeFacets(); - //init num of tries - this.numOfTries = struct.getRetriesNumber(); - //init dictionart file name - dictFileName = struct.getDictionaryFileName(); - //init targer deck size - this.totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); - // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי - board = new Board(boardSize, letters, totalAmountOfLetters); - players = gd.getPlayers(); - - } catch (JAXBException e) { - throw new NotValidXmlFileException(); + for(int i = 0; i < letters.size(); i++){ + double freq = letters.get(i).getLetter().getFrequency(); + letters.get(i).setAmount((int) Math.ceil(Math.ceil(freq / totalFreq * 100 ) / 100 * struct.getLetters().getTargetDeckSize())); + totalAmountOfLetters += letters.get(i).amount; } + + //init board size + boardSize = struct.getBoardSize(); + //init num of wings + this.numOfCubeWigs = struct.getCubeFacets(); + //init num of tries + this.numOfTries = struct.getRetriesNumber(); + //init dictionary file name + dictFileName = struct.getDictionaryFileName(); + //init target deck size + this.totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); + // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי + //init board + board = new Board(boardSize, letters, totalAmountOfLetters); + //init players + players = gd.getPlayers(); + //init dictionary + dictionary = new Dictionary(dictFilePath); } public Board getBoard() { return board; } + public Dictionary getDictionary() { + return dictionary; + } + public void updateBoard(List points) throws OutOfBoardBoundariesException { board.update(points); } @@ -186,12 +194,12 @@ public boolean isDictionaryInRightPos(String pathToXml) throws DictionaryNotFoun while (!pathToXml.endsWith("\\")) { pathToXml = pathToXml.substring(0, pathToXml.length() - 1); } - String pathToDict = pathToXml + "dictionary\\" + dictFileName; - File f = new File(pathToDict); + dictFilePath = pathToXml + "dictionary\\" + dictFileName; + File f = new File(dictFilePath); if (f.exists() && f.isFile()) return true; else { - throw new DictionaryNotFoundException(pathToDict); + throw new DictionaryNotFoundException(dictFilePath); } } @@ -226,6 +234,10 @@ public boolean isEnoughLettersForBoard() throws NotEnoughLettersException { } return true; } + + public int calcScore(String word) { + return 1; + } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 214bf5c..c680f00 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -106,7 +106,7 @@ public int getMaxRetries() { public WordCheck isWordValid(String word, int tries) { if (tries == tryNumber && tries <= currentGameData.getNumOfTries()) { - if (true) { //TODO: check in dictionary + if (currentGameData.getDictionary().hasWord(word)) { //TODO: update user int score = 0; // TODO: calculate score From b6cd8db6b2936b24b242195586e4ca587db01ba0 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Mon, 1 May 2017 17:06:36 +0300 Subject: [PATCH 41/62] fix dictionary file path constraction to thre corrent place --- GameEngine/src/engine/GameDataFromXml.java | 37 +++++++--------------- GameEngine/src/engine/GameEngine.java | 2 +- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 074104d..2dbd19f 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -92,7 +92,8 @@ public void initializingDataFromXml(String pathToXml) throws WrongPathException, Structure struct; try { - gd = deserializeFrom(inputStream);} catch (JAXBException e) { + gd = deserializeFrom(inputStream); + } catch (JAXBException e) { throw new NotValidXmlFileException(); } double totalFreq = 0; @@ -119,6 +120,14 @@ public void initializingDataFromXml(String pathToXml) throws WrongPathException, this.numOfTries = struct.getRetriesNumber(); //init dictionary file name dictFileName = struct.getDictionaryFileName(); + //init dictFilePath variable + + pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" + while (!pathToXml.endsWith("\\")) { + pathToXml = pathToXml.substring(0, pathToXml.length() - 1); + } + dictFilePath = pathToXml + "dictionary\\" + dictFileName; + //init target deck size this.totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי @@ -150,25 +159,6 @@ public List getPlayers() throws NumberOfPla return players; } - // NO NEED: - - // calc functions: -/* - public void calcRatiofrequencyLetter(Map frequencyletter) { - - double totalfreq = 0; - int ratiofreq; - for (Double freq : frequencyletter.values()) { - totalfreq += freq; - } - - for (Map.Entry item : frequencyletter.entrySet()) { - ratiofreq = (int) Math.ceil((item.getValue() / totalfreq) * 100); - this.ratiofrequencyLetter.put(item.getKey(), ratiofreq); - } - } -*/ - //creats the xml details: private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { @@ -188,13 +178,8 @@ public boolean isValidXml(String pathToXml) throws NotXmlFileException { // call this func after calling the one above - public boolean isDictionaryInRightPos(String pathToXml) throws DictionaryNotFoundException { + public boolean isDictionaryInRightPos() throws DictionaryNotFoundException { - pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" - while (!pathToXml.endsWith("\\")) { - pathToXml = pathToXml.substring(0, pathToXml.length() - 1); - } - dictFilePath = pathToXml + "dictionary\\" + dictFileName; File f = new File(dictFilePath); if (f.exists() && f.isFile()) return true; diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index c680f00..29d16dc 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -31,7 +31,7 @@ public void loadXml(String pathToXml) gd.initializingDataFromXml(pathToXml); //check validation: gd.isValidXml(pathToXml); - gd.isDictionaryInRightPos(pathToXml); + gd.isDictionaryInRightPos(); gd.isValidBoardSize(gd.getBoardSize()); gd.isAllLettersAppearOnce(); gdfx.add(gd); From 6f8ae9d7fdf1062306d5142fa74bdc6fe9b294f2 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 18:11:44 +0300 Subject: [PATCH 42/62] remove files --- ConsoleUI/src/consoleui/RunGame.java | 11 ----------- ConsoleUI/src/consoleui/ViewScreen.java | 23 ----------------------- GameEngine/src/engine/jaxb/sdf.java | 7 ------- 3 files changed, 41 deletions(-) delete mode 100644 ConsoleUI/src/consoleui/RunGame.java delete mode 100644 ConsoleUI/src/consoleui/ViewScreen.java delete mode 100644 GameEngine/src/engine/jaxb/sdf.java diff --git a/ConsoleUI/src/consoleui/RunGame.java b/ConsoleUI/src/consoleui/RunGame.java deleted file mode 100644 index 454bdc7..0000000 --- a/ConsoleUI/src/consoleui/RunGame.java +++ /dev/null @@ -1,11 +0,0 @@ -package consoleui; - -public class RunGame { - - //private GameEngine ge; - - /*public void run(){ - - ge.startGame(); - }*/ -} diff --git a/ConsoleUI/src/consoleui/ViewScreen.java b/ConsoleUI/src/consoleui/ViewScreen.java deleted file mode 100644 index b49d019..0000000 --- a/ConsoleUI/src/consoleui/ViewScreen.java +++ /dev/null @@ -1,23 +0,0 @@ -package consoleui; - -public class ViewScreen { - - private int col; - private int row; - - - ViewScreen(int _col, int _row){ - col = _col; - row = _row; - } - public void showBoard(){ - // TODO - } - - public void getMenue(){ - //TODO - } - public void showInstructions(){ - //TODO - } -} diff --git a/GameEngine/src/engine/jaxb/sdf.java b/GameEngine/src/engine/jaxb/sdf.java deleted file mode 100644 index 54ac442..0000000 --- a/GameEngine/src/engine/jaxb/sdf.java +++ /dev/null @@ -1,7 +0,0 @@ -package engine.jaxb; - -/** - * Created by נוי on 23/04/2017. - */ -public class sdf { -} From 6f868fc4f2289932e51167aa00cde1ab7f067733 Mon Sep 17 00:00:00 2001 From: Noy Levy Date: Mon, 1 May 2017 18:12:09 +0300 Subject: [PATCH 43/62] solve kupa issues + appropiriate message in case there is no fucking word --- ConsoleUI/src/consoleui/ConsoleHandler.java | 2 +- GameEngine/src/engine/Board.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index c66ee2e..c07ccd1 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -123,7 +123,7 @@ static String getWord(int tryNum, int maxTries) { Scanner scanner = new Scanner(System.in); System.out.println("Try #" + tryNum + " out of " + maxTries + ":"); - System.out.println("Please enter a word built from the letters above:"); + System.out.println("If you can build a word from the letters above please write it. If not, press -1:"); word = scanner.next(); return word.toUpperCase(); } diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index e9fca89..19998f8 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -143,6 +143,7 @@ public char[][] getBoard() { board[y][x] = new Cell(toAdd.getSign().get(0),false); numOfInsertions ++; letter.setAmount(letter.getAmount() - 1); + } } } @@ -150,9 +151,7 @@ public char[][] getBoard() { //build the kupa for(GameDataFromXml.DataLetter letter : letters){ - for(int i =0; i< letter.getAmount(); i++){ - kupa.add(i, letter); - } + kupa.add(letter); } } } @@ -161,6 +160,16 @@ public void setBoard(Cell[][] board) { this.board = board; } + public List getKupa() { + return kupa; + } + public int getKupaAmount(){ + int amount = 0; + for(GameDataFromXml.DataLetter l : kupa){ + amount += l.getAmount(); + } + return amount; + } public void update(List points) throws OutOfBoardBoundariesException { From d7508d2a80048dfcf9a74a2b7f3f77903e3eecce Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 18:12:30 +0300 Subject: [PATCH 44/62] update ConsoleUI --- ConsoleUI/src/consoleui/ConsoleHandler.java | 3 +-- ConsoleUI/src/consoleui/ConsoleUI.java | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index c66ee2e..788a367 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -30,7 +30,6 @@ static int showMainMenu() { static String getXML() { Scanner scanner = new Scanner(System.in); - String pathToXml; System.out.println("Please enter the path to the XML file:"); return scanner.nextLine(); @@ -57,7 +56,7 @@ static void printBoard(char[][] board) { int numOfRows = board.length; int numOfCols = board.length; int col, row; - StringBuilder line = new StringBuilder(); + StringBuilder line; StringBuilder boarderLine = new StringBuilder(numOfRows > 9 ? "-----" : "---"); String tmpStr; for (col = 0; col < numOfCols; col++) { diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 0824b6e..40231e4 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -74,8 +74,10 @@ private static void getXml() { System.out.println("Expected size is between " + e.getMinSize() + " to " + e.getMaxSize()); System.out.println("Got: " + e.getSize()); } catch (NotValidXmlFileException e) { - System.out.println("The XML file \"" + pathToXml +"\"\n" + + System.out.println("The XML file \"" + pathToXml + "\"\n" + "does not contains the information for Wordiada game.\n"); + } catch (GameTypeException e) { + System.out.println("Game type \"" + e.getGameType() + "\" is not currently supported.\n"); } catch (Exception e) { System.out.println("Error, " + e.getMessage()); } @@ -128,7 +130,7 @@ private static void playTurn() { case WRONG: System.out.println("Incorrect word!\n"); break; - case TRIES_DEPLITED: + case TRIES_DEPLETED: System.out.println("\nNo more retries!"); continueTrying = false; break; From 819852a2df068eabfbdacf7cc1851724adf447bc Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 18:13:05 +0300 Subject: [PATCH 45/62] update GameEngine --- GameEngine/src/engine/GameDataFromXml.java | 43 +++++++++++++++---- GameEngine/src/engine/GameEngine.java | 13 +++--- GameEngine/src/engine/Statistics.java | 7 ++- .../engine/exceptions/GameTypeException.java | 14 ++++++ 4 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 GameEngine/src/engine/exceptions/GameTypeException.java diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 2dbd19f..e3bec5b 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -1,9 +1,7 @@ package engine; import java.io.*; -//import java.io.FileNotFoundException; import java.lang.*; -//import java.io.InputStream; import java.util.*; import java.lang.String; @@ -18,7 +16,7 @@ import javax.xml.bind.Unmarshaller; -public class GameDataFromXml { +class GameDataFromXml { public class DataLetter{ private Letter letter; // sign , score, freq @@ -31,10 +29,10 @@ public class DataLetter{ public Letter getLetter() { return letter; } - public void setAmount(int amount) { + void setAmount(int amount) { this.amount = amount; } - public int getAmount() { + int getAmount() { return amount; } public void setLetter(Letter letter) { @@ -54,6 +52,8 @@ public void setLetter(Letter letter) { private Board board; private Players players; private Dictionary dictionary; + private enum GameType {WORD_COUNT, WORD_SCORE} + private GameType gameType; // get and set funcs: @@ -79,9 +79,10 @@ public int getTotalAmountOfLetters() { return totalAmountOfLetters; } - public void initializingDataFromXml(String pathToXml) throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException { + public void initializingDataFromXml(String pathToXml) + throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException, GameTypeException { GameDescriptor gd; - InputStream inputStream = null; + InputStream inputStream; try { inputStream = new FileInputStream(pathToXml); @@ -137,6 +138,18 @@ public void initializingDataFromXml(String pathToXml) throws WrongPathException, players = gd.getPlayers(); //init dictionary dictionary = new Dictionary(dictFilePath); + // init game type + String gameType = gd.getGameType().getWinnerAccordingTo(); + switch (gameType) { + case ("WordCount"): + this.gameType = GameType.WORD_COUNT; + break; + case ("WordScore"): + this.gameType = GameType.WORD_SCORE; + break; + default: + throw new GameTypeException(gameType); + } } public Board getBoard() { @@ -220,8 +233,20 @@ public boolean isEnoughLettersForBoard() throws NotEnoughLettersException { return true; } - public int calcScore(String word) { - return 1; + public float calcScore(String word) { + if (gameType == GameType.WORD_COUNT) { + return 1; + } + else if (gameType == GameType.WORD_SCORE) { + return 1; + } + else { + return 0; + } + } + + public int getKupaAmount() { + return board.getKupaAmount(); } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 29d16dc..83c1cca 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -21,12 +21,12 @@ public class GameEngine { private int numberOfTurns = 0; private int tryNumber; public enum WordCheck { - CORRECT, WRONG, TRIES_DEPLITED + CORRECT, WRONG, TRIES_DEPLETED } public void loadXml(String pathToXml) throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException, - DuplicateLetterException, NotValidXmlFileException { + DuplicateLetterException, NotValidXmlFileException, GameTypeException { GameDataFromXml gd = new GameDataFromXml(); gd.initializingDataFromXml(pathToXml); //check validation: @@ -107,10 +107,7 @@ public int getMaxRetries() { public WordCheck isWordValid(String word, int tries) { if (tries == tryNumber && tries <= currentGameData.getNumOfTries()) { if (currentGameData.getDictionary().hasWord(word)) { - //TODO: update user - int score = 0; - // TODO: calculate score - currentPlayer.updateScore(word, score); + currentPlayer.updateScore(word, currentGameData.calcScore(word)); nextPlayer(); return WordCheck.CORRECT; } @@ -118,7 +115,7 @@ public WordCheck isWordValid(String word, int tries) { return WordCheck.WRONG; } nextPlayer(); - return WordCheck.TRIES_DEPLITED; + return WordCheck.TRIES_DEPLETED; } private void nextPlayer() { @@ -129,6 +126,6 @@ private void nextPlayer() { } public Statistics getStatistics() { - return new Statistics(players, System.currentTimeMillis() - startTime, numberOfTurns, 0, currentGameData, null); + return new Statistics(players, System.currentTimeMillis() - startTime, numberOfTurns, currentGameData); } } diff --git a/GameEngine/src/engine/Statistics.java b/GameEngine/src/engine/Statistics.java index 405ef20..d5d2621 100644 --- a/GameEngine/src/engine/Statistics.java +++ b/GameEngine/src/engine/Statistics.java @@ -35,17 +35,16 @@ public float getScore() { } } - Statistics(List inputPlayer, long playTime, int turnsPlayed, int cardsLeft, GameDataFromXml gd, - Dictionary dic){ + Statistics(List inputPlayer, long playTime, int turnsPlayed, GameDataFromXml gd){ players = new ArrayList<>(); for (Player player: inputPlayer) { players.add(new PlayerData(player)); } this.playTime = playTime / 1000; numOfTurns = turnsPlayed; - leftBoxTiles = cardsLeft; + leftBoxTiles = gd.getKupaAmount(); gameData = gd; - dict = dic; + dict = gd.getDictionary(); } public long getTime() { diff --git a/GameEngine/src/engine/exceptions/GameTypeException.java b/GameEngine/src/engine/exceptions/GameTypeException.java new file mode 100644 index 0000000..21adaed --- /dev/null +++ b/GameEngine/src/engine/exceptions/GameTypeException.java @@ -0,0 +1,14 @@ +package engine.exceptions; + +public class GameTypeException extends Exception { + private String gameType; + + public GameTypeException(String gameType) { + super(); + this.gameType = gameType; + } + + public String getGameType() { + return gameType; + } +} From a4ba71db8679d5bf36e6b40c9defc278d6ef98b3 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 1 May 2017 19:46:28 +0300 Subject: [PATCH 46/62] update statistics class and print --- ConsoleUI/src/consoleui/ConsoleHandler.java | 7 +++--- GameEngine/src/engine/GameDataFromXml.java | 4 +++ GameEngine/src/engine/GameEngine.java | 1 - GameEngine/src/engine/Statistics.java | 27 +++++++++++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 60f25a5..ec9da7f 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -133,13 +133,12 @@ static void showStatistics(Statistics stats) { System.out.println("Turns played: " + stats.getNumOfTurns()); // total time played long time = stats.getTime(); - System.out.println("Time passed from game start: " + time / 60 + ":" + time % 60); + System.out.println("Time passed from game start: " + time / 60 + ":" + String.format("%02d", time % 60)); // cards left int cardsLeft = stats.getLeftBoxTiles(); System.out.println("Number of cards left: " + cardsLeft); - for (int i = 0; i < 12; i++) { - //TODO: fix for - System.out.println("\t" + (char)('A' + i) + " - " + 4 + "/" + 30); + for (Statistics.Letter letter: stats.getLetters()) { + System.out.println("\t" + letter.getLetter() + " - " + letter.getAmount() + "/" + cardsLeft); } // players long totalWords = stats.getTotalWords(); diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index e3bec5b..afb8e60 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -248,6 +248,10 @@ else if (gameType == GameType.WORD_SCORE) { public int getKupaAmount() { return board.getKupaAmount(); } + + public List getKupa() { + return board.getKupa(); + } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 83c1cca..d1675d3 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -9,7 +9,6 @@ public class GameEngine { - // private GameInformation info; private Player currentPlayer; private int nextPlayerNumber = 1; private List players; diff --git a/GameEngine/src/engine/Statistics.java b/GameEngine/src/engine/Statistics.java index d5d2621..617d7f0 100644 --- a/GameEngine/src/engine/Statistics.java +++ b/GameEngine/src/engine/Statistics.java @@ -6,10 +6,10 @@ public class Statistics { private List players ; + private List letters; private int numOfTurns; private int leftBoxTiles; private long playTime; - private GameDataFromXml gameData; private Dictionary dict; //TODO: add letters left in box of cards @@ -35,15 +35,34 @@ public float getScore() { } } + public class Letter { + private GameDataFromXml.DataLetter letter; + + private Letter(GameDataFromXml.DataLetter l) { + letter = l; + } + + public String getLetter() { + return letter.getLetter().getSign().get(0); + } + + public int getAmount() { + return letter.getAmount(); + } + } + Statistics(List inputPlayer, long playTime, int turnsPlayed, GameDataFromXml gd){ players = new ArrayList<>(); for (Player player: inputPlayer) { players.add(new PlayerData(player)); } + letters = new ArrayList<>(); + for (GameDataFromXml.DataLetter l: gd.getKupa()) { + letters.add(new Letter(l)); + } this.playTime = playTime / 1000; numOfTurns = turnsPlayed; leftBoxTiles = gd.getKupaAmount(); - gameData = gd; dict = gd.getDictionary(); } @@ -70,4 +89,8 @@ public long getTotalWords() { public long getWordCount(String word) { return dict.hasWord(word) ? dict.getWordAmount(word) : 0; } + + public List getLetters() { + return letters; + } } \ No newline at end of file From f66a26ab63cc46aa5abfb805051dc59d37a559d0 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Tue, 2 May 2017 22:26:30 +0300 Subject: [PATCH 47/62] fix change player bug, and start to check if the word's letter are visible in board --- GameEngine/src/engine/Board.java | 7 ++++++- GameEngine/src/engine/GameEngine.java | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index 19998f8..c8ddab8 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -187,7 +187,12 @@ public void update(List points) throws OutOfBoardBoundariesException { } } - + public boolean hasChars(String word) { + for (Character c: word.toCharArray()) { + c.toString(); + } + return false; + } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index d1675d3..feba53b 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -20,7 +20,7 @@ public class GameEngine { private int numberOfTurns = 0; private int tryNumber; public enum WordCheck { - CORRECT, WRONG, TRIES_DEPLETED + CORRECT, WRONG, CHARS_NOT_PRESENT, TRIES_DEPLETED } public void loadXml(String pathToXml) @@ -54,7 +54,7 @@ public void startGame() throws NumberOfPlayersException { currentPlayer = players.get(0); isGameStarted = true; startTime = System.currentTimeMillis(); - tryNumber = 0; + tryNumber = 1; } public Status getStatus() { @@ -105,6 +105,11 @@ public int getMaxRetries() { public WordCheck isWordValid(String word, int tries) { if (tries == tryNumber && tries <= currentGameData.getNumOfTries()) { + //TODO: check if letters are shown in the board + //TODO: remove used letters from board and add others + if (!currentGameData.getBoard().hasChars(word)) { + return WordCheck.CHARS_NOT_PRESENT; + } if (currentGameData.getDictionary().hasWord(word)) { currentPlayer.updateScore(word, currentGameData.calcScore(word)); nextPlayer(); @@ -119,7 +124,7 @@ public WordCheck isWordValid(String word, int tries) { private void nextPlayer() { currentPlayer = players.get(nextPlayerNumber); - nextPlayerNumber = (nextPlayerNumber + 1) & players.size(); + nextPlayerNumber = (nextPlayerNumber + 1) % players.size(); numberOfTurns++; tryNumber = 1; } From 84fceab73649c397c4f21e0f053a3f2923e5c987 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Tue, 2 May 2017 23:16:40 +0300 Subject: [PATCH 48/62] add function for input, and moved error message to main loop # the function is for handling an exception while the user's input isn't int # the error is now part of the switch-case statement as a default behaviour --- ConsoleUI/src/consoleui/ConsoleHandler.java | 33 ++++++++++++++------- ConsoleUI/src/consoleui/ConsoleUI.java | 6 ++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index ec9da7f..a9c22c2 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -1,6 +1,7 @@ package consoleui; import java.util.ArrayList; +import java.util.InputMismatchException; import java.util.List; import java.util.Scanner; import engine.Statistics; @@ -8,9 +9,25 @@ class ConsoleHandler { - static int showMainMenu() { - int selectedMenuItem; + static private int getInput() { Scanner scanner = new Scanner(System.in); + int input = 0; + boolean again; + do { + try { + again = false; + input = scanner.nextInt(); + } catch (InputMismatchException e) { + System.out.println("Wrong input value. Expected a number.\nPlease try again:"); + scanner.next(); + again = true; + } + } while (again); + return input; + } + + static int showMainMenu() { + int selectedMenuItem = 0; System.out.println("Please select an option:"); System.out.println("1. Load game from xml."); @@ -20,11 +37,7 @@ static int showMainMenu() { System.out.println("5. Show statistics."); System.out.println("6. Exit game."); - selectedMenuItem = scanner.nextInt(); - if (selectedMenuItem < 1 && selectedMenuItem > 6) { - System.out.println("Wrong menu number (need to bo 1-6)."); - } - + selectedMenuItem = getInput(); return selectedMenuItem; } @@ -52,7 +65,6 @@ static void showGameStatus(Status status, boolean needFullPrint) { } static void printBoard(char[][] board) { - // TODO: change the signature of the function and fill with correct data int numOfRows = board.length; int numOfCols = board.length; int col, row; @@ -101,7 +113,6 @@ private static void boardIndices(int numOfCols, int numOfRows) { } static List getPoints(int numOfValues, boolean sizeWasTooShort) { - Scanner scanner = new Scanner(System.in); List points = new ArrayList<>(); if (sizeWasTooShort) { System.out.println("The number of coordinates is too short! Try again...\n"); @@ -110,8 +121,8 @@ static List getPoints(int numOfValues, boolean sizeWasTooShort) { System.out.println("The format is: row col. example: 5 5"); for (int i = 0; i < numOfValues; i++) { int point[] = {-1,-1}; - point[0] = scanner.nextInt(); - point[1] = scanner.nextInt(); + point[0] = getInput(); + point[1] = getInput(); points.add(point); } return points; diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 40231e4..fd1d26a 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -10,8 +10,7 @@ public class ConsoleUI { private static GameEngine engine = new GameEngine(); public static void main(String[] args) { int selectedMenu; - while((selectedMenu= ConsoleHandler.showMainMenu()) != 6){ - // TODO: handle unloaded xml when choosing options 3-6 + while((selectedMenu = ConsoleHandler.showMainMenu()) != 6){ switch (selectedMenu) { case 1: getXml(); @@ -35,6 +34,9 @@ public static void main(String[] args) { ConsoleHandler.showStatistics(stat); } break; + default: + System.out.println("Wrong menu number (need to bo 1-6)."); + break; } } From a6d1bf729cc8e16e66431a6e7546b27529d022c2 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Tue, 2 May 2017 23:30:59 +0300 Subject: [PATCH 49/62] removed unneeded init --- ConsoleUI/src/consoleui/ConsoleHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index a9c22c2..58d09c9 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -27,7 +27,7 @@ static private int getInput() { } static int showMainMenu() { - int selectedMenuItem = 0; + int selectedMenuItem; System.out.println("Please select an option:"); System.out.println("1. Load game from xml."); From 5bfd1693a9d6084856dbafc26436284b01a5ab3b Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 01:46:24 +0300 Subject: [PATCH 50/62] fix prints regarding word correctness, and fix player changing when there are no more retries available --- ConsoleUI/src/consoleui/ConsoleUI.java | 10 ++++++++++ GameEngine/src/engine/GameEngine.java | 14 +++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index fd1d26a..f9e14b4 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -136,6 +136,16 @@ private static void playTurn() { System.out.println("\nNo more retries!"); continueTrying = false; break; + case CHARS_NOT_PRESENT: + System.out.println("You wrote a word with unavailable characters..."); + System.out.println("Please try again...\n"); + tryNumber--; + break; + case WRONG_CANT_RETRY: + System.out.println("Incorrect word!\n"); + System.out.println("\nNo more retries!"); + continueTrying = false; + break; } } System.out.println("Changing to next player..."); diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index feba53b..9ccad18 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -20,7 +20,7 @@ public class GameEngine { private int numberOfTurns = 0; private int tryNumber; public enum WordCheck { - CORRECT, WRONG, CHARS_NOT_PRESENT, TRIES_DEPLETED + CORRECT, WRONG, WRONG_CANT_RETRY, CHARS_NOT_PRESENT, TRIES_DEPLETED } public void loadXml(String pathToXml) @@ -99,23 +99,31 @@ public char[][] getBoard() { } + private boolean canRetry() { + return tryNumber <= currentGameData.getNumOfTries(); + } + public int getMaxRetries() { return currentGameData.getNumOfTries(); } public WordCheck isWordValid(String word, int tries) { - if (tries == tryNumber && tries <= currentGameData.getNumOfTries()) { - //TODO: check if letters are shown in the board + if (tries == tryNumber && canRetry()) { //TODO: remove used letters from board and add others if (!currentGameData.getBoard().hasChars(word)) { return WordCheck.CHARS_NOT_PRESENT; } if (currentGameData.getDictionary().hasWord(word)) { + currentGameData.getBoard().removeLettersFromBoard(word); currentPlayer.updateScore(word, currentGameData.calcScore(word)); nextPlayer(); return WordCheck.CORRECT; } tryNumber++; + if (canRetry()) { + nextPlayer(); + return WordCheck.WRONG_CANT_RETRY; + } return WordCheck.WRONG; } nextPlayer(); From e29ebf2a3a31d6e35731982e1f8272841520fe81 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 01:50:37 +0300 Subject: [PATCH 51/62] added functions, moved duplicated code to a new function and fix typo # func to check if word's chars are visible on board # func to replace the word's chars from board and hid them in case the word is in the dictionary --- GameEngine/src/engine/Board.java | 129 +++++++++++++++++++++---------- 1 file changed, 88 insertions(+), 41 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index c8ddab8..5e6e30a 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -64,7 +64,7 @@ private class Cell{ private short size; private List kupa = new ArrayList<>(); private Cell [][] board; // for priting - private Map > initLettrs = new HashMap<>(); //for changes during the game + private Map > initLetters = new HashMap<>(); //for changes during the game static final short MAX_SIZE = 50; static final short MIN_SIZE = 5; @@ -82,36 +82,24 @@ public char[][] getBoard() { //C'tor Board(short _size, List letters, int totalAmountLetters){ - int x,y; Letter toAdd; Point p; this.board = new Cell[_size][_size]; size = _size; //(x,y) point in the board - Random xy = new Random(); //if equal amount letters to board size if(totalAmountLetters == _size * _size) { for(GameDataFromXml.DataLetter letter : letters){ toAdd = letter.getLetter(); - if (!initLettrs.containsKey(toAdd)) { - initLettrs.put(toAdd, new ArrayList<>()); + if (!initLetters.containsKey(toAdd)) { + initLetters.put(toAdd, new ArrayList<>()); } for(int i = 0 ; i < letter.getAmount(); i++){ - boolean toContinue; - do { - toContinue = false; - x = xy.nextInt(size); - y = xy.nextInt(size); - p = new Point(x,y); - for (List listPoints : initLettrs.values()){ - if (listPoints.contains(p)) - toContinue = true; - } - } while (toContinue); - initLettrs.get(toAdd).add(p); - board[y][x] = new Cell(toAdd.getSign().get(0),false); + p = getRandomPoint(); + initLetters.get(toAdd).add(p); + board[p.getY()][p.getX()] = new Cell(toAdd.getSign().get(0),false); letter.setAmount(letter.getAmount() - 1); } } @@ -120,42 +108,46 @@ public char[][] getBoard() { else{ int numOfInsertions = 0; while (numOfInsertions < size*size){ - for(int i =0; i< letters.size(); i++){ - GameDataFromXml.DataLetter letter = letters.get(i); + for(GameDataFromXml.DataLetter letter : letters){ if(numOfInsertions < size*size){ if(letter.getAmount()>0){ - boolean toContinue; toAdd = letter.getLetter(); - if (!initLettrs.containsKey(toAdd)) { - initLettrs.put(toAdd, new ArrayList<>()); + if (!initLetters.containsKey(toAdd)) { + initLetters.put(toAdd, new ArrayList<>()); } - do { - toContinue = false; - x = xy.nextInt(size); - y = xy.nextInt(size); - p = new Point(x,y); - for (List listPoints : initLettrs.values()){ - if (listPoints.contains(p)) - toContinue = true; - } - } while (toContinue); - initLettrs.get(toAdd).add(p); - board[y][x] = new Cell(toAdd.getSign().get(0),false); + p = getRandomPoint(); + initLetters.get(toAdd).add(p); + board[p.getY()][p.getX()] = new Cell(toAdd.getSign().get(0),false); numOfInsertions ++; letter.setAmount(letter.getAmount() - 1); - } } } } //build the kupa - for(GameDataFromXml.DataLetter letter : letters){ - kupa.add(letter); - } + kupa.addAll(letters); } } + private Point getRandomPoint() { + int x,y; + Random xy = new Random(); + Point p; + boolean toContinue; + do { + toContinue = false; + x = xy.nextInt(size); + y = xy.nextInt(size); + p = new Point(x,y); + for (List listPoints : initLetters.values()){ + if (listPoints.contains(p)) + toContinue = true; + } + } while (toContinue); + return p; + } + public void setBoard(Cell[][] board) { this.board = board; } @@ -189,9 +181,64 @@ public void update(List points) throws OutOfBoardBoundariesException { public boolean hasChars(String word) { for (Character c: word.toCharArray()) { - c.toString(); + boolean hasChar = false; + for (Letter letter: initLetters.keySet()) { + if (letter.getSign().get(0).equals(c.toString())) { + for (Point point: initLetters.get(letter)) { + if (board[point.getY()][point.getX()].isShown) { + hasChar = true; + break; + } + } + if (!hasChar) { + return false; + } + } + if (hasChar) { + break; + } + } + } + return true; + } + + public void removeLettersFromBoard(String word) { + Random random = new Random(); + List chars = new ArrayList<>(); + for (Character c: word.toCharArray()) { + chars.add(c.toString()); } - return false; + boolean stop = false; + for (int row = 0; row < size && !stop; row++) { + for (int col = 0; col < size && !stop; col++) { + if (!chars.isEmpty()) { + if (board[row][col].isShown && chars.contains(board[row][col].sign)) { + chars.remove(board[row][col].sign); + for (Letter letter: initLetters.keySet()) { + if (letter.getSign().get(0).equals(board[row][col].sign)) { + initLetters.get(letter).remove(new Point(col, row)); + break; + } + } + + // add new letter to the board + GameDataFromXml.DataLetter dataLetter; + do { + int letter = random.nextInt(initLetters.size()); + dataLetter = kupa.get(letter); + } while(!(dataLetter.getAmount() > 0)); + Letter letter = dataLetter.getLetter(); + initLetters.get(letter).add(new Point(col, row)); + dataLetter.setAmount(dataLetter.getAmount() - 1); + board[row][col].sign = letter.getSign().get(0); + board[row][col].isShown = false; + } + } + else { + stop = true; + } + } + } } From 7158b508027378a7e176f3908b170d25a9c55917 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 13:48:04 +0300 Subject: [PATCH 52/62] add function to print errors --- ConsoleUI/src/consoleui/ConsoleHandler.java | 6 +++++ ConsoleUI/src/consoleui/ConsoleUI.java | 29 ++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 58d09c9..1e68edf 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -162,4 +162,10 @@ static void showStatistics(Statistics stats) { } } } + + static void printError(String title, String message) { + System.out.println(title + ":"); + System.out.println(message); + System.out.println(); + } } diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index f9e14b4..d8ed3a5 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -58,30 +58,35 @@ private static void getXml() { boolean needInput = true; String pathToXml = null; + String message = ""; while (needInput) { pathToXml = ConsoleHandler.getXML(); try { engine.loadXml(pathToXml); needInput = false; } catch (WrongPathException e) { - System.out.println("Invalid path to XML file.\n"); + message = "Invalid path to XML file."; } catch (NotXmlFileException e) { - System.out.println("The file \"" + pathToXml + "\" is not an XML file.\n"); + message = "The file \"" + pathToXml + "\" is not an XML file."; } catch (DictionaryNotFoundException e) { - System.out.println("Unable to use dictionary file \"" + e.getFileName() + "\"\n"); + message = "Unable to use dictionary file \"" + e.getFileName() + "\""; } catch (DuplicateLetterException e) { - System.out.println("The letter " + e.getLetter() + " appears more than once.\n"); + message = "The letter " + e.getLetter() + " appears more than once."; } catch (BoardSizeException e) { - System.out.println("XML not valid!"); - System.out.println("Expected size is between " + e.getMinSize() + " to " + e.getMaxSize()); - System.out.println("Got: " + e.getSize()); + message = "Expected size is between " + e.getMinSize() + " to " + e.getMaxSize() + ". Got: " + e.getSize(); } catch (NotValidXmlFileException e) { - System.out.println("The XML file \"" + pathToXml + "\"\n" + - "does not contains the information for Wordiada game.\n"); - } catch (GameTypeException e) { - System.out.println("Game type \"" + e.getGameType() + "\" is not currently supported.\n"); + message = "The XML file \"" + pathToXml + "\"\n" + + "does not contains the information for Wordiada game."; + } catch (WinTypeException e) { + message = "Winning type \"" + e.getWinType() + "\" is not currently supported."; + } catch (NotEnoughLettersException e) { + message = "There of cards is not enough to fill the board.\n" + + "The board needs " + e.getExpectedAmount() + " but there are only " + e.getCurrentAmount(); } catch (Exception e) { - System.out.println("Error, " + e.getMessage()); + message = "Error, " + e.getMessage(); + } + if (needInput) { + ConsoleHandler.printError("XML load failed", message); } } ConsoleHandler.showGameStatus(engine.getStatus(), false); From 4b2df698429235b3df02b1bdd2be91fbbab5a51b Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 13:49:29 +0300 Subject: [PATCH 53/62] fix exceptions, players error when there are no players in xml, --- GameEngine/src/engine/GameDataFromXml.java | 59 ++++++++++--------- GameEngine/src/engine/GameEngine.java | 11 +++- .../engine/exceptions/GameTypeException.java | 14 ----- .../exceptions/NotEnoughLettersException.java | 15 ++--- .../engine/exceptions/WinTypeException.java | 14 +++++ 5 files changed, 58 insertions(+), 55 deletions(-) delete mode 100644 GameEngine/src/engine/exceptions/GameTypeException.java create mode 100644 GameEngine/src/engine/exceptions/WinTypeException.java diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index afb8e60..4333890 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -25,7 +25,7 @@ public class DataLetter{ DataLetter(Letter l){ letter = l; amount = 0; - } + } public Letter getLetter() { return letter; } @@ -40,6 +40,7 @@ public void setLetter(Letter letter) { } } + private GameDescriptor gameDescriptor; private List letters = new ArrayList<>(); private int totalAmountOfLetters = 0; private short boardSize; @@ -52,8 +53,8 @@ public void setLetter(Letter letter) { private Board board; private Players players; private Dictionary dictionary; - private enum GameType {WORD_COUNT, WORD_SCORE} - private GameType gameType; + private enum WinAccordingTo {WORD_COUNT, WORD_SCORE} + private WinAccordingTo winAccordingTo; // get and set funcs: @@ -79,9 +80,8 @@ public int getTotalAmountOfLetters() { return totalAmountOfLetters; } - public void initializingDataFromXml(String pathToXml) - throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException, GameTypeException { - GameDescriptor gd; + public void initializeDataFromXml(String pathToXml) + throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException, WinTypeException { InputStream inputStream; try { @@ -89,16 +89,15 @@ public void initializingDataFromXml(String pathToXml) } catch (FileNotFoundException e) { throw new WrongPathException(); } - //inputStream = GameDataFromXml.class.getResourceAsStream("/resources/master.xml"); Structure struct; try { - gd = deserializeFrom(inputStream); + gameDescriptor = deserializeFrom(inputStream); } catch (JAXBException e) { throw new NotValidXmlFileException(); } double totalFreq = 0; - struct = gd.getStructure(); + struct = gameDescriptor.getStructure(); // creates list of data letters @@ -135,20 +134,20 @@ public void initializingDataFromXml(String pathToXml) //init board board = new Board(boardSize, letters, totalAmountOfLetters); //init players - players = gd.getPlayers(); + players = gameDescriptor.getPlayers(); //init dictionary dictionary = new Dictionary(dictFilePath); // init game type - String gameType = gd.getGameType().getWinnerAccordingTo(); - switch (gameType) { + String winnerAccordingTo = gameDescriptor.getGameType().getWinnerAccordingTo(); + switch (winnerAccordingTo) { case ("WordCount"): - this.gameType = GameType.WORD_COUNT; + this.winAccordingTo = WinAccordingTo.WORD_COUNT; break; case ("WordScore"): - this.gameType = GameType.WORD_SCORE; + this.winAccordingTo = WinAccordingTo.WORD_SCORE; break; default: - throw new GameTypeException(gameType); + throw new WinTypeException(winnerAccordingTo); } } @@ -165,14 +164,19 @@ public void updateBoard(List points) throws OutOfBoardBoundariesException } public List getPlayers() throws NumberOfPlayersException{ - List players = this.players.getPlayer(); - if (players.size() != 2) { - throw new NumberOfPlayersException(players.size(), engine.Player.MIN_PLAYERS, engine.Player.MAX_PLAYERS); + List players; + if (this.players == null) { + return new ArrayList<>(); + } + players = this.players.getPlayer(); + if (players.size() > 2) { + //TODO: fix when supporting more than 2 + throw new NumberOfPlayersException(players.size(), engine.Player.MIN_PLAYERS, engine.Player.MIN_PLAYERS); } return players; } - //creats the xml details: + //creates the xml details: private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); @@ -209,35 +213,32 @@ public boolean isValidBoardSize(short size) throws BoardSizeException { } public boolean isAllLettersAppearOnce() throws DuplicateLetterException { - boolean isMoreThanOnce = false; for (int i = 0; i < this.getLetters().size(); i++) { DataLetter l = this.getLetters().get(i); String c = this.getLetters().get(i).getLetter().getSign().get(0); this.getLetters().remove(i); for(DataLetter toCompare : this.getLetters()){ - if(toCompare.getLetter().getSign().get(0) == c) - isMoreThanOnce = true; + if(toCompare.getLetter().getSign().get(0).equals(c)) { + throw new DuplicateLetterException(c); + } } this.getLetters().add(i, l); - //appears more than once - if (isMoreThanOnce) - throw new DuplicateLetterException("THE SIGN: " + c + "APPEARS MORE THAN ONCE!"); } return true; } public boolean isEnoughLettersForBoard() throws NotEnoughLettersException { - if (this.letters.size() < this.boardSize * this.boardSize) { + if (totalAmountOfLetters < this.boardSize * this.boardSize) { throw new NotEnoughLettersException(this.boardSize * this.boardSize, this.letters.size()); } - return true; + return true; } public float calcScore(String word) { - if (gameType == GameType.WORD_COUNT) { + if (winAccordingTo == WinAccordingTo.WORD_COUNT) { return 1; } - else if (gameType == GameType.WORD_SCORE) { + else if (winAccordingTo == WinAccordingTo.WORD_SCORE) { return 1; } else { diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 9ccad18..03224f7 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -25,13 +25,14 @@ public enum WordCheck { public void loadXml(String pathToXml) throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException, - DuplicateLetterException, NotValidXmlFileException, GameTypeException { + DuplicateLetterException, NotValidXmlFileException, WinTypeException, NotEnoughLettersException { GameDataFromXml gd = new GameDataFromXml(); - gd.initializingDataFromXml(pathToXml); + gd.initializeDataFromXml(pathToXml); //check validation: gd.isValidXml(pathToXml); gd.isDictionaryInRightPos(); gd.isValidBoardSize(gd.getBoardSize()); + gd.isEnoughLettersForBoard(); gd.isAllLettersAppearOnce(); gdfx.add(gd); } @@ -48,9 +49,13 @@ public boolean isStarted() { public void startGame() throws NumberOfPlayersException { currentGameData = gdfx.get(0); players = new ArrayList<>(); - for (engine.jaxb.schema.generated.Player p: currentGameData.getPlayers()) { + List _players = currentGameData.getPlayers(); + for (engine.jaxb.schema.generated.Player p: _players) { players.add(new Player(p.getName().get(0))); } + while (players.size() < 2) { + players.add(new Player("Player" + players.size())); + } currentPlayer = players.get(0); isGameStarted = true; startTime = System.currentTimeMillis(); diff --git a/GameEngine/src/engine/exceptions/GameTypeException.java b/GameEngine/src/engine/exceptions/GameTypeException.java deleted file mode 100644 index 21adaed..0000000 --- a/GameEngine/src/engine/exceptions/GameTypeException.java +++ /dev/null @@ -1,14 +0,0 @@ -package engine.exceptions; - -public class GameTypeException extends Exception { - private String gameType; - - public GameTypeException(String gameType) { - super(); - this.gameType = gameType; - } - - public String getGameType() { - return gameType; - } -} diff --git a/GameEngine/src/engine/exceptions/NotEnoughLettersException.java b/GameEngine/src/engine/exceptions/NotEnoughLettersException.java index ef52c58..477bf66 100644 --- a/GameEngine/src/engine/exceptions/NotEnoughLettersException.java +++ b/GameEngine/src/engine/exceptions/NotEnoughLettersException.java @@ -5,19 +5,16 @@ public class NotEnoughLettersException extends Exception { private int expectedAmount; private int currentAmount; - public NotEnoughLettersException() {} - public NotEnoughLettersException(int expected, int current){ + public NotEnoughLettersException(int expected, int current) { this.currentAmount = current; this.expectedAmount = expected; } - public NotEnoughLettersException(String message) { - super (message); + public int getExpectedAmount() { + return expectedAmount; } - public NotEnoughLettersException(Throwable cause) { - super (cause); - } - public NotEnoughLettersException(String message, Throwable cause) { - super(message, cause); + + public int getCurrentAmount() { + return currentAmount; } } diff --git a/GameEngine/src/engine/exceptions/WinTypeException.java b/GameEngine/src/engine/exceptions/WinTypeException.java new file mode 100644 index 0000000..c228abe --- /dev/null +++ b/GameEngine/src/engine/exceptions/WinTypeException.java @@ -0,0 +1,14 @@ +package engine.exceptions; + +public class WinTypeException extends Exception { + private String winType; + + public WinTypeException(String winType) { + super(); + this.winType = winType; + } + + public String getWinType() { + return winType; + } +} From cfc5c338a0be3f9c781eda171c44eecc3beba000 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 14:50:25 +0300 Subject: [PATCH 54/62] fix print and changed more error messages prints to the printError func --- ConsoleUI/src/consoleui/ConsoleHandler.java | 2 +- ConsoleUI/src/consoleui/ConsoleUI.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 1e68edf..57dba3c 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -57,7 +57,7 @@ static void showGameStatus(Status status, boolean needFullPrint) { if (needFullPrint) { line += "remaining "; } - line += "in the pot: " + status.getLeftTiles(); + line += "in the Kupa: " + status.getLeftTiles(); System.out.println(line); if (needFullPrint) { System.out.println("Current player: " + status.getPlayerName() + "\n"); diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index d8ed3a5..23e5eb6 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -6,7 +6,6 @@ import engine.exceptions.*; public class ConsoleUI { - // TODO: fix exceptions private static GameEngine engine = new GameEngine(); public static void main(String[] args) { int selectedMenu; @@ -94,19 +93,20 @@ private static void getXml() { } private static void startGame(){ + String errTitle = "Starting game failed"; if (!engine.isXmlLoaded()) { - System.out.println("No xml game file was loaded.\n" + + ConsoleHandler.printError(errTitle, "No xml game file was loaded.\n" + "Please select 1 first to load at least one xml file.\n"); } else if (engine.isStarted()) { - System.out.println("The game was already started...\n" + + ConsoleHandler.printError(errTitle, "The game was already started...\n" + "Please DON'T use this option again.\n"); } else { try { engine.startGame(); } catch (NumberOfPlayersException e) { - System.out.println("The number of players is incorrect.\n" + + ConsoleHandler.printError(errTitle, "The number of players is incorrect.\n" + "The minimum is " + e.getMinPlayers() + ", the maximum is " + e.getMaxPlayers() + ", but got " + e.getActualNumOfPlayers() + " players.\n"); return; From 39898b50a65686a705aea79cef1e13099b4739ec Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 14:52:00 +0300 Subject: [PATCH 55/62] add leftCard variable and removed duplicate code # leftCard counts how many cards left in Kupa --- GameEngine/src/engine/Board.java | 5 +++++ GameEngine/src/engine/GameEngine.java | 15 ++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index 5e6e30a..3f71955 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -61,6 +61,7 @@ private class Cell{ } + private int leftCards; private short size; private List kupa = new ArrayList<>(); private Cell [][] board; // for priting @@ -103,6 +104,7 @@ public char[][] getBoard() { letter.setAmount(letter.getAmount() - 1); } } + leftCards = 0; } //more letters than board size - need for kupa else{ @@ -125,6 +127,8 @@ public char[][] getBoard() { } } + leftCards = totalAmountLetters - numOfInsertions; + //build the kupa kupa.addAll(letters); } @@ -232,6 +236,7 @@ public void removeLettersFromBoard(String word) { dataLetter.setAmount(dataLetter.getAmount() - 1); board[row][col].sign = letter.getSign().get(0); board[row][col].isShown = false; + leftCards--; } } else { diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 03224f7..51e6985 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -63,18 +63,12 @@ public void startGame() throws NumberOfPlayersException { } public Status getStatus() { - if (currentGameData == null) { - GameDataFromXml gd = gdfx.get(gdfx.size() - 1); - return new Status( - gd.getBoard().getBoard(), - currentPlayer != null ? currentPlayer.getName() : null, - gd.getNumOfTries() - ); - } + GameDataFromXml gd = isGameStarted ? currentGameData : gdfx.get(gdfx.size() - 1); + return new Status( - currentGameData.getBoard().getBoard(), + gd.getBoard().getBoard(), currentPlayer != null ? currentPlayer.getName() : null, - currentGameData.getNumOfTries() + gd.getBoard().getKupaAmount() ); } @@ -114,7 +108,6 @@ public int getMaxRetries() { public WordCheck isWordValid(String word, int tries) { if (tries == tryNumber && canRetry()) { - //TODO: remove used letters from board and add others if (!currentGameData.getBoard().hasChars(word)) { return WordCheck.CHARS_NOT_PRESENT; } From 06ac1e7df070f27f646c79ee459fdadd4f6c161e Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 15:29:39 +0300 Subject: [PATCH 56/62] changed for loop and changed return type to void in all checks as they will throw an exception --- GameEngine/src/engine/GameDataFromXml.java | 34 +++++++++------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 4333890..34f6ef5 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -106,10 +106,10 @@ public void initializeDataFromXml(String pathToXml) totalFreq += this.letters.get(i).getLetter().getFrequency(); } - for(int i = 0; i < letters.size(); i++){ - double freq = letters.get(i).getLetter().getFrequency(); - letters.get(i).setAmount((int) Math.ceil(Math.ceil(freq / totalFreq * 100 ) / 100 * struct.getLetters().getTargetDeckSize())); - totalAmountOfLetters += letters.get(i).amount; + for(DataLetter letter: letters) { + double freq = letter.getLetter().getFrequency(); + letter.setAmount((int) Math.ceil(Math.ceil(freq / totalFreq * 100 ) / 100 * struct.getLetters().getTargetDeckSize())); + totalAmountOfLetters += letter.amount; } //init board size @@ -186,33 +186,29 @@ private static GameDescriptor deserializeFrom(InputStream in) throws JAXBExcepti // check Validation functions: - public boolean isValidXml(String pathToXml) throws NotXmlFileException { + public void isValidXml(String pathToXml) throws NotXmlFileException { if (!pathToXml.toLowerCase().endsWith(".xml")) { - throw new NotXmlFileException("ITS NOT XML FILE!"); - } else - return true; + throw new NotXmlFileException(); + } } // call this func after calling the one above - public boolean isDictionaryInRightPos() throws DictionaryNotFoundException { + public void isDictionaryInRightPos() throws DictionaryNotFoundException { File f = new File(dictFilePath); - if (f.exists() && f.isFile()) - return true; - else { + if (!(f.exists() && f.isFile())) { throw new DictionaryNotFoundException(dictFilePath); } } - public boolean isValidBoardSize(short size) throws BoardSizeException { - if ((size >= Board.MIN_SIZE) && (size <= Board.MAX_SIZE)) - return true; - else + public void isValidBoardSize(short size) throws BoardSizeException { + if ((size < Board.MIN_SIZE) && (size > Board.MAX_SIZE)) { throw new BoardSizeException(size, Board.MIN_SIZE, Board.MAX_SIZE); + } } - public boolean isAllLettersAppearOnce() throws DuplicateLetterException { + public void isAllLettersAppearOnce() throws DuplicateLetterException { for (int i = 0; i < this.getLetters().size(); i++) { DataLetter l = this.getLetters().get(i); String c = this.getLetters().get(i).getLetter().getSign().get(0); @@ -224,14 +220,12 @@ public boolean isAllLettersAppearOnce() throws DuplicateLetterException { } this.getLetters().add(i, l); } - return true; } - public boolean isEnoughLettersForBoard() throws NotEnoughLettersException { + public void isEnoughLettersForBoard() throws NotEnoughLettersException { if (totalAmountOfLetters < this.boardSize * this.boardSize) { throw new NotEnoughLettersException(this.boardSize * this.boardSize, this.letters.size()); } - return true; } public float calcScore(String word) { From 3dfed9473dce5d704ae1ff275d76b79b4cae11a5 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 16:00:31 +0300 Subject: [PATCH 57/62] break xml load to little functions for better readability and error handling --- GameEngine/src/engine/GameDataFromXml.java | 163 ++++++++++----------- GameEngine/src/engine/GameEngine.java | 6 - 2 files changed, 80 insertions(+), 89 deletions(-) diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 34f6ef5..74c177b 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -81,7 +81,44 @@ public int getTotalAmountOfLetters() { } public void initializeDataFromXml(String pathToXml) - throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException, WinTypeException { + throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException, WinTypeException, + NotXmlFileException, BoardSizeException, DuplicateLetterException, NotEnoughLettersException { + + loadXml(pathToXml); + Structure struct; + struct = gameDescriptor.getStructure(); + buildDataLetters(struct); + + //init board size + boardSize = struct.getBoardSize(); + //init num of wings + numOfCubeWigs = struct.getCubeFacets(); + //init num of tries + numOfTries = struct.getRetriesNumber(); + //init dictionary file name + dictFileName = struct.getDictionaryFileName(); + + initDictionary(pathToXml); + initBoard(); + + //init players + players = gameDescriptor.getPlayers(); + + initWinType(); + } + + //creates the xml details: + private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); + Unmarshaller u = jc.createUnmarshaller(); + return (GameDescriptor) u.unmarshal(in); + } + + // load the xml to gameDescriptor + private void loadXml(String pathToXml) throws NotXmlFileException, WrongPathException, NotValidXmlFileException { + if (!pathToXml.toLowerCase().endsWith(".xml")) { + throw new NotXmlFileException(); + } InputStream inputStream; try { @@ -89,54 +126,72 @@ public void initializeDataFromXml(String pathToXml) } catch (FileNotFoundException e) { throw new WrongPathException(); } - Structure struct; try { gameDescriptor = deserializeFrom(inputStream); } catch (JAXBException e) { throw new NotValidXmlFileException(); } - double totalFreq = 0; - struct = gameDescriptor.getStructure(); + } + // builds the letters variable and calculates the each letter's frequency + private void buildDataLetters(Structure struct) throws DuplicateLetterException { // creates list of data letters - + double totalFreq = 0; for (int i = 0; i < struct.getLetters().getLetter().size(); i++) { - this.letters.add(i,new DataLetter(struct.getLetters().getLetter().get(i))); - totalFreq += this.letters.get(i).getLetter().getFrequency(); + this.letters.add(i, new DataLetter(struct.getLetters().getLetter().get(i))); + totalFreq += letters.get(i).getLetter().getFrequency(); } - for(DataLetter letter: letters) { + for (DataLetter letter : letters) { double freq = letter.getLetter().getFrequency(); - letter.setAmount((int) Math.ceil(Math.ceil(freq / totalFreq * 100 ) / 100 * struct.getLetters().getTargetDeckSize())); + letter.setAmount((int) Math.ceil(Math.ceil(freq / totalFreq * 100) / 100 * struct.getLetters().getTargetDeckSize())); totalAmountOfLetters += letter.amount; } + verifyLettersAppearOnce(); + //init target deck size + totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); + // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי + } - //init board size - boardSize = struct.getBoardSize(); - //init num of wings - this.numOfCubeWigs = struct.getCubeFacets(); - //init num of tries - this.numOfTries = struct.getRetriesNumber(); - //init dictionary file name - dictFileName = struct.getDictionaryFileName(); - //init dictFilePath variable + private void verifyLettersAppearOnce() throws DuplicateLetterException { + for (int i = 0; i < letters.size(); i++) { + DataLetter l = letters.get(i); + String c = letters.get(i).getLetter().getSign().get(0); + letters.remove(i); + for(DataLetter toCompare : letters){ + if(toCompare.getLetter().getSign().get(0).equals(c)) { + throw new DuplicateLetterException(c); + } + } + letters.add(i, l); + } + } + // check if dictionary exists and pars it + private void initDictionary(String pathToXml) throws DictionaryNotFoundException { pathToXml = pathToXml.substring(0, pathToXml.length() - 4); // minus 4 for ".xml" while (!pathToXml.endsWith("\\")) { pathToXml = pathToXml.substring(0, pathToXml.length() - 1); } dictFilePath = pathToXml + "dictionary\\" + dictFileName; + dictionary = new Dictionary(dictFilePath); + } - //init target deck size - this.totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); - // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי + // initialize board after size check + private void initBoard() throws BoardSizeException, NotEnoughLettersException { + if ((boardSize < Board.MIN_SIZE) && (boardSize > Board.MAX_SIZE)) { + throw new BoardSizeException(boardSize, Board.MIN_SIZE, Board.MAX_SIZE); + } + if (totalAmountOfLetters < boardSize * boardSize) { + throw new NotEnoughLettersException(boardSize * boardSize, totalAmountOfLetters); + } //init board board = new Board(boardSize, letters, totalAmountOfLetters); - //init players - players = gameDescriptor.getPlayers(); - //init dictionary - dictionary = new Dictionary(dictFilePath); + } + + // gets win type + private void initWinType() throws WinTypeException { // init game type String winnerAccordingTo = gameDescriptor.getGameType().getWinnerAccordingTo(); switch (winnerAccordingTo) { @@ -176,58 +231,6 @@ public List getPlayers() throws NumberOfPla return players; } - //creates the xml details: - - private static GameDescriptor deserializeFrom(InputStream in) throws JAXBException { - JAXBContext jc = JAXBContext.newInstance(JAXB_XML_GAME_PACKAGE_NAME); - Unmarshaller u = jc.createUnmarshaller(); - return (GameDescriptor) u.unmarshal(in); - } - - // check Validation functions: - - public void isValidXml(String pathToXml) throws NotXmlFileException { - if (!pathToXml.toLowerCase().endsWith(".xml")) { - throw new NotXmlFileException(); - } - } - - // call this func after calling the one above - - public void isDictionaryInRightPos() throws DictionaryNotFoundException { - - File f = new File(dictFilePath); - if (!(f.exists() && f.isFile())) { - throw new DictionaryNotFoundException(dictFilePath); - } - } - - public void isValidBoardSize(short size) throws BoardSizeException { - if ((size < Board.MIN_SIZE) && (size > Board.MAX_SIZE)) { - throw new BoardSizeException(size, Board.MIN_SIZE, Board.MAX_SIZE); - } - } - - public void isAllLettersAppearOnce() throws DuplicateLetterException { - for (int i = 0; i < this.getLetters().size(); i++) { - DataLetter l = this.getLetters().get(i); - String c = this.getLetters().get(i).getLetter().getSign().get(0); - this.getLetters().remove(i); - for(DataLetter toCompare : this.getLetters()){ - if(toCompare.getLetter().getSign().get(0).equals(c)) { - throw new DuplicateLetterException(c); - } - } - this.getLetters().add(i, l); - } - } - - public void isEnoughLettersForBoard() throws NotEnoughLettersException { - if (totalAmountOfLetters < this.boardSize * this.boardSize) { - throw new NotEnoughLettersException(this.boardSize * this.boardSize, this.letters.size()); - } - } - public float calcScore(String word) { if (winAccordingTo == WinAccordingTo.WORD_COUNT) { return 1; @@ -248,9 +251,3 @@ public List getKupa() { return board.getKupa(); } } - - - - - - diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index 51e6985..ab9c070 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -28,12 +28,6 @@ public void loadXml(String pathToXml) DuplicateLetterException, NotValidXmlFileException, WinTypeException, NotEnoughLettersException { GameDataFromXml gd = new GameDataFromXml(); gd.initializeDataFromXml(pathToXml); - //check validation: - gd.isValidXml(pathToXml); - gd.isDictionaryInRightPos(); - gd.isValidBoardSize(gd.getBoardSize()); - gd.isEnoughLettersForBoard(); - gd.isAllLettersAppearOnce(); gdfx.add(gd); } From 1d2141585f9c602d314f70da850062713f5fde5f Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 17:15:47 +0300 Subject: [PATCH 58/62] fix prints --- ConsoleUI/src/consoleui/ConsoleHandler.java | 1 + ConsoleUI/src/consoleui/ConsoleUI.java | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 57dba3c..6ebfb27 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -161,6 +161,7 @@ static void showStatistics(Statistics stats) { System.out.println("\t" + word + ": " + stats.getWordCount(word) + "/" + totalWords); } } + System.out.println(); } static void printError(String title, String message) { diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 23e5eb6..226af95 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -147,13 +147,12 @@ private static void playTurn() { tryNumber--; break; case WRONG_CANT_RETRY: - System.out.println("Incorrect word!\n"); - System.out.println("\nNo more retries!"); + System.out.println("Incorrect word!\nNo more retries!"); + System.out.println("Changing to next player..."); continueTrying = false; break; } } - System.out.println("Changing to next player..."); ConsoleHandler.showGameStatus(engine.getStatus(), true); } From b27a08e3b29e25e9b131a7b595f3d3280107825a Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 17:16:23 +0300 Subject: [PATCH 59/62] remove duplicated code --- GameEngine/src/engine/Board.java | 51 ++++++++++---------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index 3f71955..b6a34d1 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -90,48 +90,29 @@ public char[][] getBoard() { //(x,y) point in the board //if equal amount letters to board size - if(totalAmountLetters == _size * _size) - { - for(GameDataFromXml.DataLetter letter : letters){ - toAdd = letter.getLetter(); - if (!initLetters.containsKey(toAdd)) { - initLetters.put(toAdd, new ArrayList<>()); + leftCards = totalAmountLetters; + int numOfInsertions = 0; + while (numOfInsertions < size * size) { + for (GameDataFromXml.DataLetter letter : letters) { + if (numOfInsertions >= size * size) { + break; } - for(int i = 0 ; i < letter.getAmount(); i++){ + if (letter.getAmount() > 0) { + toAdd = letter.getLetter(); + if (!initLetters.containsKey(toAdd)) { + initLetters.put(toAdd, new ArrayList<>()); + } p = getRandomPoint(); initLetters.get(toAdd).add(p); - board[p.getY()][p.getX()] = new Cell(toAdd.getSign().get(0),false); + board[p.getY()][p.getX()] = new Cell(toAdd.getSign().get(0), false); letter.setAmount(letter.getAmount() - 1); + leftCards--; + numOfInsertions++; } } - leftCards = 0; - } - //more letters than board size - need for kupa - else{ - int numOfInsertions = 0; - while (numOfInsertions < size*size){ - for(GameDataFromXml.DataLetter letter : letters){ - if(numOfInsertions < size*size){ - if(letter.getAmount()>0){ - toAdd = letter.getLetter(); - if (!initLetters.containsKey(toAdd)) { - initLetters.put(toAdd, new ArrayList<>()); - } - p = getRandomPoint(); - initLetters.get(toAdd).add(p); - board[p.getY()][p.getX()] = new Cell(toAdd.getSign().get(0),false); - numOfInsertions ++; - letter.setAmount(letter.getAmount() - 1); - } - } - } - } - - leftCards = totalAmountLetters - numOfInsertions; - - //build the kupa - kupa.addAll(letters); } + //build the kupa + kupa.addAll(letters); } private Point getRandomPoint() { From ea2f079793dc92aa8da1214b7fe98ccd6cb7f07e Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Wed, 3 May 2017 17:17:42 +0300 Subject: [PATCH 60/62] fixed game flow - only when failing all retries the turn goes to the next player --- GameEngine/src/engine/GameEngine.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index ab9c070..a18d4ce 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -108,11 +108,11 @@ public WordCheck isWordValid(String word, int tries) { if (currentGameData.getDictionary().hasWord(word)) { currentGameData.getBoard().removeLettersFromBoard(word); currentPlayer.updateScore(word, currentGameData.calcScore(word)); - nextPlayer(); + tryNumber = 1; return WordCheck.CORRECT; } tryNumber++; - if (canRetry()) { + if (!canRetry()) { nextPlayer(); return WordCheck.WRONG_CANT_RETRY; } From 2db20170653b287a9c862ba3fad2a271d54a647a Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Thu, 4 May 2017 15:12:42 +0300 Subject: [PATCH 61/62] update --- .idea/artifacts/Wordiada_jar.xml | 9 ++ ConsoleUI/src/META-INF/MANIFEST.MF | 3 + ConsoleUI/src/consoleui/ConsoleHandler.java | 2 +- ConsoleUI/src/consoleui/ConsoleUI.java | 12 +- GameEngine/src/engine/Board.java | 74 ++-------- GameEngine/src/engine/Dictionary.java | 16 +-- GameEngine/src/engine/GameDataFromXml.java | 36 ++--- GameEngine/src/engine/GameEngine.java | 13 +- GameEngine/src/engine/Player.java | 12 +- GameEngine/src/engine/Statistics.java | 2 - .../exceptions/DuplicateLetterException.java | 3 - .../exceptions/NotXmlFileException.java | 9 -- .../OutOfBoardBoundariesException.java | 9 -- .../engine/exceptions/WrongPathException.java | 12 -- .../src/engine/jaxb/SimpleJAXBMain.java | 5 - .../engine/jaxb/schema/generated/Wordiada.xsd | 127 ------------------ README.docx | Bin 0 -> 12916 bytes 17 files changed, 54 insertions(+), 290 deletions(-) create mode 100644 .idea/artifacts/Wordiada_jar.xml create mode 100644 ConsoleUI/src/META-INF/MANIFEST.MF delete mode 100644 GameEngine/src/engine/jaxb/SimpleJAXBMain.java delete mode 100644 GameEngine/src/engine/jaxb/schema/generated/Wordiada.xsd create mode 100644 README.docx diff --git a/.idea/artifacts/Wordiada_jar.xml b/.idea/artifacts/Wordiada_jar.xml new file mode 100644 index 0000000..1a15979 --- /dev/null +++ b/.idea/artifacts/Wordiada_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/Wordiada_jar + + + + + + \ No newline at end of file diff --git a/ConsoleUI/src/META-INF/MANIFEST.MF b/ConsoleUI/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..410ad8f --- /dev/null +++ b/ConsoleUI/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: consoleui.ConsoleUI + diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 6ebfb27..3fb1060 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -133,7 +133,7 @@ static String getWord(int tryNum, int maxTries) { Scanner scanner = new Scanner(System.in); System.out.println("Try #" + tryNum + " out of " + maxTries + ":"); - System.out.println("If you can build a word from the letters above please write it. If not, press -1:"); + System.out.println("If you can build a word from the letters above please write it:"); word = scanner.next(); return word.toUpperCase(); } diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index 226af95..ec585e4 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -116,14 +116,20 @@ else if (engine.isStarted()) { } private static void playTurn() { - boolean listSizeTooShort = false, continueTrying = true; + boolean listSizeTooShort = false, continueTrying = true, outOfBoarder; List points; int diceValue = engine.getDiceValue(), tryNumber; System.out.println("Dice value is " + diceValue); do { + outOfBoarder = false; points = ConsoleHandler.getPoints(diceValue, listSizeTooShort); - listSizeTooShort = !engine.updateBoard(points); - } while(listSizeTooShort); + try { + listSizeTooShort = !engine.updateBoard(points); + } catch (OutOfBoardBoundariesException e) { + ConsoleHandler.printError("Error", "Some of the points you chose are out of boundaries!\n Try again."); + outOfBoarder = true; + } + } while(listSizeTooShort && !outOfBoarder); char[][] board = engine.getBoard(); ConsoleHandler.printBoard(board); int maxTries = engine.getMaxRetries(); diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index b6a34d1..ef1345e 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -8,7 +8,7 @@ import java.util.Map; import java.util.*; -public class Board { +class Board { public class Point{ private int x; @@ -69,7 +69,7 @@ private class Cell{ static final short MAX_SIZE = 50; static final short MIN_SIZE = 5; - public char[][] getBoard() { + char[][] getBoard() { char[][] board = new char[size][size]; for (int row = 0; row < size; row++) { for (int col = 0; col < size; col++) { @@ -133,22 +133,15 @@ private Point getRandomPoint() { return p; } - public void setBoard(Cell[][] board) { - this.board = board; - } - - public List getKupa() { + List getKupa() { return kupa; } - public int getKupaAmount(){ - int amount = 0; - for(GameDataFromXml.DataLetter l : kupa){ - amount += l.getAmount(); - } - return amount; + + int getKupaAmount(){ + return leftCards; } - public void update(List points) throws OutOfBoardBoundariesException { + void update(List points) throws OutOfBoardBoundariesException { //check valid point @@ -164,7 +157,7 @@ public void update(List points) throws OutOfBoardBoundariesException { } } - public boolean hasChars(String word) { + boolean hasChars(String word) { for (Character c: word.toCharArray()) { boolean hasChar = false; for (Letter letter: initLetters.keySet()) { @@ -187,7 +180,7 @@ public boolean hasChars(String word) { return true; } - public void removeLettersFromBoard(String word) { + void removeLettersFromBoard(String word) { Random random = new Random(); List chars = new ArrayList<>(); for (Character c: word.toCharArray()) { @@ -226,53 +219,4 @@ public void removeLettersFromBoard(String word) { } } } - - - - - - - //TODO: remove -/* - public void printLetterInBoard(char sign){ - System.out.println(String.format("%-30s","h")); - }*/ - -/* - public void printBoard(char[][] board) - { - //התקרה - for(int i =0; i < size; i++){ - System.out.print("-------"); - } - System.out.println(); - - for(int j =0; j < size * 2; j++) { - - //colums - if(j % 2 == 0) { - for (int i = 0; i < size + 1; i++) { - char ch = 'a'; - System.out.print("| " + ch + " "); - } - System.out.println(); - for (int i = 0; i < size + 1; i++) { - System.out.print("| "); - } - System.out.println(); - } - - //rows - else{ - for(int i =0; i < size; i++){ - System.out.print("-------"); - } - System.out.println(); - } - - } - - - } - */ } \ No newline at end of file diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java index 4c1a458..406d89d 100644 --- a/GameEngine/src/engine/Dictionary.java +++ b/GameEngine/src/engine/Dictionary.java @@ -8,7 +8,7 @@ import java.util.Map; import java.util.Scanner; -public class Dictionary { +class Dictionary { private long numberOfWords = 0; private Map words = new HashMap<>(); @@ -90,26 +90,18 @@ public boolean equals(Object obj) { } - public boolean hasWord(String word) { + boolean hasWord(String word) { return words.containsKey(word); } - public long getNumberOfWords() { + long getNumberOfWords() { return numberOfWords; } - public long getWordAmount(String word) { + long getWordAmount(String word) { return words.get(word).getCount(); } - public Map getWords() { - Map map = new HashMap<>(); - for (Word word: words.values()) { - map.put(word.word, word.getCount()); - } - return map; - } - private void calcFrequency() { for (Word word: words.values()) { float freq = word.getCount() / numberOfWords * 100; diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index 74c177b..ed9c9ed 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -57,30 +57,14 @@ private enum WinAccordingTo {WORD_COUNT, WORD_SCORE} private WinAccordingTo winAccordingTo; // get and set funcs: - - public short getTargetDeckSize() { - return totalTargetDeckSize; - } - public short getBoardSize() { - return boardSize; - } - public int getNumOfCubeWigs() { + int getNumOfCubeWigs() { return numOfCubeWigs; } - public int getNumOfTries() { + int getNumOfTries() { return numOfTries; } - public List getLetters() { - return letters; - } - public String getDictFileName() { - return dictFileName; - } - public int getTotalAmountOfLetters() { - return totalAmountOfLetters; - } - public void initializeDataFromXml(String pathToXml) + void initializeDataFromXml(String pathToXml) throws WrongPathException, NotValidXmlFileException, DictionaryNotFoundException, WinTypeException, NotXmlFileException, BoardSizeException, DuplicateLetterException, NotEnoughLettersException { @@ -206,19 +190,19 @@ private void initWinType() throws WinTypeException { } } - public Board getBoard() { + Board getBoard() { return board; } - public Dictionary getDictionary() { + Dictionary getDictionary() { return dictionary; } - public void updateBoard(List points) throws OutOfBoardBoundariesException { + void updateBoard(List points) throws OutOfBoardBoundariesException { board.update(points); } - public List getPlayers() throws NumberOfPlayersException{ + List getPlayers() throws NumberOfPlayersException{ List players; if (this.players == null) { return new ArrayList<>(); @@ -231,7 +215,7 @@ public List getPlayers() throws NumberOfPla return players; } - public float calcScore(String word) { + float calcScore(String word) { if (winAccordingTo == WinAccordingTo.WORD_COUNT) { return 1; } @@ -243,11 +227,11 @@ else if (winAccordingTo == WinAccordingTo.WORD_SCORE) { } } - public int getKupaAmount() { + int getKupaAmount() { return board.getKupaAmount(); } - public List getKupa() { + List getKupa() { return board.getKupa(); } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index a18d4ce..eed1b69 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -72,19 +72,12 @@ public int getDiceValue() { return diceValue; } - public boolean updateBoard(List points) { + public boolean updateBoard(List points) throws OutOfBoardBoundariesException { if (points.size() > diceValue) { return false; } - try { - currentGameData.updateBoard(points); - return true; - } - catch (OutOfBoardBoundariesException e){ - // TODO: handel correctly - System.out.println("Some of the points you chose are out of boandries!\n Try again."); - return false; - } + currentGameData.updateBoard(points); + return true; } public char[][] getBoard() { diff --git a/GameEngine/src/engine/Player.java b/GameEngine/src/engine/Player.java index 72bba5c..3570e2b 100644 --- a/GameEngine/src/engine/Player.java +++ b/GameEngine/src/engine/Player.java @@ -2,7 +2,7 @@ import java.util.*; -public class Player { +class Player { private String name; private float score; @@ -10,26 +10,26 @@ public class Player { static final short MAX_PLAYERS = 6; static final short MIN_PLAYERS = 2; - public Player(String name) { + Player(String name) { this.name = name; score = 0; words = new ArrayList<>(); } - public void updateScore(String word, float score) { + void updateScore(String word, float score) { this.score += score; words.add(word); } - public String getName() { + String getName() { return name; } - public float getScore() { + float getScore() { return score; } - public List getWords() { + List getWords() { List l = new ArrayList<>(); l.addAll(words); return l; diff --git a/GameEngine/src/engine/Statistics.java b/GameEngine/src/engine/Statistics.java index 617d7f0..10f39db 100644 --- a/GameEngine/src/engine/Statistics.java +++ b/GameEngine/src/engine/Statistics.java @@ -12,8 +12,6 @@ public class Statistics { private long playTime; private Dictionary dict; - //TODO: add letters left in box of cards - public class PlayerData { private Player player; diff --git a/GameEngine/src/engine/exceptions/DuplicateLetterException.java b/GameEngine/src/engine/exceptions/DuplicateLetterException.java index d6d4d3d..e962b61 100644 --- a/GameEngine/src/engine/exceptions/DuplicateLetterException.java +++ b/GameEngine/src/engine/exceptions/DuplicateLetterException.java @@ -1,8 +1,5 @@ package engine.exceptions; -/** - * Created by נוי on 24/04/2017. - */ public class DuplicateLetterException extends Exception { String letter; diff --git a/GameEngine/src/engine/exceptions/NotXmlFileException.java b/GameEngine/src/engine/exceptions/NotXmlFileException.java index 7afff62..b074542 100644 --- a/GameEngine/src/engine/exceptions/NotXmlFileException.java +++ b/GameEngine/src/engine/exceptions/NotXmlFileException.java @@ -8,14 +8,5 @@ public class NotXmlFileException extends Exception { public NotXmlFileException () {} - public NotXmlFileException (String message) { - super (message); - } - public NotXmlFileException (Throwable cause) { - super (cause); - } - public NotXmlFileException (String message, Throwable cause) { - super (message, cause); - } } diff --git a/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java b/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java index 2357760..dc6d94d 100644 --- a/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java +++ b/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java @@ -4,13 +4,4 @@ public class OutOfBoardBoundariesException extends Exception { public OutOfBoardBoundariesException() {} - public OutOfBoardBoundariesException(String message) { - super (message); - } - public OutOfBoardBoundariesException(Throwable cause) { - super (cause); - } - public OutOfBoardBoundariesException(String message, Throwable cause) { - super (message, cause); - } } diff --git a/GameEngine/src/engine/exceptions/WrongPathException.java b/GameEngine/src/engine/exceptions/WrongPathException.java index 9d5227d..6d65414 100644 --- a/GameEngine/src/engine/exceptions/WrongPathException.java +++ b/GameEngine/src/engine/exceptions/WrongPathException.java @@ -1,18 +1,6 @@ package engine.exceptions; -/** - * Created by נוי on 24/04/2017. - */ public class WrongPathException extends Exception { public WrongPathException () {} - public WrongPathException (String message) { - super (message); - } - public WrongPathException (Throwable cause) { - super (cause); - } - public WrongPathException (String message, Throwable cause) { - super (message, cause); - } } diff --git a/GameEngine/src/engine/jaxb/SimpleJAXBMain.java b/GameEngine/src/engine/jaxb/SimpleJAXBMain.java deleted file mode 100644 index 8ec45f4..0000000 --- a/GameEngine/src/engine/jaxb/SimpleJAXBMain.java +++ /dev/null @@ -1,5 +0,0 @@ -package engine.jaxb; - -/** - * Created by נוי on 23/04/2017. - */ diff --git a/GameEngine/src/engine/jaxb/schema/generated/Wordiada.xsd b/GameEngine/src/engine/jaxb/schema/generated/Wordiada.xsd deleted file mode 100644 index 79f91ef..0000000 --- a/GameEngine/src/engine/jaxb/schema/generated/Wordiada.xsd +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/README.docx b/README.docx new file mode 100644 index 0000000000000000000000000000000000000000..99ec09408d5b2d4cce91422e04b3d2db8b5ae856 GIT binary patch literal 12916 zcmeHtgi58ONF zo0)IA`d8g&rmVY4RuU8p1ponn0ssJn0H$ag72`JmKpr>%fDC{F(Gaw;b~Lhf)KPS^ zHFD6RbG5Q0$OZ$U_zD04_W$4UU;GAY<3`MT7!ZVS17G~7>K7!MDe`)UvLlVKO&{Kb zu*eAA2;{WBv~P1T=8-V64D}OCtawa7G5Sv}rC35E*13=#p>rqr#%i0fQ!mbcr}Z(! zB-@N*SmPgJ`((+|+J-5`_J)DDt|w+p0p?>`PMSZe>K!10Dn3$~ zGhfLwq{g^{C4V?bdfDJW@x`MQZ*~$y*y`gZv(g#~G64ql5Fw{_$HR{j?UEE?O($JV z@UEh8Vfa#o)B~W-&F`913Q-LW5T{!zXZlolsLES4RprqNtl(`QioYSLd!3+VCw>xh zv6h}vE}gWV@QLf8Jw_p-q<{BK-9d^_4kF$LI%s zs^RpYBHs~%+PQRu;5h)x`pY7YMyf*e3}*xnL0SA=WYw)lj`ALh?Wd&c1C@EQn485b z{;Kg9zgQRl z^4Cjax`1j4%XjAg>_62ex73A^BSUX6xs0(038f(}g}l6AKL7H}wXgu9b)Y9Y@@+bH z(%m6V#Azc=>l`aV2`;1!dhTAkN8_>86%ZfTn#brmXS)TPy8FZUd6-z7a@apq4K-u} z3nKb1C~2${d522q$4Yw^i(;kWo4y4qB0suGws5dS)_J;KT zQ4&KN11Bq>C;REb{!o}VKtBfT{oj3*#*Y28;{j)Z?fwfMv>&Vlp`#rreKj?1-xzv4 z3*H#yN~?Ex2}>Y-ftdD>VAeNj51e(sDntG7^{R~(q?!c$bAGjxjrtq>z8{<5N#thc zMWy_2h}{>y-?|*JE5>w3ojr8bMCrGFiZE5RJ1v2)yAH;k3`p#MPfIB_f61?$SuNZy zHcjd>4LexDv{;U|;e10}sgHBcyI61b0Hb47H*dNx0)8uo!gfWd(2OSDIV3KCcD@W1 zS_s8Ll?H-yqv?fKvv%whOlRpy$f4nYFp`9TVtfH&8`ojXHgJv;n^pB0My(inU@^tt zH3a%1aOW{IHZ6%9!TV8oU+zi%$LD}CvNeJQ3;+72CxrD!QrwUj zdhuwdIohaGe_D8x-O*7@drNNbO9!R*#55#&wc8L!?MJ#P)nSvZ+wHC|mR8G7xdJSL zq&bb-c=`uC2j0)K+jcQkj;eaaIG?^UVP4g4qe)!!UKy%yzzp4lyF7WSx7kUthe-zp`_PTW#pEawJcq_>Xl101N6(8moVdtF7efQjKdO%_=++QI#D zA`zve?;8--gMJ|}A7QFgC&fyyz|GZ#Fm^e1L{?KpL;Cv2%lQd%4l)(|^FF6>qnkC?t zGl&UuH6|>jQH0K(A6%Om_hvmZ38R8;1kXaCj4u~fwZ$bbE?GZPd63fS+SAf!89t;v zFOx?@_SVhwoI&>5-EX)t7=wPMfN$6ezw^;b;Oq$gP7%1>51ybJR=GU8H(6=GZTHmy z*{kT)7A>R|@eobP=h@ve@mZpX)4LJVX5b}f!}r{KVlZ+myg<)!eQ-qfM)N&l!hrpSyhJJjx=kGi_b;Zsm27^UrD?Fh}#ok1N-EIO_M>AKRbGS8`qF(s>LZ zcfn0`2(vmv4aw+eD2jDSo@z(hg%5oDOsz8IVE}wPyzsz)QDJ3X5X)cnP*kFimU9RZkQ3z3Db_#}cSOUp`?MaPshFmEorudo`G6*Rr8cd$qL6+~DJB1Y}^mWWjij~3=$|ZX7l&j@Xg4&X$ zE~Q$JI{w7t;nbrGsKx)tHx(jv?}k?D;gl0?KNN@R(c)-pKOh zN>t(YAa;kJP{_WWj9p+rLg5(GrLT71e;V{D+E5eZTj1Zt!bF3?mMLCD&veLSumuwz zh~5skzC%cdf^uK7&wj2&|A^rVJ{)=q z;mvWa!Z^d{HdWJ`t9GRYTEXX5Rpo1=-0an0wt-4P#*uFMm0COJ6um}Epg&Htrh7T# zgXJ9BIcjlfS@{YN>hhdA$e99L93Wnk!WO32Go+s(iUS{sOCRHSlOo}*4UEFDkwcy` zrt;yX&ks8#abd7if8Y1};?GJ%fYUDFPeqm%H5^2iu4JzJnYc8GK$I zuj`t=Lo6xc)x(=xou}t(h4cBVGi~1c;fTHWFSnUIk0- zyj)eCEwB-ecZ4zsknEF;jnc@Rj3WTk-k0<~J=iMiDQRMOg``E*Nl--WeQXD@ui*27 z#$abml*nuwvx{E-=lr9_AR3?Mw|fDn3KH&dYI}~{*piXmG~vhoHOUbzaGTLqmOiu{ z{)>v`E|v}l1A|}PLI>k|pz_2%l}5@SR41+WECe0#z+>z<(sXjex+7=^+6RgDo2z4L z^#qTOtcb|&E(eXhXiety?zTrpNae1eMlEO(=?7d;r9mgDV)g{=4{}rJV-NXrz76~2 zK*)?sD9}Y9l(uYXUERcg+Z>1Pv2;7c#TYHM5e(M^NjV$s_5Q*jNvbT(4(n(k@=l0O z4$4|ikCcB5H)hrdPq&$M)rFDio7a!EcH;QicE0Ki%o;0bp|NKUa)Y3_tIL!Oat>~V zm3hNekA`Zx!0XwDk0;F@gy3x>l}@5%BX?{o&90Aefp=RLF8Jf$G{mgY-(I&lb|jv@ zwmI4?PwdezP=_lg-fb0^uaIb*oft?B`X(XQ4#YP*aJJb}U@Hk@(&8iMSJBXYX0}E2 zFNVcH&D2H2@3p1+QdEpc)NYGw$B?I)@veCB@WT;7jbY|zH;X!Tu4D;N3gweaPs*ho zGm^_W5r-S7ddCX$Xm>?AD8u^K&jD;n;@Q@OQ#4o;1X;$;bTmt7Xl0|%%4mlc(Wp(Y zfKl(6^Odw{O`E8%3?mBGI)=9^%x$zuyR{Yx2X)Nld$DHz0re|VNJ~s%dO>rk6P)uW zN)mAHY7}f{EE;D-^T|P_W}xC@SR4r+<)`B8Z_=F8s#-CJ^_k*dT=P?-gvu2;RxrvLWe$j8{p{{998l@PHxt=RHT@+FKLYATdA9XxadoPHm{#%>+q@WlX!Zg06?+G5DY@?ILsR z3bOtEcFlV)H?4HUE>tB)qD;i6EzuoKXhn-GI&zRvj8l$xRNC`578yFlwXOU^Wi9dY zBS&+RS`#HIklJx!*4c-g61=hO*Nadu^Xc%4^opgR@X7IK88zHn{nb zr@s9116&s~88UpSQp@HRE6=&@15MMjcFD{S>^Aw1P4>s0_OrUBo-gnm^12Ngx2yeM zmCO~rI=-_}VLmIj%s5)ql`kLHLs;K#63yA~_PHQx_gUQjd(=o6Up+Adj2dBJ{t`7h z7&$tcS(`Zg^eDB;tJceGDDC)_E)0&`eKEuzf@KSWPF$rCD+G6V0HpG4h%dgm$Blh! zUSHxc7R_W`sojkZJ@+!#Ij>u8C(_`Yg|MmmSS09UO!&jP^EH z)D$m|$|E(J!TX#;k}Q;t%^8kGdpRyVYL=H5UFSsBRBE9feM+vn@32)*_EwEG4eE#( zo>ec(AH`TQ9(wKW^#)>tjbrh-FbLO#-zJmHB(5b9t3x#{HiKDKUAY&dkzicFPx0Ef z<_xE;xBb(CR`42XQb8~;t_jbJ4ZKJN4u-P~DebkGWVqu1e9KbaS8#GQOh{L*blWg^S?qW0I^v#A30I zmdmNB7V(*VAvi0M+pAt83a65E%#sCP+m%m3I`q`M?M-E{DD)v;!u9x0GvOrVza7Ik_xq?b`bT+;cvPbLRlMj&%XTb3sD5`Ba-oah`&# zcui?dZa0rS-uHaUP+d~pbX@-M&P?Z}+aj9@o(8_Rya|zm(<4Vnh(44!gc2dRfnrbR z3sunv-HgGdQS!8eBhv4~F;*?D4y9;3^;~_QMVm0476uJ+(5~Cfm=il6!`MWACm88NZl0=JFBUD_QtxY3 zjq2#J0_)7__F2?d*L*WFJUc1JACqU84WUjMXi6ZD*E;5Q zHQuX{Z11?D>5z`3aRJrQyFmG>3=FnX@$jXa zi~V;I?Gq9;gOC~pG)kPttG=b2U`?J!5rK)<$4weSPfO&8)2DJ&222^wbDUi&M~+-d zog_I130NJ`XvVA(1gy*-foTiDv^qz3)SV)f<bgF4dFwjOZU#~ zX2I4R6&B=rD*hn9=IuOq{d9rHr=e8=LOSiL=IbaAm7iY?8nT$>@r5%lR0vn_Tju;F z;_~CUr^mEtzsDioX*tPc#~j=9zrMuB&6Gv!w*bJsEdcQDkC*7+=w@m3o9S##*HYMi zkM#Mh!Ti;qTE&Du388xc)+tG$vr~X})Rt^?yiT7w7;SO*!Qj*L4fT-B)?~tV!lNyC z@N}eM+w-uw4@t-C1=7d{`bXxhn3}Hro)>}*@j{~L(Fq7%yoy^Mct08w@!njCyTy%o z6MtTw*Jqm!-b~~BlJ9C?--tV7eKGMD&Y=JJrH4lIJjn=uCWhR7TPlxn*wam0pc5Um)bk$+fb>hpUjm3_T=eOlYv9urkOkX8BHUIFGEDL?g(kKAYPmi@StH zJ)i2kTE5Hs1X6lqA~ge%F94KK2BqYb9sKKYMeb?}T%M(d*FJktj_x<`bDuc4+S19X zj1-DQb#6%}E4xg%pQ2$p&M~PCGm;Yz1l8M0wHJBksfKDc?&FNI5F(q6;DQ5pSJTLo zG4^TGjPBjYRJZ#B?+ffClXmJF=!Hli1gG_X@U~r`$C~*2`_Fzz%!kxC6HgdbIlC}C z8^~RYUD8k(nxu@vb*VyqrA^&QjxH48P%Bk!;cUbxjxf za=y1iw}BmTb`W{pJF>Tk7nyG}o(5fO-CidwQp;wsv#5}sU+)YJYxs<(W+ev`$!>4v z0x+f9QvhZ>T0zp=Y)>833x)F8l-^y*$pF78jerv#7&~2}>ZLU{=1}%WYu-R}( z+;$Z~(X-jf3lCPuOKmtW&x+49yA_sVBtVlE4wd?5MhoW)_7u*S#YvnmiNI3{cp^{Y zh-T+-MsSHZ;FyJMe5Z0W(xY7*h_JNTJLM6%vva{mdTMNm1bDBkBDdqa+&-NSta7J6 z+PO@u0h?l3Gc@Sx{4}g;NX|~GljYsA?eV@pBRKRTz8cQnozS#@TMT|xO$PK3@d67g`RUt)fA zL$V+4&G%1{U=Ry&m554}WFt4YAR)qQM~ya=S0%44&qVJh@gpcQK+7-onMWZ`#Xl9A z^C^WTX{5;gE>v2m7`C*9c)HXFy=n^d+UM2&%NNXg#?Cr1W+rSF18AnZ618zGPD2vs)?>e)>F^Ow;_$)Opg6PHI19QXR{36(_i|iDfPoT@w)q;Do9 z=pp9jHZ49L9E6NUKOzk2+i=}_SGtGqHygF{oSN62hMvtdOAKA=yu?7A|GKI7T69_h zBQ_4}MQ!i#GDYWP#e!S@%B1&p-X~ahcIFFYYzNqfmcXNq8V!!(^tL#fk$@|tV)jUL z7Zt9<=M$YLB`#8>_tYe-fbvg<#El>^a9J_JX@+qgmTmzbEZt@vC6kyEL~SL;FJF>F zf}~*I=E!$<7aCSFP{GlJDSmo!*`LvUwwW&KdRQ+}=nhH%uwp1>MB}{#mtW54D!Li# z{duyzAe}Et(fb|1GqRE>jn76oLZ*=HUC8Irc##Tdi}RR(k&8(#2^Jggnt{c~vD+aN zjB%QaH!jfGDH6SYSEw$>L^JAu8V_Qkj3;{EP|vxsFnHoI?;N;D>&5$zL5s9~b6& zxIpewTAoP0V}NPXV$(8pP`j6&M1QGUt(tjKVGwcaB2o_XqpWfjjxGHD;?ON2ztRIQ zm`K|Rg-6Pc>lDwD*`4~%*5%xovalk^ zst+?sP~=wkHRTsLLoVMEgpW4*jhB(ka2MnJ$gR|Bjp8@BV8>=b3T4x3zDEXZCfO1BYC`QQ)H$Zi zfXA-U<(jz&BkyTkf>#0nQtdm#`LI!mCPhxF zzzdF?Zdd#qfsjZ!Lh%2z0}+8x|LHbS*T%duQW)jOMkVw$90t)eXX!@&9T1Twr`HNZ z^bP!#CIGfnh~WFPYZy#-TNn(bY0mFW=J$nJ9ddeH9VF-=%9JbJAn7-pw*z` zF|VXpVf`r5eqL_-v{0#HrSx=yNR#3Qg@wnJqy9#OJt#>c>zLAf!06`v{2G#P^ZETr z^)qzl`?kGAI;9DL1&e%u_W~WbXE#A>%{m}A5ATzGy>`?;?{1be4P2$*Ey^0Jlz+sY zmF|>)gVvS@4eOXe*r8<=x)+Bd7b%^I`V_z9WABXInhSy9Q$#qdVIFiDi-k8_DK7}3 zY%bO*v3m9Cxc5#HPHs(JFfMb(*6vF@7Siw3^B64Mr@YS;HbCGt;ymI^h+o5y3R(AG(Wmn5vn1EFL^ zcC+%aGcU0fBkKo%*v{YsM3fAEP>_=EV{AWeCH zB?1Te`wUJB6FyI9@OBz5{D2&~{&F=>%D&#E<)KSP)!|>;3}wpeie2VIF$9*H0XF+l zUdd(|UIiU?1kH-Tl1g*GzWZ=F7DrlX-LKg@Y``1xaQQQ?PQ3YtYD~Y`f)c`2O&D6< z2B*cEy7eZ^%LE<`arJ>h#j)A0k4jjlhgqi+iV3_+d9O{(vmobz+- z1bb|kmnk12YFlhHoYijoYn$9IkF5$yZP-&sV4c!-*^{yM1 zZ*O^V!zG-aEa(&oweD!k$^UrLU z;+7ziJ&`_-)_5)zf8r|bNaIklUv1`mhv=bIlS_s2Qq*)F!)m|9VW z-C|(s7)96B1h=7Xo+3n%nv&X>aNvud$ZIao3DDV)`@71R(Qv5Fc%GJsHb)G1MD!6GB;aK%_B0WU&$?;&58|R^bL2hQ{ghEwQUO0VpXHW&K4y z#)=EvYJ;gf@!#%@S+8q}KBS?bX`Ue&o%n+&m@$pmd;Q zQdH$np7z3|dj0VP1M;|?1zl&`In{V6kwUS7b$VXId=kKR$!dwUo%?P(hi-wybu+Hd zHk#Yh5n%=O))m?Mhp;c#`qSOGO&hM=dHGVJ9G+7|)>s4MZHsT10GAs6u8dofwkF+f zu9TWRR?T*jG&ogY0s>639?@&^W{@hRF|Wwm(gG?l4@ZKepB)i zY)Kxs+%}4*7dfl4V3!6)AukM)(%99zmv)BZGq4_AVWWfLWKV;N=(!J(2+Y*tg$A7W zO+Is`Yr<-Zn)MOn`q>)N80eRJKXtCJy~P`E&1&ZWZ) z&Xd(Ir#I;0V$6)i@Sr9{uGoh3zMzjM>X&#kj&XrQ*$`mxXiC(F6XrmO`R$w%9Z&F* zQ<5IQEu1n6Md}W>;N9VeD99emMMX$==qDv+_?9Y>N&qir{_{#Ghe6U2Q4Tp{AQqU4 zWQ=vh6dGLE2n>nO83Jcc{5lm}_qMw&{S-_B+y>zeIa`pN#{FZEuMeLntPrl97<3C~ zi3A3bXKW)XtHyVTHe*0~1K?n*ao00}NRr+3J4Y?#i>3jl8G9#HYO5EElP2Rw$v8g{ zH5_i5#wb&fEF#ln(9#dP>MiUH_LEX(!TQfhj3#?WgqY0?&7GVv7`yQ-sm|}icd1|2-J)TqHG-Xs(hM8Z&?Ip>~Qg*7!Xu0WD}*!V;FCmqCBkHt}1MF`qs<>$rKDZ(PcA z)ow1}%~gY97iC%&ye(ER)FNu9=yz?xok2`cKB`0VBc!I4lxhKC=gSNE`fW=e z{HP#CF((@yS-z?DD)&fNmtjc0B81*T#7Na3N!K^G-V)mJwc~#C^(st@bnZF#0+W-Q z+syn{CqM5GYu>&MZk~m-bI!LZh=%l2Z2Uj6)04jTW1YZ441_p-`~p`5Jt1$`*`r21 zet7hRg6^y#^Q=H!?vo#KbWbaKe}LlRln`>HRhKsVDsJb`tfa|n$=MyLlGbo_NBiy& zrDK=W@_xY$Plddg>O0wJ`Hy7JE8sTEKaKs^`Ghz=(9oko|3!z4fkmK-dis{XS^JfE zEgPT?eLf>U;T3A9w-ca1K`l-|HTzZ@TBcADZWqMrBgFGL&Zh&Jyf%kVm`>SBGS{

5__GO5B`5cDDp0sC|$etC(V zb@&&kJ!}jM9>T!e9gYZJbOGl5MR^R^-8r+}i`g>$v6TrYx2`g};onO=G5R0NY@}8#kSlD=#xO@JXk=dMaGj8%v%)FXGd9l<=wT9ui+f3 z$BUqSHT87i-iGj;@MDp7WiP3G^Jjea3WUs@YL9thgXq9y2f*`yQ>{lhw>~oZK$d47VaEZcUHW zkT#fad%~g7XH1V{_~EQe&v;%22HgvF78*;iG_a&It309<8O|!P8+VzY$rEX$BfQUl z2E-g`s-dzX@=C1g{lg&9Tds$6SI0B-f*{y6qeL$KiHcVz+iVv+99(yD4UfmOy7B!` zP1F}d(6Z%SpC!I!$fOsb(EL-JL^8B&=Yg@q3eYSg{55vav$g$S=m7LlzaMD|UDnGC zux;-acrlvUL;Rg_L4^CF^!N2NKzpqwilxZA4aK7tzAny3R%3r$bT0lF896geOc|Ow zzorZsH00W#e`7gLWxLeSf1-Sxb?<(WtOOlz5q|@(d<+%5Iv9!HOZEUjgv$*f(NwSE z)>pO9xW;pjH;!|TJMcV4mB(;daY>)DJ-U&62Y;{6^V++K+Eq8H9UvYR9x?*ju2OsR z{!ub=j4>($1@5|w3hbUZv$kf=fc~yGq(7%R{D7a%e5*jrat1zz#2RdCXn<{~FMfj< z>8LG4f>>I1E^*!uz3L9hk5!#;Oxc_L{loVUrKgZRN<8$gYD9&>wEKys=M;N>iCK5X zE2f5EhBU=mih8fR)*-#h)Nd`!b)1LE5T4!RjDM8M{R;oJ_U2FcF6{5{Un_BbW$|mG^-mUD$iK7rYufc!_^EB@r*hVjP){%`8ySMcALQ-4B%$s-Z~;2(>tU*W$7xqmWfBl~^q zzlFTN;(vAUf8yUz{f_^eyZ;sccZ>cf8UT=``OEZwx9_r&;6U*L0APW?H$Vy1`k6ul F{2%V#3!(r3 literal 0 HcmV?d00001 From 0b63210cebc123db86f66e8473bb991a2a4180b6 Mon Sep 17 00:00:00 2001 From: DjLegolas Date: Mon, 15 May 2017 12:02:17 +0300 Subject: [PATCH 62/62] final commit for console --- ConsoleUI/src/consoleui/ConsoleHandler.java | 23 +++++++---- ConsoleUI/src/consoleui/ConsoleUI.java | 27 ++++++++++--- GameEngine/src/engine/Board.java | 33 ++++++++++------ GameEngine/src/engine/GameDataFromXml.java | 3 ++ GameEngine/src/engine/GameEngine.java | 44 ++++++++++++++++++++- 5 files changed, 104 insertions(+), 26 deletions(-) diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java index 3fb1060..0c8007f 100644 --- a/ConsoleUI/src/consoleui/ConsoleHandler.java +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -6,11 +6,11 @@ import java.util.Scanner; import engine.Statistics; import engine.Status; +import engine.Board.Point; class ConsoleHandler { - static private int getInput() { - Scanner scanner = new Scanner(System.in); + static private int getInput(Scanner scanner) { int input = 0; boolean again; do { @@ -27,6 +27,7 @@ static private int getInput() { } static int showMainMenu() { + Scanner scanner = new Scanner(System.in); int selectedMenuItem; System.out.println("Please select an option:"); @@ -37,7 +38,7 @@ static int showMainMenu() { System.out.println("5. Show statistics."); System.out.println("6. Exit game."); - selectedMenuItem = getInput(); + selectedMenuItem = getInput(scanner); return selectedMenuItem; } @@ -112,17 +113,25 @@ private static void boardIndices(int numOfCols, int numOfRows) { System.out.println(line); } - static List getPoints(int numOfValues, boolean sizeWasTooShort) { + static List getPoints(int numOfValues, boolean sizeWasTooShort, List unshown) { + Scanner scanner = new Scanner(System.in); + int unShownHalfSize = 1; List points = new ArrayList<>(); if (sizeWasTooShort) { System.out.println("The number of coordinates is too short! Try again...\n"); } - System.out.println("Please enter "+ numOfValues + " coordinates."); + System.out.println("Please enter "+ numOfValues + " of the available coordinates:"); + for (Point p: unshown ){ + System.out.print(p.printAsStr() + (unShownHalfSize % 10 != 0 ? " " : "\n")); + unShownHalfSize++; + } + System.out.println(); System.out.println("The format is: row col. example: 5 5"); + System.out.println(""); for (int i = 0; i < numOfValues; i++) { int point[] = {-1,-1}; - point[0] = getInput(); - point[1] = getInput(); + point[0] = getInput(scanner); + point[1] = getInput(scanner); points.add(point); } return points; diff --git a/ConsoleUI/src/consoleui/ConsoleUI.java b/ConsoleUI/src/consoleui/ConsoleUI.java index ec585e4..c750eff 100644 --- a/ConsoleUI/src/consoleui/ConsoleUI.java +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -8,8 +8,9 @@ public class ConsoleUI { private static GameEngine engine = new GameEngine(); public static void main(String[] args) { + boolean wasEnded = false; int selectedMenu; - while((selectedMenu = ConsoleHandler.showMainMenu()) != 6){ + while((selectedMenu = ConsoleHandler.showMainMenu()) != 6 && !wasEnded){ switch (selectedMenu) { case 1: getXml(); @@ -24,7 +25,7 @@ public static void main(String[] args) { break; case 4: if (isGameStarted()) { - playTurn(); + wasEnded = playTurn(); } break; case 5: @@ -41,10 +42,19 @@ public static void main(String[] args) { System.out.println("---- Game ended ----"); if (engine.isStarted()) { + String winnerName; + if (selectedMenu == 6) { + winnerName = engine.getWinnerName(true); + } + else { + winnerName = engine.getWinnerName(false); + } + char[][] board = engine.getBoard(); ConsoleHandler.printBoard(board); Statistics stat = engine.getStatistics(); ConsoleHandler.showStatistics(stat); + System.out.println("\n\n----------------------\nTHE WINNER IS: " + winnerName + "!"); } } @@ -115,21 +125,25 @@ else if (engine.isStarted()) { } } - private static void playTurn() { + private static boolean playTurn() { + + if(engine.isGameEnded()){ + return true; + } boolean listSizeTooShort = false, continueTrying = true, outOfBoarder; List points; int diceValue = engine.getDiceValue(), tryNumber; System.out.println("Dice value is " + diceValue); do { outOfBoarder = false; - points = ConsoleHandler.getPoints(diceValue, listSizeTooShort); + points = ConsoleHandler.getPoints(diceValue, listSizeTooShort, engine.getUnShownPoints()); try { listSizeTooShort = !engine.updateBoard(points); } catch (OutOfBoardBoundariesException e) { ConsoleHandler.printError("Error", "Some of the points you chose are out of boundaries!\n Try again."); outOfBoarder = true; } - } while(listSizeTooShort && !outOfBoarder); + } while(listSizeTooShort || outOfBoarder); char[][] board = engine.getBoard(); ConsoleHandler.printBoard(board); int maxTries = engine.getMaxRetries(); @@ -160,6 +174,7 @@ private static void playTurn() { } } ConsoleHandler.showGameStatus(engine.getStatus(), true); + return false; } private static boolean isGameStarted() { @@ -172,4 +187,6 @@ private static boolean isGameStarted() { ".\n"); return false; } + + } diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java index ef1345e..a105000 100644 --- a/GameEngine/src/engine/Board.java +++ b/GameEngine/src/engine/Board.java @@ -8,9 +8,9 @@ import java.util.Map; import java.util.*; -class Board { +public class Board { - public class Point{ + public static class Point{ private int x; private int y; @@ -19,6 +19,10 @@ public class Point{ y = _y; } + public String printAsStr(){ + return "( " + x + ", " + y + " )"; + } + public int getX() { return x; } @@ -50,7 +54,7 @@ public boolean equals(Object obj) { return this.x == other.x && this.y == other.y; } } - private class Cell{ + public class Cell{ boolean isShown; String sign; @@ -62,14 +66,14 @@ private class Cell{ } private int leftCards; - private short size; + private short size; // size of board private List kupa = new ArrayList<>(); private Cell [][] board; // for priting private Map > initLetters = new HashMap<>(); //for changes during the game static final short MAX_SIZE = 50; static final short MIN_SIZE = 5; - char[][] getBoard() { + char[][] getBoard_onlySigns() { char[][] board = new char[size][size]; for (int row = 0; row < size; row++) { for (int col = 0; col < size; col++) { @@ -79,6 +83,8 @@ char[][] getBoard() { return board; } + Cell[][] getFullBoardDetails(){return board;} + //C'tor Board(short _size, List letters, int totalAmountLetters){ @@ -144,16 +150,17 @@ int getKupaAmount(){ void update(List points) throws OutOfBoardBoundariesException { //check valid point - - for(int i = 0; i < points.size(); i++){ + for(int i = 0; i < points.size(); i++) { Point point = new Point((points.get(i))[1], (points.get(i))[0]); - - if(point.getX() > size || point.getX() < 1 || point.getY() > size || point.getY() < 1){ + if (point.getX() > size || point.getX() < 1 || point.getY() > size || point.getY() < 1) { throw new OutOfBoardBoundariesException(); } - else{ - board[point.getY()-1][point.getX()-1].isShown = true; - } + } + + + for(int i = 0; i < points.size(); i++){ + Point point = new Point((points.get(i))[1], (points.get(i))[0]); + board[point.getY()-1][point.getX()-1].isShown = true; } } @@ -180,6 +187,8 @@ boolean hasChars(String word) { return true; } + short getBoardSize(){return size;} + void removeLettersFromBoard(String word) { Random random = new Random(); List chars = new ArrayList<>(); diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java index ed9c9ed..374c0f7 100644 --- a/GameEngine/src/engine/GameDataFromXml.java +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -234,4 +234,7 @@ int getKupaAmount() { List getKupa() { return board.getKupa(); } + Board getBoardClass(){ + return board; + } } diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java index eed1b69..b75826d 100644 --- a/GameEngine/src/engine/GameEngine.java +++ b/GameEngine/src/engine/GameEngine.java @@ -1,11 +1,14 @@ package engine; import java.lang.String; + +import com.sun.xml.internal.bind.v2.schemagen.xmlschema.Import; import engine.exceptions.*; import java.util.ArrayList; import java.util.List; import java.util.Random; +import engine.Board.Point; public class GameEngine { @@ -60,7 +63,7 @@ public Status getStatus() { GameDataFromXml gd = isGameStarted ? currentGameData : gdfx.get(gdfx.size() - 1); return new Status( - gd.getBoard().getBoard(), + gd.getBoard().getBoard_onlySigns(), currentPlayer != null ? currentPlayer.getName() : null, gd.getBoard().getKupaAmount() ); @@ -81,7 +84,7 @@ public boolean updateBoard(List points) throws OutOfBoardBoundariesExcept } public char[][] getBoard() { - return currentGameData.getBoard().getBoard(); + return currentGameData.getBoard().getBoard_onlySigns(); } @@ -125,4 +128,41 @@ private void nextPlayer() { public Statistics getStatistics() { return new Statistics(players, System.currentTimeMillis() - startTime, numberOfTurns, currentGameData); } + + public List getUnShownPoints(){ + List unShownPoints = new ArrayList<>(); + for(int row = 0; row