/** * @file Game.java * * @author Christos Choutouridis AEM:8997 * @email cchoutou@ece.auth.gr */ package net.hoo2.auth.labyrinth; /** * Main application class. This class is the only public interface of * the entire game. */ public class Game { Game() {} /**< An empty constructor */ /** * @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; /** @} */ /** * Main game loop */ public static void main(String[] args) { try { // Create a game, a board and 2 players. Game game = new Game(); Board board = new Board(11, 4, 82); Player T = new Player(1, "Theseus", board, 0); Player M = new Player(2, "Minotaur", board, Position.toID(3, 3)); // Populate data to the board board.createBoard(T.playerTileId(), M.playerTileId()); while (true) { int[] m; System.out.println(); System.out.println("Round: " + (game.getRound()+1)); m = T.move(T.playerTileId()); System.out.println(T.getName() + ":\t tileId =" + m[0] + " (" + m[1] + ", " + m[2] + ")"); m = M.move(M.playerTileId()); System.out.println(M.getName() + ":\t tileId =" + m[0] + " (" + m[1] + ", " + m[2] + ")"); board.printBoard( board.getStringRepresentation(T.playerTileId(), M.playerTileId()) ); // Termination cases if (T.getScore() == 4) { System.out.println(T.getName() + " Wins!!! Score =" + T.getScore()); System.exit(0); } if (M.getScore() == 4 || M.playerTileId() == T.playerTileId()) { System.out.println(M.getName() + " Wins!!! Score =" + M.getScore()); System.exit(0); } game.setRound(game.getRound()+1); if (!(game.getRound() < 100)) { System.out.println("New day has come... Tie!!!"); System.exit(0); } } } catch (Exception e) { System.out.println(e.getMessage()); System.exit(1); } } }