// Card object structure class Card { constructor(filename, red, green, yellow) { this.filename = filename; this.red = red; this.green = green; this.yellow = yellow; } // Initialize the deck of cards function createDeck() { let deck = []; // Add each card to the deck deck.push(new Card("mathtornado_c1.jpg", 16, 3, 7)); deck.push(new Card("mathtornado_c2.jpg", 7, 4, 8)); deck.push(new Card("mathtornado_c3.jpg", 11, 5, 6)); deck.push(new Card("mathtornado_c4.jpg", 8, 7, 2)); deck.push(new Card("mathtornado_c5.jpg", 5, 6, 11)); deck.push(new Card("mathtornado_c6.jpg", 1, 11, 6)); deck.push(new Card("mathtornado_c7.jpg", 11, 1, 5)); deck.push(new Card("mathtornado_c8.jpg", 9, 13, 8)); deck.push(new Card("mathtornado_c9.jpg", 8, 17, 14)); deck.push(new Card("mathtornado_c10.jpg", 5, 2, 8)); deck.push(new Card("mathtornado_c11.jpg", 10, 1, 6)); deck.push(new Card("mathtornado_c12.jpg", 12, 3, 11)); deck.push(new Card("mathtornado_c13.jpg", 13, 2, 16)); deck.push(new Card("mathtornado_c14.jpg", 6, 3, 18)); deck.push(new Card("mathtornado_c15.jpg", 4, 16, 4)); deck.push(new Card("mathtornado_c16.jpg", 2, 16, 3)); deck.push(new Card("mathtornado_c17.jpg", 3, 8, 1)); deck.push(new Card("mathtornado_c18.jpg", 4, 10, 7)); deck.push(new Card("mathtornado_c19.jpg", 14, 7, 3)); deck.push(new Card("mathtornado_c20.jpg", 18, 6, 10)); deck.push(new Card("mathtornado_c21.jpg", 7, 9, 3)); deck.push(new Card("mathtornado_c22.jpg", 17, 8, 2)); deck.push(new Card("mathtornado_c23.jpg", 2, 15, 8)); deck.push(new Card("mathtornado_c24.jpg", 15, 9, 5)); deck.push(new Card("mathtornado_c25.jpg", 5, 8, 13)); deck.push(new Card("mathtornado_c26.jpg", 8, 5, 15)); deck.push(new Card("mathtornado_c27.jpg", 10, 12, 2)); deck.push(new Card("mathtornado_c28.jpg", 1, 14, 4)); deck.push(new Card("mathtornado_c29.jpg", 3, 18, 1)); deck.push(new Card("mathtornado_c30.jpg", 6, 5, 13)); deck.push(new Card("mathtornado_c31.jpg", 2, 4, 12)); deck.push(new Card("mathtornado_c32.jpg", 7, 11, 17)); deck.push(new Card("mathtornado_c33.jpg", 3, 10, 7)); deck.push(new Card("mathtornado_c34.jpg", 6, 12, 16)); deck.push(new Card("mathtornado_c35.jpg", 16, 6, 9)); deck.push(new Card("mathtornado_c36.jpg", 16, 4, 7)); deck.push(new Card("mathtornado_c37.jpg", 2, 11, 10)); deck.push(new Card("mathtornado_c38.jpg", 14, 4, 9)); deck.push(new Card("mathtornado_c39.jpg", 12, 10, 17)); deck.push(new Card("mathtornado_c40.jpg", 7, 13, 4)); deck.push(new Card("mathtornado_c41.jpg", 6, 12, 12)); deck.push(new Card("mathtornado_c42.jpg", 4, 6, 16)); deck.push(new Card("mathtornado_c43.jpg", 15, 9, 12)); deck.push(new Card("mathtornado_c44.jpg", 9, 7, 14)); deck.push(new Card("mathtornado_c45.jpg", 13, 2, 5)); return deck; } // Function to shuffle the deck of cards function shuffleDeck(deck) { let currentIndex = deck.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (currentIndex !== 0) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = deck[currentIndex]; deck[currentIndex] = deck[randomIndex]; deck[randomIndex] = temporaryValue; } return deck; } function displayCards(playerHand, boardCards) { // Example of setting the src for board cards const boardCardElements = document.querySelectorAll('#board-cards .board-card'); boardCards.forEach((card, index) => { boardCardElements[index].src = `path/to/card/images/${card.filename}`; }); // Similar logic would be applied to display the player's hand } // Initialize the deck of cards function createDeck() { let deck = []; // Add each card to the deck // ... (Add all cards as previously listed) // The following is an example, please replace with actual card data deck.push(new Card("mathtornado_c1.jpg", 16, 3, 7)); // ... (Continue adding all the rest of the cards in a similar manner) deck.push(new Card("mathtornado_c45.jpg", 13, 2, 5)); return deck; } // Function to shuffle the deck of cards function shuffleDeck(deck) { let currentIndex = deck.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (currentIndex !== 0) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = deck[currentIndex]; deck[currentIndex] = deck[randomIndex]; deck[randomIndex] = temporaryValue; } return deck; } // Usage let deck = createDeck(); // Create a new deck shuffleDeck(deck); // Shuffle the deck // Now the deck is ready to be used in the game // Function to deal cards to the player and place cards on the board function dealCards(deck) { // Assuming the deck is already shuffled const playerHand = deck.slice(0, 5); // Take the first 5 cards for the player const boardCards = deck.slice(5, 8); // Take the next 3 cards for the board // Add the Plus_Minus and Equals cards to the board in the correct positions boardCards.splice(1, 0, new Card("plus_minus.jpg", 0, 0, 0)); // Insert at index 1 boardCards.splice(3, 0, new Card("gleichheitszeichen.jpg", 0, 0, 0)); // Insert at index 3 return { playerHand, boardCards }; } // Function to display the cards on the UI // This is a placeholder function, you'll need to implement the actual rendering logic function displayCards(playerHand, boardCards) { // Render the player's hand // ... // Render the board cards // ... } // The main game setup function function setupGame() { const deck = createDeck(); // Create and initialize the deck shuffleDeck(deck); // Shuffle the deck const { playerHand, boardCards } = dealCards(deck); // Deal the cards displayCards(playerHand, boardCards); // Display the cards on the UI } // Call setupGame to start the game setupGame(); function dealCards(deck) { // Assuming the deck is already shuffled const playerHand = deck.slice(0, 5); // Take the first 5 cards for the player const boardCards = deck.slice(5, 8); // Take the next 3 cards for the board // Add the Plus_Minus and Equals cards to the board in the correct positions boardCards.splice(1, 0, new Card("plus_minus.jpg", 0, 0, 0)); // Insert at index 1 boardCards.splice(3, 0, new Card("gleichheitszeichen.jpg", 0, 0, 0)); // Insert at index 3 return { playerHand, boardCards }; }