This project simulates a card-based game, employing object-oriented programming concepts. It features distinct modules to define card behaviors, manage game logic, and facilitate player interactions.
This module defines all card types and their unique abilities. Each card inherits from the base Cards class and provides specific implementations for its behavior.
Base class for all card types, encapsulating shared properties and methods like:
getManaCost(): Returns the mana cost of the card.getAttackPower(): Retrieves the attack power of the card.useAbility(target): Placeholder method to be overridden by subclasses to implement card-specific abilities.
Represents a card with a healing ability.
useAbility(target): Heals the specified target card, increasing its health.
A powerful card with a board-clearing ability.
useAbility(target): Eliminates all enemy cards on the field.
Buffs allied cards.
useAbility(target): Increases the attack power of all allied cards.
Specializes in healing allied cards.
useAbility(target): Heals all allied cards on the field.
A card focused on debuffing the strongest enemy card.
useAbility(target): Reduces the attack of the strongest enemy card.
Unique ability to swap its health with an enemy card.
useAbility(target): Exchanges health points with the specified target card.
Alters an enemy card's health and attack.
useAbility(target): Switches the attack and health values of the target card.
Inflicts a debilitating effect on enemy cards.
useAbility(target): Reduces the attack power of an enemy card.
This module orchestrates the game mechanics, handling the field, players, and match logic.
Entry point of the application. Initializes the game, sets up players and decks, and starts the matches.
Utility class for managing coordinate-based operations, likely related to the positioning of cards on the game board.
getX(),getY(): Accessors for coordinate values.
Manages a player's collection of cards.
shuffle(): Shuffles the deck to randomize card order.drawCard(): Draws a card from the deck for the player.
Represents the game board where cards are played.
placeCard(card, coords): Places a card at a specific position.removeCard(coords): Removes a card from the field.getCardAt(coords): Retrieves the card at a given position.
Represents a player in the game.
drawCard(): Adds a card to the player’s hand from their deck.playCard(card, coords): Plays a card from the hand onto the field.takeDamage(amount): Reduces the player's health by the specified amount.
Contains test cases or demonstrations for various game features.
Central class for simulating a match between two players.
- It initializes
FieldandPlayerobjects for managing the game board and the two players. - Players are instantiated using decks provided via input.
- Defines constants for player rows on the board (e.g.,
PLAYER2_FRONT_ROW,PLAYER1_BACK_ROW). - Includes a
MAX_MANAconstant, which likely represents the maximum mana a player can accumulate.
playerTurn: Tracks which player's turn it is.turnCounter: Counts the number of turns that have elapsed.gameEnded: Boolean flag indicating whether the game has concluded.
- Accepts an
Inputobject to initialize game components such as players and the field.
From the snippet, the class seems focused on coordinating player actions, managing turns, and monitoring the game's progression.
Prepares the match by:
- Setting the starting player.
- Selecting decks and heroes for both players.
- Shuffling decks using a provided seed.
- Drawing initial cards.
- Allocating initial mana to each player.
Executes setup tasks for each round:
- Updates mana for both players, capped at
MAX_MANA. - Draws one card for each player.
- Resets attack statuses on the field.
- Resets the "used" status of player heroes, allowing them to act in the new round.
Resets all match elements:
- Clears the game board.
- Resets player states (e.g., mana, cards, health).
- Resets the turn counter.
- Sets the
gameEndedflag tofalse.
Processes a list of actions for the match:
- Uses an
ObjectMapperto handle and log game events. - Iterates over
ActionsInputto perform specific game actions. - Returns results as an
ArrayNode, likely representing the outcomes of the actions.
- The
startGame()andstartRound()methods emphasize setting up and managing the state of the game and players. resetMatch()ensures the game can be replayed without lingering states.playing()is central to executing the match's logic, iterating through player actions and applying them to the game state.
The Match.java class serves as the core controller of the game's lifecycle, implementing mechanisms for state initialization, turn-based progression, and action execution in adherence to the game's rules. By leveraging encapsulated interactions with Player, Field, and Cards, it ensures consistent state management through methods such as startGame(), startRound(), and playing(). Its design integrates input parsing, resource management (e.g., mana allocation and card drawing), and gameplay logic, enabling systematic turn and round transitions.
The use of constants like MAX_MANA and specific row identifiers ensures a clear and efficient mapping of gameplay parameters. Additionally, the modularity provided by the playing() method, which processes actions dynamically, positions the class as a flexible and extensible component for future enhancements. Overall, Match.java demonstrates a rigorously defined structure that provides precise control over gameplay flow, making it a pivotal element in the system's architecture.