Implement turn-based gameplay with phase control and interactive card restrictions

This commit introduces a comprehensive turn-based system that controls when players can interact with cards. The changes include:

- Adding turnPhase state tracking with draw, player_play, and cpu_play phases
- Setting initial turn phase to player_play for proper game flow
- Implementing conditional logic in card interaction handlers (hover, click)
- Restricting all interactive card behaviors to only occur during the player's turn phase
- Updating documentation comments to reflect the new turn-based control system

These changes establish the foundation for a structured gameplay sequence where players can only play cards during their designated turn phase, preventing actions outside of proper game flow.
This commit is contained in:
Brian Fertig 2025-08-13 19:56:22 -06:00
parent a4931d491a
commit 63be7a337e
1 changed files with 20 additions and 2 deletions

View File

@ -142,7 +142,7 @@ function create() {
playerField: [], playerField: [],
opponentField: [], opponentField: [],
selectedCard: null, selectedCard: null,
turnPhase: 'draw', turnPhase: 'draw', // Possible phases: draw, player_play, cpu_play
currentPlayer: 'player' currentPlayer: 'player'
}; };
@ -168,6 +168,9 @@ function create() {
// Display the opponent's hand at the top of the screen (face down) // Display the opponent's hand at the top of the screen (face down)
displayOpponentHand.call(this); displayOpponentHand.call(this);
// Set initial turn phase to player play
this.gameState.turnPhase = 'player_play';
console.log('Game scene created successfully'); console.log('Game scene created successfully');
} }
@ -286,7 +289,7 @@ function displayOpponentHand() {
} }
/** /**
* Make a single card interactive with hover effects * Make a single card interactive with hover effects and turn-based control
*/ */
function addInteractiveCard(card, xPosition, yPosition, width, height) { function addInteractiveCard(card, xPosition, yPosition, width, height) {
const originalY = yPosition; const originalY = yPosition;
@ -298,6 +301,11 @@ function addInteractiveCard(card, xPosition, yPosition, width, height) {
// Add event listeners for hover effects // Add event listeners for hover effects
hitArea.on('pointerover', () => { hitArea.on('pointerover', () => {
// Only allow hover effects if it's the player's turn and phase
if (this.gameState.currentPlayer !== 'player' || this.gameState.turnPhase !== 'player_play') {
return;
}
// Only allow hover effects if the card is in hand (not already on field) // Only allow hover effects if the card is in hand (not already on field)
const isInHand = this.gameState.playerHand.includes(card); const isInHand = this.gameState.playerHand.includes(card);
if (isInHand && !card.isLocked) { if (isInHand && !card.isLocked) {
@ -322,6 +330,11 @@ function addInteractiveCard(card, xPosition, yPosition, width, height) {
}); });
hitArea.on('pointerout', () => { hitArea.on('pointerout', () => {
// Only allow hover effects if it's the player's turn and phase
if (this.gameState.currentPlayer !== 'player' || this.gameState.turnPhase !== 'player_play') {
return;
}
// Only allow hover effects if the card is in hand (not already on field) // Only allow hover effects if the card is in hand (not already on field)
const isInHand = this.gameState.playerHand.includes(card); const isInHand = this.gameState.playerHand.includes(card);
if (isInHand && !card.isLocked) { if (isInHand && !card.isLocked) {
@ -347,6 +360,11 @@ function addInteractiveCard(card, xPosition, yPosition, width, height) {
// Add click event to lock the card in place // Add click event to lock the card in place
hitArea.on('pointerdown', () => { hitArea.on('pointerdown', () => {
// Only allow clicking if it's the player's turn and phase
if (this.gameState.currentPlayer !== 'player' || this.gameState.turnPhase !== 'player_play') {
return;
}
// Only allow clicking if the card is in hand (not already on field) // Only allow clicking if the card is in hand (not already on field)
const isInHand = this.gameState.playerHand.includes(card); const isInHand = this.gameState.playerHand.includes(card);
if (isInHand) { if (isInHand) {