Skip to content
Snippets Groups Projects
Select Git revision
  • 49a7bfc13bc87c84dadacbd430404f5533011375
  • main default protected
  • submission-4
  • stage-4
  • submission-3
  • stage-3
  • submission-2
  • stage-2
  • submission-1
  • stage-1
  • log4j2-tidy
  • test-2
  • test-1
  • test-pitest-with-lower-versions
  • test-pitest-with-verbose
  • test-pitest-on-CI
  • tag-to-test-CI-2
  • tag-to-test-CI-1
  • full-release-CR
  • fix-syntax
  • multi-release-change
  • check-folder-structure
22 results

GameEndings.java

Blame
  • 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() + "!!!!");
                }
            }
        }