From 524988079fa4bd058504c9dd73311b36cf60cbe1 Mon Sep 17 00:00:00 2001 From: Christos Choutouridis Date: Sat, 24 Oct 2020 22:22:09 +0300 Subject: [PATCH] DEV: Player has a champion flag to indicate the supply pickup ability --- src/net/hoo2/auth/labyrinth/Board.java | 5 ++- src/net/hoo2/auth/labyrinth/Game.java | 56 +++++++++++++++++++------ src/net/hoo2/auth/labyrinth/Player.java | 27 +++++++----- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/net/hoo2/auth/labyrinth/Board.java b/src/net/hoo2/auth/labyrinth/Board.java index ea875aa..6d1eac1 100644 --- a/src/net/hoo2/auth/labyrinth/Board.java +++ b/src/net/hoo2/auth/labyrinth/Board.java @@ -395,8 +395,11 @@ class Board { int S = tiles[tileId].hasSupply(supplies); if (T && !M) return " T "; - else if (M && !T) return " M "; else if (T && M) return "T+M"; + else if (M) { + if (S == Const.noSupply) return " M "; + else return "M+s"; + } else if (S != Const.noSupply) return String.format("s%02d", S+1); else return " "; diff --git a/src/net/hoo2/auth/labyrinth/Game.java b/src/net/hoo2/auth/labyrinth/Game.java index e7e00f7..7842a88 100644 --- a/src/net/hoo2/auth/labyrinth/Game.java +++ b/src/net/hoo2/auth/labyrinth/Game.java @@ -7,17 +7,38 @@ package net.hoo2.auth.labyrinth; +import java.util.Scanner; + /** * Main application class. This class is the only public interface of * the entire game. */ public class Game { - Game() {} /**< An empty constructor */ + /**< 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 @@ -31,15 +52,14 @@ public class Game { /** @name Game's data */ /** @{ */ - private int round; + private int round; /**< Holds the round of the game */ + private Scanner scan; /**< Input handle used in interactive mode */ /** @} */ /** - * Main game loop + * Command line argument handler */ static boolean getArguments (String[] args) { - boolean ret = true; - for (int i =0 ; i */ int[] move(int id) { - // Init return array with the current data + // Initialize return array with the current data int[] ret = {id, Position.toRow(id), Position.toCol(id), Const.noSupply}; int diceDirection = board.dice(); // throw the dice @@ -71,8 +73,9 @@ class Player { ret[0] = next.getId(); // Update player's and return data ret[1] = y = next.getRow(); ret[2] = x = next.getCol(); - if ((ret[3] = board.tryPickSupply(next.getId())) != Const.noSupply) { - ++score; // keep score + // In case of a champion player, try also to pick a supply + if (champion && (ret[3] = board.tryPickSupply(next.getId())) != Const.noSupply) { + ++score; // keep score System.out.println(name + ":\t*Found a supply. [score: " + score + "]"); } } @@ -81,8 +84,11 @@ class Player { return ret; } + /** Utility to access player's tileID */ int playerTileId() { return Position.toID(y, x); } + /** Utility to access player's row position (row coordinate) */ int playerRow() { return y; } + /** Utility to access player's column position (column coordinate) */ int playerCol() { return x; } /** @} */ @@ -122,5 +128,6 @@ class Player { private int score; /**< The current score of the player */ private int x; /**< The column coordinate of the player on the board */ private int y; /**< The row coordinate of the player on the board */ + private boolean champion; /**< Champion indicate a player who plays against the Minotaur */ /** @} */ }