@@ -15,11 +15,11 @@
* Contains the main game logic
*/
public class GamePlay {
public static GameConfig gameConfig;
public static int round = 0;
public static Player currentPlayer;
private static GameConfig gameConfig;
private static int round = 0;
private static Player currentPlayer;
private static Queue<Player> playerOrder = new PriorityQueue<>();
public static int turnSeconds = 0;
private static int turnSeconds = 0;

/**
* Start the regular gameplay. Should be called at the end of land selection phase
@@ -117,8 +117,8 @@ private static boolean curPlayerHasLowScore() {
int lowScore = currentPlayer.getScore();

//Determine which player has the lowest score
for (int i = 0; i < GamePlay.gameConfig.getNumPlayers(); i++) {
if (GamePlay.gameConfig.players[i].getScore() < lowScore) {
for (int i = 0; i < gameConfig.getNumPlayers(); i++) {
if (gameConfig.getPlayers()[i].getScore() < lowScore) {
return false;
}
}
@@ -170,4 +170,32 @@ private static void calculateProduction() {
private static void initializePlayerOrder() {
playerOrder.addAll(Arrays.asList(gameConfig.getPlayers()).subList(0, gameConfig.getNumPlayers()));
}

public static GameConfig getGameConfig() {
return gameConfig;
}

public static void setGameConfig(GameConfig game) {
gameConfig = game;
}

public static int getRound() {
return round;
}

public static Player getCurrentPlayer() {
return currentPlayer;
}

public static void setCurrentPlayer(Player current) {
currentPlayer = current;
}

public static int getTurnSeconds() {
return turnSeconds;
}

public static void setTurnSeconds(int seconds) {
turnSeconds = seconds;
}
}
@@ -80,7 +80,7 @@ public enum Color {
private int smithoreMule;
private int crystiteMule;
private int numLand;
public PlayerTimer timer;
private PlayerTimer timer;
private int score;
/**
* Initialization of players. Sets race, color (which cannot
@@ -106,7 +106,7 @@ public Player(String name, Race race, Color color, int number) {
}

//initial resources amounts
if (GamePlay.gameConfig.getDifficulty() == GameConfig.Difficulty.BEGINNER) {
if (GamePlay.getGameConfig().getDifficulty() == GameConfig.Difficulty.BEGINNER) {
this.food = 8;
this.energy = 4;
this.smithore = 0;
@@ -115,7 +115,7 @@ public Player(String name, Race race, Color color, int number) {
this.energyMule = 0;
this.smithoreMule = 0;
this.crystiteMule = 0;
} else if (GamePlay.gameConfig.getDifficulty() == GameConfig.Difficulty.INTERMEDIATE) {
} else if (GamePlay.getGameConfig().getDifficulty() == GameConfig.Difficulty.INTERMEDIATE) {
this.food = 4;
this.energy = 2;
this.smithore = 0;
@@ -383,6 +383,10 @@ public int getScore() {
return this.score = money + 500*numLand + energy + food + smithore + crystite;
}

public PlayerTimer getTimer() {
return timer;
}

/**
* Compares one player to another
* @param other player to compare
@@ -19,7 +19,7 @@ public class PlayerTimer {
public PlayerTimer(Player current) {
this.current = current;
int food = current.getFood();
int round = GamePlay.round;
int round = GamePlay.getRound();
int time;
if (round > 0 && round < 5) {
if (food > 3) {
@@ -46,7 +46,7 @@ public PlayerTimer(Player current) {
time = 30;
}
}
GamePlay.turnSeconds = time;
GamePlay.setTurnSeconds(time);
ticker = new Timeline(new KeyFrame(Duration.seconds(1), ae -> increment()));
ticker.setCycleCount(Animation.INDEFINITE);
}
@@ -56,9 +56,9 @@ public PlayerTimer(Player current) {
*/
private void increment() {
elapsedTime++;
System.err.println("Time remaining: " + (GamePlay.turnSeconds - elapsedTime));
System.err.println("Time remaining: " + (GamePlay.getTurnSeconds() - elapsedTime));
// TODO: show remaining time on the game screen
if (elapsedTime >= GamePlay.turnSeconds) {
if (elapsedTime >= GamePlay.getTurnSeconds()) {
// TODO: Alert that player change is happening
ticker.stop();
GamePlay.nextPlayer();
@@ -69,7 +69,7 @@ private void increment() {
* @return time remaining in turn
*/
public int getRemainingTime() {
return GamePlay.turnSeconds - elapsedTime;
return GamePlay.getTurnSeconds() - elapsedTime;
}

/**
@@ -85,6 +85,6 @@ public void startTime() {
*/
public int stopTime() {
ticker.stop();
return GamePlay.turnSeconds - elapsedTime;
return GamePlay.getTurnSeconds() - elapsedTime;
}
}