Select Git revision
Banker.java
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;
}
}