Overview
ThePlayer class is the core game object that manages all aspects of a player’s state in Elemental Battlecards. It handles card drawing, playing cards to the field, fusion mechanics, and graveyard management.
Constructor
The player identifier (‘player1’ or ‘player2’)
The main game scene
Properties
The player’s unique identifier
Reference to the main game scene
The player’s deck instance
Manages the player’s elemental essences
Array of cards currently in the player’s hand
Array of 6 slots representing the battlefield. Each slot can contain a Card or be null
Array of card data objects (not sprites) that have been defeated
Counter for turns where the player hasn’t attacked
Methods
drawInitialHand()
Draws the initial hand of 4 cards at the start of the game.drawCard()
Draws a card from the deck and adds it to the hand. If the deck is empty, refills it from the graveyard.The card data object that was drawn, or null if no cards are available
instanceId using Phaser.Math.RND.uuid() when drawn, allowing it to be tracked throughout its lifecycle.
refillDeckFromGraveyard()
Moves all cards from the graveyard back to the deck and shuffles it. Called automatically when the deck is empty.playCardFromHand(instanceId, fieldIndex)
Moves a card from the hand to a specific slot on the battlefield.The unique instance ID of the card to play
The battlefield slot index (0-5)
The card that was played, or null if the operation failed
fuseCards(draggedIndex, targetIndex)
Fuses two cards on the battlefield. Both cards must be of the same type and level, and the level must be less than 3.The field index of the card being dragged
The field index of the target card
An object containing:
newCard: The fused card data with increased levelemptiedIndex: The field slot that was emptied (draggedIndex)
- Both cards must have the same
typeandlevel - Cards cannot be level 3 (max level)
- The new card occupies the target slot
- The dragged slot becomes empty
- A new
instanceIdis generated for the fused card
fuseFromHand(instanceId, targetIndex)
Fuses a card from the hand with a card on the battlefield.The instance ID of the card in the hand
The field index of the target card
The new fused card data, or null if fusion fails
addCardDataToGraveyard(cardData)
Adds a defeated card to the graveyard. Cards of level 2 or 3 are decomposed into their base level 1 components.The card data object to add to the graveyard
- Level 1: 1 card (2^0)
- Level 2: 2 cards (2^1)
- Level 3: 4 cards (2^2)