Package game

Class Game

java.lang.Object
game.Game

public class Game extends Object
This class is responsible for setting up and managing the game flow of the Pokémon Trading Card Game emulation. It handles the game setup, player actions, turn management, and win conditions.
Version:
1.0
Author:
Tyler Mong
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
    A string used to store the result of the coin flip to determine who goes first.
    private Player
    A reference to the current player whose turn it is.
    private static final Scanner
    A Scanner object used to read user input from the console.
    private boolean
    A flag used to indicate if the current player's turn is over.
    private Player
    A reference to the opponent player, who is not currently taking their turn.
    private Player
    A reference to the first player in the game.
    private Player
    A reference to the second player in the game.
    private boolean
    A flag used to indicate if the player has completed the action of attaching an Energy card to a Pokémon this turn.
    private boolean
    A flag used to indicate if the player has completed the action of retreating their Active Pokémon this turn.
  • Constructor Summary

    Constructors
    Constructor
    Description
    A constructor to initialize the game with two players and their decks.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Sets the player's Benched Pokémon.
    private void
    Adds 6 cards to the player's Prize pile.
    private boolean
    attachEnergy(Player currentPlayer)
    Handles attaching energy to a Pokémon.
    private boolean
    Checks the following win condition: If the opponent has taken all of their prize cards.
    private boolean
    Checks the following win condition: If the current player has no Pokémon in play (both active and bench).
    private boolean
    Checks the following win condition: If the opponent has no cards left in their deck at the beginning of their turn.
    private EnergyCard
    Helper method to create an Energy card based on the given type.
    private String
    Simulates a coin flip.
    private void
    handleBonusDraws(Player currentPlayer, int opponentMulliganCount)
    Handles the bonus draws for the current player based on the opponent's Mulligan count.
    private void
    handleKnockout(Player currentPlayer, Player opponent)
    Handles the knockout of a Pokémon after an attack.
    private void
    Handles the case of the current player having no Active Pokémon, at the end of their opponent's turn.
    private boolean
    Checks if the game is over by evaluating the win conditions at the start of each turn.
    private void
    playTrainerCard(Player currentPlayer)
    Handles playing a Trainer card.
    private boolean
    Handles retreating the Active Pokémon to the Bench.
    private void
    This method handles deck selection for each player.
    private void
    Sets the player's Active Pokémon.
    void
    Sets up the game by following the "Setting up to Play" sequence found in the official Pokémon TCG: Sun & Moon—Celestial Storm rulebook.
    private void
    showCardStats(Player currentPlayer)
    Displays the stats of a selected Pokémon card.
    private void
    Helper method to display the stats of a selected Pokémon card.
    private void
    sleep(int ms)
    Helper method to call Thread.sleep() and handle the InterruptedException.
    void
    Starts the game by following the "Parts of a Turn" sequence found in the official Pokémon TCG: Sun & Moon—Celestial Storm rulebook.
    private int
    Checks if the player's hand contains any Basic Pokémon cards.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • player1

      private Player player1
      A reference to the first player in the game.
    • player2

      private Player player2
      A reference to the second player in the game.
    • currentPlayer

      private Player currentPlayer
      A reference to the current player whose turn it is. This player will take actions during their turn.
    • opponent

      private Player opponent
      A reference to the opponent player, who is not currently taking their turn. This player will be affected by the current player's actions.
    • coin

      private String coin
      A string used to store the result of the coin flip to determine who goes first.
    • in

      private static final Scanner in
      A Scanner object used to read user input from the console.
    • playerHasCompletedAction2ThisTurn

      private boolean playerHasCompletedAction2ThisTurn
      A flag used to indicate if the player has completed the action of attaching an Energy card to a Pokémon this turn. This is used to prevent multiple Energy attachments in a single turn.
    • playerHasCompletedAction4ThisTurn

      private boolean playerHasCompletedAction4ThisTurn
      A flag used to indicate if the player has completed the action of retreating their Active Pokémon this turn. This is used to prevent multiple retreats in a single turn.
    • isTurnOver

      private boolean isTurnOver
      A flag used to indicate if the current player's turn is over. This is set to true when the player has attacked and ended their turn.
  • Constructor Details

    • Game

      public Game()
      A constructor to initialize the game with two players and their decks.
  • Method Details

    • setupGame

      public void setupGame()
      Sets up the game by following the "Setting up to Play" sequence found in the official Pokémon TCG: Sun & Moon—Celestial Storm rulebook. This setup includes the following steps: (1) shaking hands, (2) flipping a coin to determine who goes first, (3) shuffling decks and drawing cards, (4) checking for Basic Pokémon in hand, (5) selecting an Active Pokémon, (6) selecting Bench Pokémon, and (7) placing Prize cards.
      See Also:
    • selectDeck

      private void selectDeck(Player player)
      This method handles deck selection for each player. It displays the prebuilt decks, prompts for selection, validates the selection, and assigns the selected deck to the player.
      Parameters:
      player - The player who is selecting a deck.
    • flipCoin

      private String flipCoin()
      Simulates a coin flip.
      Returns:
      The result of the coin flip, either "Heads" or "Tails".
    • validateHand

      private int validateHand(Player player)
      Checks if the player's hand contains any Basic Pokémon cards. If not, the player must reveal their hand, return all cards to their deck, shuffle it, and draw 7 new cards. This process is repeated until the player has at least one Basic Pokémon in their hand.
      Parameters:
      player - The player whose hand is being validated.
      Returns:
      The number of Mulligans (invalid hands) the player had before getting a valid hand.
    • handleBonusDraws

      private void handleBonusDraws(Player currentPlayer, int opponentMulliganCount)
      Handles the bonus draws for the current player based on the opponent's Mulligan count.
      Parameters:
      currentPlayer - The player drawing bonus cards.
      opponentMulliganCount - The player's opponent's Mulligan count.
    • setActivePokemon

      private void setActivePokemon(Player player)
      Sets the player's Active Pokémon. Prompts the player to select a Basic Pokémon from their hand, validates the selection, and moves the selected card to the Active position.
      Parameters:
      player - The player selecting an Active Pokémon.
    • addBenchPokemon

      private void addBenchPokemon(Player player)
      Sets the player's Benched Pokémon. Prompts the player to select Basic Pokémon from their hand, validates the selections, and moves the selected cards to the Bench.
      Parameters:
      player - The player selecting Benched Pokémon.
    • addPrizePokemon

      private void addPrizePokemon(Player player)
      Adds 6 cards to the player's Prize pile. This method is called during the game setup in order to setup the Prize pile for each player.
      Parameters:
      player - The player who is adding cards to their Prize pile.
    • startGame

      public void startGame()
      Starts the game by following the "Parts of a Turn" sequence found in the official Pokémon TCG: Sun & Moon—Celestial Storm rulebook. This includes (1) drawing a card, (2) performing actions (putting Basic Pokémon on Bench, attaching Energy cards, playing Trainer cards, and retreating Active Pokémon), and (3) attacking and ending the turn.
      See Also:
    • isGameOver

      private boolean isGameOver()
      Checks if the game is over by evaluating the win conditions at the start of each turn. The following win conditions are checked: (1) If the current player has taken all of their Prize cards, (2) if the opponent has no Pokémon in play (both active and bench), and (3) if the opponent has no cards left in their deck at the beginning of their turn.
      Returns:
      True if any of the win conditions are met, false otherwise.
    • checkWinCondition1

      private boolean checkWinCondition1()
      Checks the following win condition: If the opponent has taken all of their prize cards. The opponent is checked as they are the player who just had their turn (since this is checked at the start of a turn, after the roles have switched).
      Returns:
      True if the opponent has no Prize cards left, false otherwise.
    • checkWinCondition2

      private boolean checkWinCondition2()
      Checks the following win condition: If the current player has no Pokémon in play (both active and bench). The current player is checked as they are the player who just had their turn (since this is checked at the start of a turn, after the roles have switched).
      Returns:
      True if the current player has no Pokémon in play, false otherwise.
    • checkWinCondition3

      private boolean checkWinCondition3()
      Checks the following win condition: If the opponent has no cards left in their deck at the beginning of their turn. The opponent is checked as they are the player who just had their turn (since this is checked at the start of a turn, after the roles have switched).
      Returns:
      True if the opponent has no cards left in their deck, false otherwise.
    • handleKnockout

      private void handleKnockout(Player currentPlayer, Player opponent)
      Handles the knockout of a Pokémon after an attack. This method is called when a Pokémon is knocked out by an attack. It moves the knocked out Pokémon to the discard pile and has current player draw a prize card.
      Parameters:
      currentPlayer - The attacking player who knocked out the opponent's Pokémon.
      opponent - The defending player whose Pokémon was knocked out.
    • handleNoActivePokemon

      private void handleNoActivePokemon(Player currentPlayer)
      Handles the case of the current player having no Active Pokémon, at the end of their opponent's turn.
      Parameters:
      currentPlayer - The player who has no Active Pokémon.
    • attachEnergy

      private boolean attachEnergy(Player currentPlayer)
      Handles attaching energy to a Pokémon. This method prompts for Pokémon selection, validates the selection, prompts for Energy selection, validates the selection, and attaches the selected Energy card to the selected Pokémon.
      Parameters:
      currentPlayer - The player who is attaching an Energy card to a Pokémon.
      Returns:
      True if an Energy card was attached, false otherwise.
    • playTrainerCard

      private void playTrainerCard(Player currentPlayer)
      Handles playing a Trainer card. This method prompts the player to select a Trainer card, validates the selection, and uses the effect of the card.
      Parameters:
      currentPlayer - The player playing a Trainer card.
    • retreatActivePokemon

      private boolean retreatActivePokemon(Player currentPlayer)
      Handles retreating the Active Pokémon to the Bench. This method prompts the player for confirmation, validates if they can retreat, and allows them to select a card to switch with.
      Parameters:
      currentPlayer - The player who is retreating their Active Pokémon.
      Returns:
      True if the retreat was successful, false otherwise.
    • createEnergyCard

      private EnergyCard createEnergyCard(String energyType)
      Helper method to create an Energy card based on the given type. This method is used to create an Energy card when discarding energy during a retreat.
      Parameters:
      energyType - The type of Energy card to create (e.g., "Grass", "Fire", etc.).
      Returns:
      The created Energy card.
    • showCardStats

      private void showCardStats(Player currentPlayer)
      Displays the stats of a selected Pokémon card. This method prompts the player to select a pile (Active or Bench), validates the selection, and displays the stats of the selected Pokémon card, including HP, Moves, Weakness, Resistance, and Energy attached.
      Parameters:
      currentPlayer - The player selecting a Pokémon card to view stats for.
    • showCardStatsHelper

      private void showCardStatsHelper(PokemonCard selectedPokemon)
      Helper method to display the stats of a selected Pokémon card. This method prints the HP, Moves, Weakness, Resistance, Energy attached, and Retreat Cost of the selected Pokémon card.
      Parameters:
      selectedPokemon - The Pokémon to display stats for.
    • sleep

      private void sleep(int ms)
      Helper method to call Thread.sleep() and handle the InterruptedException. Used to pause the game, allowing the player's to more easily read the text output in the console.
      Parameters:
      ms - The number of milliseconds to sleep for.
      Throws:
      InterruptedException - If the sleep is interrupted.