Select Git revision
GameEndings.java
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
GameEndings.java 1.59 KiB
package com.cm6123.monopoly.game;
import java.util.ArrayList;
/**
* Class for GameEndings if round max reach and declare winner.
*/
public final class GameEndings {
private GameEndings() {}
/**
* Checks if the round inputed by the user has reached the number of rounds.
*
* @param round The current round number, rounds start at 1.
* @param numberOfRounds The number of rounds the user wants.
* @return true if the round has reached or exceeded the maximum number of rounds, false otherwise.
*/
public static boolean checkRoundsReached (final int round, final int numberOfRounds){
if (round >= numberOfRounds) {
System.out.println("Game over! Max rounds reached");
return true;
}
return false;
}
/**
* Determines the winner by checking which player has the most money.
* Prints out the winner's name and money amount.
*
* @param players The list of players in the game.
*/
public static void determineWinner (final ArrayList<Player> players){
Player winner = null;
int maxMoney = 0;
for (Player player : players) {
if (player.getMoney() > maxMoney) {
maxMoney = player.getMoney();
winner = player;
}
}
if (winner != null) {
System.out.println("The winner is... " + winner.getName() + " with £" + winner.getMoney() + "!!!!");
}
}
}