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/ViewScreen.java b/ConsoleUI/src/ViewScreen.java deleted file mode 100644 index 4f0f71b..0000000 --- a/ConsoleUI/src/ViewScreen.java +++ /dev/null @@ -1,4 +0,0 @@ - -public class ViewScreen { - -} diff --git a/ConsoleUI/src/consoleui/ConsoleHandler.java b/ConsoleUI/src/consoleui/ConsoleHandler.java new file mode 100644 index 0000000..0c8007f --- /dev/null +++ b/ConsoleUI/src/consoleui/ConsoleHandler.java @@ -0,0 +1,181 @@ +package consoleui; + +import java.util.ArrayList; +import java.util.InputMismatchException; +import java.util.List; +import java.util.Scanner; +import engine.Statistics; +import engine.Status; +import engine.Board.Point; + +class ConsoleHandler { + + static private int getInput(Scanner scanner) { + 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() { + Scanner scanner = new Scanner(System.in); + int selectedMenuItem; + + 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 status."); + System.out.println("4. Make a move."); + System.out.println("5. Show statistics."); + System.out.println("6. Exit game."); + + selectedMenuItem = getInput(scanner); + return selectedMenuItem; + } + + static String getXML() { + Scanner scanner = new Scanner(System.in); + + System.out.println("Please enter the path to the XML file:"); + return scanner.nextLine(); + } + + static void showGameStatus(Status status, boolean needFullPrint) { + if (needFullPrint){ + System.out.println("Game Status:\n"); + } + printBoard(status.getBoard()); + String line = "The number of cards "; + if (needFullPrint) { + line += "remaining "; + } + line += "in the Kupa: " + status.getLeftTiles(); + System.out.println(line); + if (needFullPrint) { + System.out.println("Current player: " + status.getPlayerName() + "\n"); + } + } + + static void printBoard(char[][] board) { + int numOfRows = board.length; + int numOfCols = board.length; + int col, row; + StringBuilder line; + StringBuilder boarderLine = new StringBuilder(numOfRows > 9 ? "-----" : "---"); + String tmpStr; + for (col = 0; col < numOfCols; col++) { + boarderLine.append("--"); + } + System.out.println("Current Board:\n"); + boardIndices(numOfCols, numOfRows); + System.out.println(boarderLine); + // print board + for (row = 0; row < numOfRows; row++) { + line = new StringBuilder(numOfRows > 9 && row < 9 ? " " : ""); + tmpStr = (row + 1) + "|"; + line.append(tmpStr); + for (col = 0; col < numOfCols; col++) { + tmpStr = board[row][col] + "|"; + line.append(tmpStr); + } + line.append(row + 1); + System.out.println(line); + System.out.println(boarderLine); + } + boardIndices(numOfCols, numOfRows); + } + + private static void boardIndices(int numOfCols, int numOfRows) { + int col; + StringBuilder line = new StringBuilder(); + String tmpStr, lineStart = numOfRows > 9 ? " |" : " |"; + line.append(lineStart); + if (numOfRows > 9) { + for (col = 1; col <= numOfCols; col++) { + line.append(col % 10 == 0 ? col / 10 + "|" : " |"); + } + System.out.println(line); + } + line = new StringBuilder(lineStart); + for (col = 0; col < numOfCols; col++) { + tmpStr = (col + 1) % 10 + "|"; + line.append(tmpStr); + } + System.out.println(line); + } + + 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 + " 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(scanner); + point[1] = getInput(scanner); + points.add(point); + } + return points; + } + + 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("If you can build a word from the letters above please write it:"); + word = scanner.next(); + return word.toUpperCase(); + } + + static void showStatistics(Statistics stats) { + System.out.println("Game Statistics:\n"); + // 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 + ":" + String.format("%02d", time % 60)); + // cards left + int cardsLeft = stats.getLeftBoxTiles(); + System.out.println("Number of cards left: " + cardsLeft); + for (Statistics.Letter letter: stats.getLetters()) { + System.out.println("\t" + letter.getLetter() + " - " + letter.getAmount() + "/" + cardsLeft); + } + // 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); + } + } + System.out.println(); + } + + 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 new file mode 100644 index 0000000..c750eff --- /dev/null +++ b/ConsoleUI/src/consoleui/ConsoleUI.java @@ -0,0 +1,192 @@ +package consoleui; + +import java.util.List; +import engine.GameEngine; +import engine.Statistics; +import engine.exceptions.*; + +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 && !wasEnded){ + switch (selectedMenu) { + case 1: + getXml(); + break; + case 2: + startGame(); + break; + case 3: + if (isGameStarted()) { + ConsoleHandler.showGameStatus(engine.getStatus(), true); + } + break; + case 4: + if (isGameStarted()) { + wasEnded = playTurn(); + } + break; + case 5: + if (isGameStarted()) { + Statistics stat = engine.getStatistics(); + ConsoleHandler.showStatistics(stat); + } + break; + default: + System.out.println("Wrong menu number (need to bo 1-6)."); + break; + } + } + + 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 + "!"); + } + } + + 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; + String message = ""; + while (needInput) { + pathToXml = ConsoleHandler.getXML(); + try { + engine.loadXml(pathToXml); + needInput = false; + } catch (WrongPathException e) { + message = "Invalid path to XML file."; + } catch (NotXmlFileException e) { + message = "The file \"" + pathToXml + "\" is not an XML file."; + } catch (DictionaryNotFoundException e) { + message = "Unable to use dictionary file \"" + e.getFileName() + "\""; + } catch (DuplicateLetterException e) { + message = "The letter " + e.getLetter() + " appears more than once."; + } catch (BoardSizeException e) { + message = "Expected size is between " + e.getMinSize() + " to " + e.getMaxSize() + ". Got: " + e.getSize(); + } catch (NotValidXmlFileException e) { + 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) { + message = "Error, " + e.getMessage(); + } + if (needInput) { + ConsoleHandler.printError("XML load failed", message); + } + } + ConsoleHandler.showGameStatus(engine.getStatus(), false); + System.out.println("XML file \"" + pathToXml + "\" loaded successfully!\n"); + } + + private static void startGame(){ + String errTitle = "Starting game failed"; + if (!engine.isXmlLoaded()) { + 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()) { + ConsoleHandler.printError(errTitle, "The game was already started...\n" + + "Please DON'T use this option again.\n"); + } + else { + try { + engine.startGame(); + } catch (NumberOfPlayersException e) { + 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; + } + System.out.println("Game started! Have fun :>\n"); + } + } + + 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, 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); + char[][] board = engine.getBoard(); + ConsoleHandler.printBoard(board); + int maxTries = engine.getMaxRetries(); + 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_DEPLETED: + 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!\nNo more retries!"); + System.out.println("Changing to next player..."); + continueTrying = false; + break; + } + } + ConsoleHandler.showGameStatus(engine.getStatus(), true); + return false; + } + + 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/GameDataFromXml.java b/GameEngine/src/GameDataFromXml.java deleted file mode 100644 index 1a89ce4..0000000 --- a/GameEngine/src/GameDataFromXml.java +++ /dev/null @@ -1,3 +0,0 @@ - -public class GameDataFromXml { -} diff --git a/GameEngine/src/GameEngine.java b/GameEngine/src/GameEngine.java deleted file mode 100644 index 7492637..0000000 --- a/GameEngine/src/GameEngine.java +++ /dev/null @@ -1,2 +0,0 @@ -public class GameEngine { -} 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 deleted file mode 100644 index 4844ce3..0000000 --- a/GameEngine/src/Player.java +++ /dev/null @@ -1,8 +0,0 @@ - -public class Player { - - private String mName; - private float mScore; - - -} diff --git a/GameEngine/src/engine/Board.java b/GameEngine/src/engine/Board.java new file mode 100644 index 0000000..a105000 --- /dev/null +++ b/GameEngine/src/engine/Board.java @@ -0,0 +1,231 @@ +package engine; + +import engine.exceptions.OutOfBoardBoundariesException; +import engine.jaxb.schema.generated.Letter; + +import java.util.Random; +import java.util.HashMap; +import java.util.Map; +import java.util.*; + +public class Board { + + public static class Point{ + private int x; + private int y; + + Point(int _x, int _y){ + x = _x; + y = _y; + } + + public String printAsStr(){ + return "( " + x + ", " + y + " )"; + } + + public int getX() { + return x; + } + + 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; + } + } + public class Cell{ + boolean isShown; + String sign; + + Cell(String _sign, boolean _isShown) { + isShown = _isShown; + sign = _sign; + } + + } + + private int leftCards; + 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_onlySigns() { + 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].isShown ? this.board[row][col].sign.toCharArray()[0] : ' '; + } + } + return board; + } + + Cell[][] getFullBoardDetails(){return board;} + + + //C'tor + Board(short _size, List letters, int totalAmountLetters){ + + Letter toAdd; + Point p; + this.board = new Cell[_size][_size]; + size = _size; + + //(x,y) point in the board + //if equal amount letters to board size + leftCards = totalAmountLetters; + int numOfInsertions = 0; + while (numOfInsertions < size * size) { + for (GameDataFromXml.DataLetter letter : letters) { + if (numOfInsertions >= size * size) { + break; + } + 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); + letter.setAmount(letter.getAmount() - 1); + leftCards--; + numOfInsertions++; + } + } + } + //build the kupa + 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; + } + + List getKupa() { + return kupa; + } + + int getKupaAmount(){ + return leftCards; + } + + void update(List points) throws OutOfBoardBoundariesException { + + //check valid point + 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(); + } + } + + + 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; + } + } + + boolean hasChars(String word) { + for (Character c: word.toCharArray()) { + 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; + } + + short getBoardSize(){return size;} + + void removeLettersFromBoard(String word) { + Random random = new Random(); + List chars = new ArrayList<>(); + for (Character c: word.toCharArray()) { + chars.add(c.toString()); + } + 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; + leftCards--; + } + } + else { + stop = true; + } + } + } + } +} \ No newline at end of file diff --git a/GameEngine/src/engine/Dictionary.java b/GameEngine/src/engine/Dictionary.java new file mode 100644 index 0000000..406d89d --- /dev/null +++ b/GameEngine/src/engine/Dictionary.java @@ -0,0 +1,111 @@ +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; + +class Dictionary { + private long numberOfWords = 0; + 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; + try { + scanner = new Scanner(new File(pathToDict)); + } catch (FileNotFoundException e) { + throw new DictionaryNotFoundException(pathToDict); + } + + String currentWord; + String toRemove = " !?,.:;-_=+*\"'\\(\\)\\{\\}\\[\\]%$"; + while (scanner.hasNext()) { + currentWord = scanner.next(); + currentWord = currentWord.replaceAll("[" + toRemove +"]", "").toUpperCase(); + if (currentWord.length() >= 2) { + if (!words.containsKey(currentWord)){ + words.put(currentWord, new Word(currentWord)); + } + else { + words.get(currentWord).advanceCount(); + } + numberOfWords++; + } + } + calcFrequency(); + } + + + boolean hasWord(String word) { + return words.containsKey(word); + } + + long getNumberOfWords() { + return numberOfWords; + } + + long getWordAmount(String word) { + return words.get(word).getCount(); + } + + private void calcFrequency() { + for (Word word: words.values()) { + float freq = word.getCount() / numberOfWords * 100; + word.setFrequency(freq); + } + } +} diff --git a/GameEngine/src/engine/GameDataFromXml.java b/GameEngine/src/engine/GameDataFromXml.java new file mode 100644 index 0000000..374c0f7 --- /dev/null +++ b/GameEngine/src/engine/GameDataFromXml.java @@ -0,0 +1,240 @@ +package engine; + +import java.io.*; +import java.lang.*; +import java.util.*; +import java.lang.String; + +import engine.exceptions.*; + + +import engine.jaxb.schema.generated.*; +import engine.jaxb.schema.generated.Player; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + + +class GameDataFromXml { + + public class DataLetter{ + private Letter letter; // sign , score, freq + private int amount = 0; + + DataLetter(Letter l){ + letter = l; + amount = 0; + } + public Letter getLetter() { + return letter; + } + void setAmount(int amount) { + this.amount = amount; + } + int getAmount() { + return amount; + } + public void setLetter(Letter letter) { + this.letter = letter; + } + } + + private GameDescriptor gameDescriptor; + 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; + private enum WinAccordingTo {WORD_COUNT, WORD_SCORE} + private WinAccordingTo winAccordingTo; + + // get and set funcs: + int getNumOfCubeWigs() { + return numOfCubeWigs; + } + int getNumOfTries() { + return numOfTries; + } + + void initializeDataFromXml(String pathToXml) + 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 { + inputStream = new FileInputStream(pathToXml); + } catch (FileNotFoundException e) { + throw new WrongPathException(); + } + + try { + gameDescriptor = deserializeFrom(inputStream); + } catch (JAXBException e) { + throw new NotValidXmlFileException(); + } + } + + // 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 += letters.get(i).getLetter().getFrequency(); + } + + 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; + } + verifyLettersAppearOnce(); + //init target deck size + totalTargetDeckSize = struct.getLetters().getTargetDeckSize(); + // this.targetDeckSize = struct.getLetters().getTargetDeckSize();----> הצפי + } + + 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); + } + + // 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); + } + + // gets win type + private void initWinType() throws WinTypeException { + // init game type + String winnerAccordingTo = gameDescriptor.getGameType().getWinnerAccordingTo(); + switch (winnerAccordingTo) { + case ("WordCount"): + this.winAccordingTo = WinAccordingTo.WORD_COUNT; + break; + case ("WordScore"): + this.winAccordingTo = WinAccordingTo.WORD_SCORE; + break; + default: + throw new WinTypeException(winnerAccordingTo); + } + } + + Board getBoard() { + return board; + } + + Dictionary getDictionary() { + return dictionary; + } + + void updateBoard(List points) throws OutOfBoardBoundariesException { + board.update(points); + } + + List getPlayers() throws NumberOfPlayersException{ + 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; + } + + float calcScore(String word) { + if (winAccordingTo == WinAccordingTo.WORD_COUNT) { + return 1; + } + else if (winAccordingTo == WinAccordingTo.WORD_SCORE) { + return 1; + } + else { + return 0; + } + } + + int getKupaAmount() { + return board.getKupaAmount(); + } + + List getKupa() { + return board.getKupa(); + } + Board getBoardClass(){ + return board; + } +} diff --git a/GameEngine/src/engine/GameEngine.java b/GameEngine/src/engine/GameEngine.java new file mode 100644 index 0000000..b75826d --- /dev/null +++ b/GameEngine/src/engine/GameEngine.java @@ -0,0 +1,168 @@ +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 { + + private Player currentPlayer; + private int nextPlayerNumber = 1; + private List players; + private List gdfx = new ArrayList<>(); + private GameDataFromXml currentGameData; + private boolean isGameStarted = false; + private int diceValue; + private long startTime; + private int numberOfTurns = 0; + private int tryNumber; + public enum WordCheck { + CORRECT, WRONG, WRONG_CANT_RETRY, CHARS_NOT_PRESENT, TRIES_DEPLETED + } + + public void loadXml(String pathToXml) + throws WrongPathException, DictionaryNotFoundException, BoardSizeException, NotXmlFileException, + DuplicateLetterException, NotValidXmlFileException, WinTypeException, NotEnoughLettersException { + GameDataFromXml gd = new GameDataFromXml(); + gd.initializeDataFromXml(pathToXml); + gdfx.add(gd); + } + + + public boolean isXmlLoaded() { + return !gdfx.isEmpty(); + } + + public boolean isStarted() { + return isGameStarted; + } + + public void startGame() throws NumberOfPlayersException { + currentGameData = gdfx.get(0); + players = new ArrayList<>(); + 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(); + tryNumber = 1; + } + + public Status getStatus() { + GameDataFromXml gd = isGameStarted ? currentGameData : gdfx.get(gdfx.size() - 1); + + return new Status( + gd.getBoard().getBoard_onlySigns(), + currentPlayer != null ? currentPlayer.getName() : null, + gd.getBoard().getKupaAmount() + ); + } + + public int getDiceValue() { + Random random = new Random(); + diceValue = random.nextInt(currentGameData.getNumOfCubeWigs() - 1) + 2; + return diceValue; + } + + public boolean updateBoard(List points) throws OutOfBoardBoundariesException { + if (points.size() > diceValue) { + return false; + } + currentGameData.updateBoard(points); + return true; + } + + public char[][] getBoard() { + return currentGameData.getBoard().getBoard_onlySigns(); + + } + + private boolean canRetry() { + return tryNumber <= currentGameData.getNumOfTries(); + } + + public int getMaxRetries() { + return currentGameData.getNumOfTries(); + } + + public WordCheck isWordValid(String word, int tries) { + if (tries == tryNumber && canRetry()) { + 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)); + tryNumber = 1; + return WordCheck.CORRECT; + } + tryNumber++; + if (!canRetry()) { + nextPlayer(); + return WordCheck.WRONG_CANT_RETRY; + } + return WordCheck.WRONG; + } + nextPlayer(); + return WordCheck.TRIES_DEPLETED; + } + + private void nextPlayer() { + currentPlayer = players.get(nextPlayerNumber); + nextPlayerNumber = (nextPlayerNumber + 1) % players.size(); + numberOfTurns++; + tryNumber = 1; + } + + public Statistics getStatistics() { + return new Statistics(players, System.currentTimeMillis() - startTime, numberOfTurns, currentGameData); + } + + public List getUnShownPoints(){ + List unShownPoints = new ArrayList<>(); + for(int row = 0; row words; + static final short MAX_PLAYERS = 6; + static final short MIN_PLAYERS = 2; + + Player(String name) { + this.name = name; + score = 0; + words = new ArrayList<>(); + } + + void updateScore(String word, float score) { + this.score += score; + words.add(word); + } + + String getName() { + return name; + } + + float getScore() { + return score; + } + + 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 new file mode 100644 index 0000000..10f39db --- /dev/null +++ b/GameEngine/src/engine/Statistics.java @@ -0,0 +1,94 @@ +package engine; + +import java.util.ArrayList; +import java.util.List; + +public class Statistics { + + private List players ; + private List letters; + private int numOfTurns; + private int leftBoxTiles; + private long playTime; + private Dictionary dict; + + public class PlayerData { + private Player player; + + private PlayerData(Player p) { + player = p; + } + + public String getName() { + return player.getName(); + } + + public List getWords() { + + return player.getWords(); + } + + public float getScore() { + return player.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(); + dict = gd.getDictionary(); + } + + public long getTime() { + return playTime; + } + + public int getNumOfTurns() { + return numOfTurns; + } + + 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; + } + + public List getLetters() { + return letters; + } +} \ No newline at end of file diff --git a/GameEngine/src/engine/Status.java b/GameEngine/src/engine/Status.java new file mode 100644 index 0000000..eeb312c --- /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 != null ? playerName : ""; + } + + public char[][] getBoard() { + return board; + } +} 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; + } +} diff --git a/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java new file mode 100644 index 0000000..e6b6ce3 --- /dev/null +++ b/GameEngine/src/engine/exceptions/DictionaryNotFoundException.java @@ -0,0 +1,16 @@ +package engine.exceptions; + +import java.io.FileNotFoundException; + +public class DictionaryNotFoundException extends FileNotFoundException { + private String fileName; + + public DictionaryNotFoundException (String fileName) { + super (); + this.fileName = fileName; + } + + public String getFileName() { + return fileName; + } +} diff --git a/GameEngine/src/engine/exceptions/DuplicateLetterException.java b/GameEngine/src/engine/exceptions/DuplicateLetterException.java new file mode 100644 index 0000000..e962b61 --- /dev/null +++ b/GameEngine/src/engine/exceptions/DuplicateLetterException.java @@ -0,0 +1,14 @@ +package engine.exceptions; + +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/NotEnoughLettersException.java b/GameEngine/src/engine/exceptions/NotEnoughLettersException.java new file mode 100644 index 0000000..477bf66 --- /dev/null +++ b/GameEngine/src/engine/exceptions/NotEnoughLettersException.java @@ -0,0 +1,20 @@ +package engine.exceptions; + + +public class NotEnoughLettersException extends Exception { + private int expectedAmount; + private int currentAmount; + + public NotEnoughLettersException(int expected, int current) { + this.currentAmount = current; + this.expectedAmount = expected; + } + + public int getExpectedAmount() { + return expectedAmount; + } + + public int getCurrentAmount() { + return currentAmount; + } +} 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/NotXmlFileException.java b/GameEngine/src/engine/exceptions/NotXmlFileException.java new file mode 100644 index 0000000..b074542 --- /dev/null +++ b/GameEngine/src/engine/exceptions/NotXmlFileException.java @@ -0,0 +1,12 @@ +package engine.exceptions; +import java.lang.String; +import java.lang.Throwable; + +/** + * Created by נוי on 24/04/2017. + */ +public class NotXmlFileException extends Exception { + + public NotXmlFileException () {} +} + 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; + } +} diff --git a/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java b/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java new file mode 100644 index 0000000..dc6d94d --- /dev/null +++ b/GameEngine/src/engine/exceptions/OutOfBoardBoundariesException.java @@ -0,0 +1,7 @@ +package engine.exceptions; + + +public class OutOfBoardBoundariesException extends Exception { + + public OutOfBoardBoundariesException() {} +} 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; + } +} diff --git a/GameEngine/src/engine/exceptions/WrongPathException.java b/GameEngine/src/engine/exceptions/WrongPathException.java new file mode 100644 index 0000000..6d65414 --- /dev/null +++ b/GameEngine/src/engine/exceptions/WrongPathException.java @@ -0,0 +1,6 @@ +package engine.exceptions; + +public class WrongPathException extends Exception { + + public WrongPathException () {} +} diff --git a/GameEngine/src/engine/jaxb/schema/SchemaBasedJAXBMain.java b/GameEngine/src/engine/jaxb/schema/SchemaBasedJAXBMain.java new file mode 100644 index 0000000..236dc28 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/SchemaBasedJAXBMain.java @@ -0,0 +1,46 @@ + +package engine.jaxb.schema; + + +//import examples.jaxb.schema.generated.Countries; + +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; +import javax.xml.bind.Unmarshaller; +import java.io.InputStream; + +public class SchemaBasedJAXBMain { + + 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"); + 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/jaxb/schema/generated/DynamicPlayers.java b/GameEngine/src/engine/jaxb/schema/generated/DynamicPlayers.java new file mode 100644 index 0000000..d99a154 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/DynamicPlayers.java @@ -0,0 +1,97 @@ + +package engine.jaxb.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/jaxb/schema/generated/GameDescriptor.java b/GameEngine/src/engine/jaxb/schema/generated/GameDescriptor.java new file mode 100644 index 0000000..c34fa23 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/GameDescriptor.java @@ -0,0 +1,148 @@ + +package engine.jaxb.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/jaxb/schema/generated/GameType.java b/GameEngine/src/engine/jaxb/schema/generated/GameType.java new file mode 100644 index 0000000..533858e --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/GameType.java @@ -0,0 +1,123 @@ + +package engine.jaxb.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/jaxb/schema/generated/Letter.java b/GameEngine/src/engine/jaxb/schema/generated/Letter.java new file mode 100644 index 0000000..518a460 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/Letter.java @@ -0,0 +1,111 @@ + +package engine.jaxb.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/jaxb/schema/generated/Letters.java b/GameEngine/src/engine/jaxb/schema/generated/Letters.java new file mode 100644 index 0000000..be3d394 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/Letters.java @@ -0,0 +1,91 @@ + +package engine.jaxb.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/jaxb/schema/generated/ObjectFactory.java b/GameEngine/src/engine/jaxb/schema/generated/ObjectFactory.java new file mode 100644 index 0000000..3357aa8 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/ObjectFactory.java @@ -0,0 +1,174 @@ +package engine.jaxb.schema.generated; + +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"); + + + + //engine.jaxb.schema.generated.ObjectFactory objectFactory = new engine.jaxb.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/jaxb/schema/generated/Player.java b/GameEngine/src/engine/jaxb/schema/generated/Player.java new file mode 100644 index 0000000..facbeb2 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/Player.java @@ -0,0 +1,120 @@ + +package engine.jaxb.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/jaxb/schema/generated/Players.java b/GameEngine/src/engine/jaxb/schema/generated/Players.java new file mode 100644 index 0000000..fd1fde2 --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/Players.java @@ -0,0 +1,71 @@ + +package engine.jaxb.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/jaxb/schema/generated/STGameType.java b/GameEngine/src/engine/jaxb/schema/generated/STGameType.java new file mode 100644 index 0000000..001ff0a --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/STGameType.java @@ -0,0 +1,48 @@ + +package engine.jaxb.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/jaxb/schema/generated/Structure.java b/GameEngine/src/engine/jaxb/schema/generated/Structure.java new file mode 100644 index 0000000..ee10ade --- /dev/null +++ b/GameEngine/src/engine/jaxb/schema/generated/Structure.java @@ -0,0 +1,155 @@ + +package engine.jaxb.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">
+ *       <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/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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.docx b/README.docx new file mode 100644 index 0000000..99ec094 Binary files /dev/null and b/README.docx differ