You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.4 KiB

  1. /**
  2. * @file Game.java
  3. *
  4. * @author Christos Choutouridis AEM:8997
  5. * @email cchoutou@ece.auth.gr
  6. */
  7. package net.hoo2.auth.labyrinth;
  8. /**
  9. * Main application class. This class is the only public interface of
  10. * the entire game.
  11. */
  12. public class Game {
  13. Game() {} /**< An empty constructor */
  14. /**
  15. * @name Accessor/Mutator interface
  16. * @note
  17. * Please consider not to use mutator interface. Its the abstraction killer :(
  18. * We have added a bit of logic however, in order to make it a bit more safe.
  19. */
  20. /** @{ */
  21. int getRound() { return round; }
  22. void setRound (int round) { this.round = round; }
  23. /** @} */
  24. /** @name Game's data */
  25. /** @{ */
  26. private int round;
  27. /** @} */
  28. /**
  29. * Main game loop
  30. */
  31. public static void main(String[] args) {
  32. try {
  33. // Create a game, a board and 2 players.
  34. Game game = new Game();
  35. Board board = new Board(11, 4, 82);
  36. Player T = new Player(1, "Theseus", board, 0);
  37. Player M = new Player(2, "Minotaur", board, Position.toID(3, 3));
  38. // Populate data to the board
  39. board.createBoard(T.playerTileId(), M.playerTileId());
  40. while (true) {
  41. int[] m;
  42. System.out.println();
  43. System.out.println("Round: " + (game.getRound()+1));
  44. m = T.move(T.playerTileId());
  45. System.out.println(T.getName() + ":\t tileId =" + m[0] + " (" + m[1] + ", " + m[2] + ")");
  46. m = M.move(M.playerTileId());
  47. System.out.println(M.getName() + ":\t tileId =" + m[0] + " (" + m[1] + ", " + m[2] + ")");
  48. board.printBoard(
  49. board.getStringRepresentation(T.playerTileId(), M.playerTileId())
  50. );
  51. // Termination cases
  52. if (T.getScore() == 4) {
  53. System.out.println(T.getName() + " Wins!!! Score =" + T.getScore());
  54. System.exit(0);
  55. }
  56. if (M.getScore() == 4 || M.playerTileId() == T.playerTileId()) {
  57. System.out.println(M.getName() + " Wins!!! Score =" + M.getScore());
  58. System.exit(0);
  59. }
  60. game.setRound(game.getRound()+1);
  61. if (!(game.getRound() < 100)) {
  62. System.out.println("New day has come... Tie!!!");
  63. System.exit(0);
  64. }
  65. }
  66. }
  67. catch (Exception e) {
  68. System.out.println(e.getMessage());
  69. System.exit(1);
  70. }
  71. }
  72. }