Package dev.davwheat
Class Animal
- java.lang.Object
-
- dev.davwheat.BoardSpace
-
- dev.davwheat.Animal
-
public class Animal extends BoardSpace
Class that represents an Animal, which is a space on the GameBoard.
-
-
Field Summary
Fields Modifier and Type Field Description double
purchaseCost
The cost of the Animal to buy.double[]
stopCosts
The cost to stop on this Animal for each level.double
upgradeCost
The cost to upgrade the Animal to the next level.-
Fields inherited from class dev.davwheat.BoardSpace
displayName, index, isOwnable, type
-
-
Method Summary
Modifier and Type Method Description AnimalLevel
getCurrentLevel()
Gets the current level of this Animal.Player
getOwner()
Gets the owner of this animaldouble
getStopCost(Player actor)
Get the cost for the provided Player to stop on this Animal's BoardSpace.boolean
isOwnedBy(Player actor)
Tests if the provided Player owns this animal.boolean
isUpgradable(Player actor)
Determines whether the Animal is upgradable by the specified Player.void
payForStop(Player actor)
Charge to provided Player for stopping on this Animal.void
printCard()
Prints a visual representation of the card to stdout.void
purchase(Player actor)
Attempts to purchase the Animal and make it owned by the Player.void
upgrade(Player actor)
Attempts to upgrade an Animal to the next level.
-
-
-
Field Detail
-
purchaseCost
public final double purchaseCost
The cost of the Animal to buy.
-
upgradeCost
public final double upgradeCost
The cost to upgrade the Animal to the next level.
-
stopCosts
public final double[] stopCosts
The cost to stop on this Animal for each level.Contains indexes 0 to 3 (inclusive) for Levels 0 to 3.
-
-
Constructor Detail
-
Animal
public Animal(java.lang.String name, double cost, double upgradeCost, double[] stopCosts, int index, Game game)
Create a new instance of the Animal class.- Parameters:
name
- Name of the Animal shown to Players.cost
- The cost to buy the Animal.upgradeCost
- The cost to upgrade the Animal.stopCosts
- An array of 4 costs for stopping on the Animal (Level 0 - 3).index
- Where the Animal is on the GameBoard.game
- The instance of Game that this Animal belongs to.
-
-
Method Detail
-
getOwner
public Player getOwner()
Gets the owner of this animal- Returns:
- Animal's owner
-
getStopCost
public double getStopCost(Player actor)
Get the cost for the provided Player to stop on this Animal's BoardSpace.- Parameters:
actor
- The player- Returns:
- The cost for this player to stop on this animal
-
payForStop
public void payForStop(Player actor) throws InsufficientBalanceException
Charge to provided Player for stopping on this Animal.- Parameters:
actor
- Player- Throws:
InsufficientBalanceException
-
purchase
public void purchase(Player actor) throws AnimalAlreadyOwnedException, InsufficientBalanceException
Attempts to purchase the Animal and make it owned by the Player.Also handles the charging of the purchase cost.
- Parameters:
actor
- Person buying the Animal- Throws:
AnimalAlreadyOwnedException
- Animal is already owned by another player.InsufficientBalanceException
-
upgrade
public void upgrade(Player actor) throws AnimalNotOwnedException, javax.naming.NoPermissionException, AnimalUpgradeNotAllowedException, InsufficientBalanceException
Attempts to upgrade an Animal to the next level.You should always try to check if the Animal can be upgraded first using `Animal.isUpgradable(player)`.
- Parameters:
actor
- The Player attempting to upgrade the Animal.- Throws:
AnimalNotOwnedException
- Thrown when the Animal isn't owned.javax.naming.NoPermissionException
- Thrown when a Player other than the Animal owner attempts to upgrade the Animal.AnimalUpgradeNotAllowedException
- Thrown when an Animal is already at the maximum level.InsufficientBalanceException
-
isUpgradable
public boolean isUpgradable(Player actor)
Determines whether the Animal is upgradable by the specified Player.- Parameters:
actor
- Player attempting the upgrade- Returns:
- Whether the Player can upgrade the Animal
-
isOwnedBy
public boolean isOwnedBy(Player actor)
Tests if the provided Player owns this animal.- Parameters:
actor
- The player- Returns:
- If the player owns the animal
-
printCard
public void printCard()
Prints a visual representation of the card to stdout.
-
getCurrentLevel
public AnimalLevel getCurrentLevel()
Gets the current level of this Animal.- Returns:
- the level
-
-