Package loveletter
Class Action
- java.lang.Object
-
- loveletter.Action
-
public class Action extends java.lang.Object
An abstract class to represent actions in the game LoveLetter. The class is designed to be immutable.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Card
card()
the card of the actionCard
guess()
the announced guess for 1 cardsstatic Action
playBaron(int player, int target)
Constructs a BARON action for the player challenging another player.static Action
playCountess(int player)
Constructs a COUNTESS action for the player.int
player()
The player who did the actionstatic Action
playGuard(int player, int target, Card guess)
Constructs a GUARD action from the player guessing the targets card.static Action
playHandmaid(int player)
Constructs a HANDMAID action for the player.static Action
playKing(int player, int target)
Constructs a KING action for the player requiring swapping cards with the target.static Action
playPriest(int player, int target)
Constructs a PRIEST action for the player seeing the targets card.static Action
playPrince(int player, int target)
Constructs a PRINCE action for the player requiring the targetted player to discard their card and draw a new one.static Action
playPrincess(int player)
Constructs a PRINCESS action for the player.int
target()
the target of the action for 1,2,3,5,6 cardsjava.lang.String
toString()
java.lang.String
toString(java.lang.String player, java.lang.String target)
produces a string representation of the action
-
-
-
Method Detail
-
card
public Card card()
the card of the action- Returns:
- the card for the action
-
player
public int player()
The player who did the action- Returns:
- the player index who did the action
-
target
public int target()
the target of the action for 1,2,3,5,6 cards- Returns:
- the index of the taregtted player for 1,2,3,5,6 cards and -1 otherwise
-
guess
public Card guess()
the announced guess for 1 cards- Returns:
- the guessed card for GUARD actions, and null otherwise.
-
toString
public java.lang.String toString(java.lang.String player, java.lang.String target)
produces a string representation of the action- Returns:
- a string representation of the action
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
playGuard
public static Action playGuard(int player, int target, Card guess) throws IllegalActionException
Constructs a GUARD action from the player guessing the targets card.- Parameters:
player
- the player performing the actiontarget
- the player taregtted by this actionguess
- the card the player guesses- Returns:
- the action object
- Throws:
IllegalActionException
- if an illegal action.
-
playPriest
public static Action playPriest(int player, int target) throws IllegalActionException
Constructs a PRIEST action for the player seeing the targets card.- Parameters:
player
- the player performing the actiontarget
- the player taregtted by this action- Returns:
- the action object
- Throws:
IllegalActionException
- if an illegal action.
-
playBaron
public static Action playBaron(int player, int target) throws IllegalActionException
Constructs a BARON action for the player challenging another player.- Parameters:
player
- the player performing the actiontarget
- the player taregtted by this action- Returns:
- the action object
- Throws:
IllegalActionException
- if an illegal action.
-
playHandmaid
public static Action playHandmaid(int player) throws IllegalActionException
Constructs a HANDMAID action for the player.- Parameters:
player
- the player performing the action- Returns:
- the action object
- Throws:
IllegalActionException
-
playPrince
public static Action playPrince(int player, int target) throws IllegalActionException
Constructs a PRINCE action for the player requiring the targetted player to discard their card and draw a new one.- Parameters:
player
- the player performing the actiontarget
- the player taregtted by this action- Returns:
- the action object
- Throws:
IllegalActionException
-
playKing
public static Action playKing(int player, int target) throws IllegalActionException
Constructs a KING action for the player requiring swapping cards with the target.- Parameters:
player
- the player performing the actiontarget
- the player taregtted by this action- Returns:
- the action object
- Throws:
IllegalActionException
- if an illegal action.
-
playCountess
public static Action playCountess(int player) throws IllegalActionException
Constructs a COUNTESS action for the player.- Parameters:
player
- the player performing the action- Returns:
- the action object
- Throws:
IllegalActionException
- if the player is out of range
-
playPrincess
public static Action playPrincess(int player) throws IllegalActionException
Constructs a PRINCESS action for the player.- Parameters:
player
- the player performing the action- Returns:
- the action object
- Throws:
IllegalActionException
- if the player is out of range
-
-