-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Card { | ||
constructor(name, power) { | ||
this.name = name; | ||
this.power = power; | ||
} | ||
|
||
render() { | ||
const cardElement = document.createElement('div'); | ||
cardElement.className = 'card'; | ||
cardElement.textContent = `${this.name} (${this.power})`; | ||
return cardElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Deck { | ||
constructor() { | ||
this.cards = []; | ||
} | ||
|
||
addCard(card) { | ||
this.cards.push(card); | ||
} | ||
|
||
drawCard() { | ||
return this.cards.length ? this.cards.pop() : null; | ||
} | ||
|
||
shuffle() { | ||
for (let i = this.cards.length - 1; i > 0; i--) { | ||
const j = Math.floor(Math.random() * (i + 1)); | ||
[this.cards[i], this.cards[j]] = [this.cards[j], this.cards[i]]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const rows = document.querySelectorAll('.row'); // Получаем все ряды | ||
|
||
// Создаем игроков | ||
const player1 = new Player('Player 1'); | ||
const player2 = new Player('Player 2'); | ||
|
||
// Создаем колоду и добавляем карты (12 карт) | ||
const deck = new Deck(); | ||
deck.addCard(new Card('Masik', 5)); | ||
deck.addCard(new Card('Tubik', 3)); | ||
deck.addCard(new Card('Skuf', 4)); | ||
deck.addCard(new Card('Altushka', 7)); | ||
deck.addCard(new Card('Sheikh', 6)); | ||
deck.addCard(new Card('Alkash', 4)); | ||
deck.addCard(new Card('ITishnik', 6)); | ||
deck.addCard(new Card('Fifa', 5)); | ||
deck.addCard(new Card('Vaper', 3)); | ||
deck.addCard(new Card('TikToker', 4)); | ||
deck.addCard(new Card('Khalif', 6)); | ||
deck.addCard(new Card('GameDev', 8)); | ||
deck.shuffle(); | ||
|
||
// Игроки берут по 6 карт | ||
for (let i = 0; i < 6; i++) { | ||
player1.drawCard(deck); | ||
player2.drawCard(deck); | ||
} | ||
|
||
// Рендеринг карт | ||
let cardIndex = 0; | ||
|
||
rows.forEach((row, rowIndex) => { | ||
console.log(`Рендеринг для ряда ${rowIndex + 1}`); | ||
for (let i = 0; i < 3; i++) { | ||
if (rowIndex < 2) { | ||
if (player1.hand[cardIndex]) { | ||
console.log(`Добавление карты ${player1.hand[cardIndex].name} для Player 1 в ряд ${rowIndex + 1}`); | ||
row.appendChild(player1.hand[cardIndex].render()); | ||
} | ||
} else { | ||
if (player2.hand[cardIndex - 6]) { | ||
console.log(`Добавление карты ${player2.hand[cardIndex - 6].name} для Player 2 в ряд ${rowIndex + 1}`); | ||
row.appendChild(player2.hand[cardIndex - 6].render()); | ||
} | ||
} | ||
cardIndex++; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Player { | ||
constructor(name) { | ||
this.name = name; | ||
this.hand = []; | ||
} | ||
|
||
drawCard(deck) { | ||
const card = deck.drawCard(); | ||
if (card) { | ||
this.hand.push(card); | ||
} | ||
} | ||
|
||
playCard(index) { | ||
if (index < this.hand.length) { | ||
return this.hand.splice(index, 1)[0]; | ||
} | ||
return null; | ||
} | ||
} |