/** * @file Game.java * * @author * Anastasia Foti AEM:8959 * * * @author * Christos Choutouridis AEM:8997 * */ /** * @mainpage A labyrinth board game * * This is a console game, played by 2 players. The Theseus and Minotaur. * The Minotaur goal is to capture Theseus. The Theseus's goal is to collect * all the supplies of the board before Minotaur catches him and before the * game ends. * * In this 3rd assignment we deal with the creation of a new minimax player * who can cheat and manipulate the dice. Documented classes: * - Tile * - Supply * - Board * - Player * - HeuristicPlayer * - MinMaxPlayer * - Game * * Which are the requested classes. We also provide some extra functionalities in: * - Const * - Session * - Direction * - DirRange * - Edge * - Graph * - Position * - Range * - ShuffledRange */ package host.labyrinth; import java.util.Scanner; /** * Main application class. This class is the only public interface of * the entire game. */ public class Game { /**< An empty constructor */ Game() { scan = new Scanner(System.in); } /** @name Player main application interface */ /** @{ */ /** Utility to get current round of the game */ int round () { return round; } /** Utility to increase and get the increased round of the game */ int nextRound() { return ++round; } /** * Utility to hold the execution of the program waiting for user input. * This is true only if the user passed the interactive flag. */ void waitUser () { if(Session.interactive) { System.out.println("Press enter to continue..."); scan.nextLine(); } } /** @{ */ /** * @name Accessor/Mutator interface * @note * Please consider not to use mutator interface. Its the abstraction killer :( * We have added a bit of logic however, in order to make it a bit more safe. */ /** @{ */ int getRound() { return round; } void setRound (int round) { this.round = round; } /** @} */ /** @name Game's data */ /** @{ */ private int round; /**< Holds the round of the game */ private Scanner scan; /**< Input handle used in interactive mode */ /** @} */ /** * Command line argument handler */ static boolean getArguments (String[] args) { for (int i =0 ; i] [-s|--supplies ] [-r|--rounds ] [--norooms] [-i|--interactive]"); System.out.println("or"); System.out.println("labyrinth -h|--help"); System.out.println("\nOptions\n"); System.out.println("-b | --board:\n Sets the size of board's edge.\n"); System.out.println("-s | --supplies:\n Sets the number of supplies on the board.\n"); System.out.println("-r | --rounds:\n Sets the maximum number of rounds of the game.\n"); System.out.println("--norooms:\n Prevents the creation of closed rooms inside the board.\n"); System.out.println("-i | --interactive:\n Each round requires user input in order to continue.\n"); System.out.println("-h | --help:\n Print this and exits."); return false; } } return true; } /** * Main game loop */ public static void main(String[] args) { try { // Get command line options if (!Game.getArguments(args)) throw new Exception(""); // Create a game, a board and 2 players. Game game = new Game(); Board board = new Board(Session.boardSize, Session.supplySize); Player T = new MinMaxPlayer("Theseus", true, board, 0); Player M = new Player("Minotaur", false, board, Position.toID(Session.boardSize/2, Session.boardSize/2)); Player players [] = {M, T}; // Populate data to the board board.createBoard(T.playerTileId(), M.playerTileId()); // Initial board printout System.out.println("Initial board: " + (game.round())); board.printBoard( board.getStringRepresentation(T.playerTileId(), M.playerTileId()) ); game.waitUser (); // Main game loop while (true) { System.out.println(); System.out.println("Round: " + (game.round()+1)); // Players moves for (Player p : players) { p.move(p.playerTileId()); p.statistics(); } board.printBoard( board.getStringRepresentation(T.playerTileId(), M.playerTileId()) ); // Loop termination cases if (T.getScore() == Session.supplySize) { System.out.println("**** " + T.getName() + " Wins!!! Score =" + T.getScore() + " ****"); break; } if (M.playerTileId() == T.playerTileId()) { System.out.println("**** " + M.getName() + " Wins!!!"); break; } if (!(game.nextRound() < Session.maxRounds)) { System.out.println("**** New day has come... Tie! ****"); break; } game.waitUser (); } for (Player p : players) p.final_statistics(); System.exit(0); } catch (Exception e) { // We don't handle exceptions. Print error and exit with error status. System.out.println(e.getMessage()); System.exit(1); } } }