Class CheckWinLoseComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.maingame.CheckWinLoseComponent
The CheckWinLoseComponent is responsible for determining if a player has won or lost the game.
It evaluates the player's current gold and compares it against win and loss thresholds that adjust
dynamically based on the current day of the game. This component is attached to the player entity
and listens for changes in the player's stats (e.g., gold) and day progression.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCheckWinLoseComponent
(int baseWinAmount, int baseLossThreshold) Constructs a new CheckWinLoseComponent with specified win and loss thresholds. -
Method Summary
Modifier and TypeMethodDescriptionChecks the current game state and returns one of the following values: - "WIN" if the player has enough gold to win after the final day - "LOSE" if the player's gold is below the loss threshold - "GAME_IN_PROGRESS" if the game is ongoing and no win/loss conditions have been metvoid
int
getAdjustedLossThreshold
(int currentDay) Calculates the adjusted loss threshold based on the current day.int
getAdjustedWinAmount
(int currentDay) Calculates the adjusted win amount based on the current day.boolean
hasLost
(int adjustedLossThreshold) Determines if the player has lost the game.boolean
hasWon
(int adjustedWinAmount) Determines if the player has won the game.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
CheckWinLoseComponent
public CheckWinLoseComponent(int baseWinAmount, int baseLossThreshold) Constructs a new CheckWinLoseComponent with specified win and loss thresholds. The component listens for the player creation event to retrieve the player's combat stats.- Parameters:
baseWinAmount
- The base amount of gold required to win on Day 1baseLossThreshold
- The base amount of gold below which the player loses on Day 1
-
-
Method Details
-
checkGameState
Checks the current game state and returns one of the following values: - "WIN" if the player has enough gold to win after the final day - "LOSE" if the player's gold is below the loss threshold - "GAME_IN_PROGRESS" if the game is ongoing and no win/loss conditions have been met- Returns:
- a string representing the current game state ("WIN", "LOSE", or "GAME_IN_PROGRESS")
-
getAdjustedWinAmount
public int getAdjustedWinAmount(int currentDay) Calculates the adjusted win amount based on the current day. The win amount increases as the game progresses, making it harder to win on later days.- Parameters:
currentDay
- The current day of the game- Returns:
- the adjusted win amount for the current day
-
getAdjustedLossThreshold
public int getAdjustedLossThreshold(int currentDay) Calculates the adjusted loss threshold based on the current day. The loss threshold increases as the game progresses, giving the player more room to lose on later days.- Parameters:
currentDay
- The current day of the game- Returns:
- the adjusted loss threshold for the current day
-
hasLost
public boolean hasLost(int adjustedLossThreshold) Determines if the player has lost the game. The player loses if their gold falls below the adjusted loss threshold for the current day.- Parameters:
adjustedLossThreshold
- The loss threshold for the current day- Returns:
- true if the player has less gold than the loss threshold, false otherwise
-
hasWon
public boolean hasWon(int adjustedWinAmount) Determines if the player has won the game. The player wins if their gold equals or exceeds the adjusted win amount for the current day.- Parameters:
adjustedWinAmount
- The win threshold for the current day- Returns:
- true if the player has equal or more gold than the win threshold, false otherwise
-
decreaseLoseThreshold
public void decreaseLoseThreshold()
-