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

Banker.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Banker.java 1.57 KiB
    package com.cm6123.monopoly.game;
    
    
    /**
     * Class for the banker as seen in the pro forma, banker gives money to players.
     */
    public class Banker {
        /**
         * The initial balance of the banker.
         */
        private static final int INITIAL_BALANCE = 5000;
    
        /**
         * The current balance of the banker.
         */
        private int balance;
    
        /**
         * Adds money to the banker's balance.
         *
         * @param amount The amount of money to add.
         */
        public void addMoney(final int amount) {
            balance += amount;
        }
    
        /**
         * Constructs a new Banker instance with the initial balance.
         */
        public Banker() {
            this.balance = INITIAL_BALANCE;
        }
    
        /**
         * Pays the player and money gets subtracted from the bankers initial balance.
         *
         * @param player The player to whom the money is being paid.
         * @param amount The amount of money to pay to the player.
         */
        public void payPlayerMoney(final Player player, final int amount) {
            player.addMoney(amount);
            this.balance -= amount;
        }
    
        /**
         * Checks if a player has passed 'Home' or tile 1, this method gets called in the application class.
         *
         * @param player The player whose position is being checked.
         */
        public void checkIfPlayerPassHome(final Player player) {
            if (player.getPosition() > 1) {
                payPlayerMoney(player, 0);
            }
        }
    
        /**
         * Retrieves the current balance of the banker.
         *
         * @return The current balance of the banker.
         */
        public int getBalance() {
            return balance;
        }
    }