From 8e8bc514ad39e58f5b500595c3d03c7382c73256 Mon Sep 17 00:00:00 2001 From: Brian Fertig Date: Tue, 12 Aug 2025 20:25:55 -0600 Subject: [PATCH] feat: Implement card data management with multiple decks - Added card-data.js file to define four different decks (Player default, Warrior, Mage, Archer) - Each deck contains 10 creature cards with randomized attack, shield, and health values - Updated index.html to load the new card data script before main.js - Modified main.js to initialize player deck using predefined deck1 instead of generating random cards - Removed old deck generation code from main.js --- index.html | 5 +++- src/card-data.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.js | 15 +++--------- 3 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 src/card-data.js diff --git a/index.html b/index.html index 798340a..2549c9b 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,10 @@ + + + - + diff --git a/src/card-data.js b/src/card-data.js new file mode 100644 index 0000000..5abfca5 --- /dev/null +++ b/src/card-data.js @@ -0,0 +1,61 @@ +// Card data definitions for different decks +// Each deck contains 10 cards with attack, shield, health and required-army-size attributes + +// Deck 1 - Player's default deck (will be assigned to player) +window.deck1 = [ + { id: 1, number: 1, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 2, number: 2, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 3, number: 3, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 4, number: 4, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 5, number: 5, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 6, number: 6, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 7, number: 7, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 8, number: 8, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 9, number: 9, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 10, number: 10, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 } +]; + +// Deck 2 - Warrior deck +window.deck2 = [ + { id: 1, number: 1, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 2, number: 2, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 3, number: 3, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 4, number: 4, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 5, number: 5, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 6, number: 6, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 7, number: 7, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 8, number: 8, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 9, number: 9, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 10, number: 10, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 } +]; + +// Deck 3 - Mage deck +window.deck3 = [ + { id: 1, number: 1, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 2, number: 2, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 3, number: 3, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 4, number: 4, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 5, number: 5, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 6, number: 6, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 7, number: 7, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 8, number: 8, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 9, number: 9, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 10, number: 10, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 } +]; + +// Deck 4 - Archer deck +window.deck4 = [ + { id: 1, number: 1, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 2, number: 2, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 3, number: 3, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 4, number: 4, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 5, number: 5, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 6, number: 6, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 7, number: 7, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 8, number: 8, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 9, number: 9, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 }, + { id: 10, number: 10, type: 'creature', attack: Math.floor(Math.random() * 5) + 1, shield: Math.floor(Math.random() * 5) + 1, health: Math.floor(Math.random() * 5) + 1, requiredArmySize: 1 } +]; + +// Make all decks available globally for the game +window.allDecks = [window.deck1, window.deck2, window.deck3, window.deck4]; diff --git a/src/main.js b/src/main.js index 6c575c6..ee8ed33 100644 --- a/src/main.js +++ b/src/main.js @@ -128,7 +128,7 @@ function create() { }); instructions.setOrigin(0.5); - // Initialize game state +// Initialize game state this.gameState = { playerDeck: [], opponentDeck: [], @@ -141,17 +141,8 @@ function create() { currentPlayer: 'player' }; - // Create a 10-card deck with numbers 1-10 - this.gameState.playerDeck = []; - for (let i = 1; i <= 10; i++) { - this.gameState.playerDeck.push({ - id: i, - number: i, - type: 'creature', // placeholder type - attack: Math.floor(Math.random() * 5) + 1, // random attack value - health: Math.floor(Math.random() * 5) + 1 // random health value - }); - } + // Assign the first deck (deck1) to the player + this.gameState.playerDeck = [...window.deck1]; // Shuffle the deck using Fisher-Yates algorithm (using Phaser's scope) shuffleDeck(this.gameState.playerDeck);