diff --git a/engine/core/card.js b/engine/core/card.js new file mode 100644 index 0000000..e844232 --- /dev/null +++ b/engine/core/card.js @@ -0,0 +1,12 @@ +import Effect from './effect.js'; + +class Card { + constructor() { + /** @type {string} */ + this.name; + /** @type {string} */ + this.description; + /** @type {Effect} */ + this.effect; + } +} \ No newline at end of file diff --git a/engine/core/effect.js b/engine/core/effect.js new file mode 100644 index 0000000..6daf046 --- /dev/null +++ b/engine/core/effect.js @@ -0,0 +1,3 @@ +class Effect { + constructor() {} +} \ No newline at end of file diff --git a/engine/core/game_state.js b/engine/core/game_state.js index 2f7b404..50c77b4 100644 --- a/engine/core/game_state.js +++ b/engine/core/game_state.js @@ -1,7 +1,13 @@ +import Board from './board.js'; +import Team from './team.js'; +import Stack from './stack.js'; + class GameState { constructor() { /** @type {Board} */ this.board = new Board(); + /** @type {Stack} */ + this.stack = new Stack(); /** @type {Team} */ this.whiteTeam = new Team("white"); /** @type {Team} */ diff --git a/engine/core/hand.js b/engine/core/hand.js new file mode 100644 index 0000000..8d6fe7d --- /dev/null +++ b/engine/core/hand.js @@ -0,0 +1,29 @@ +import Card from './card.js'; + +class Hand { + constructor() { + /** @type {Array(Card)} */ + this.cards = []; + } + + /** + * @param {Card} card + */ + pushCard(card) { + this.cards.push(card); + } + + /** + * @param {number} index + * @returns {Card|null} + */ + popCard(index) { + if (index < 0 || index >= this.cards.length) { + return null; + } else { + let c = this.cards.at(index); + this.cards.splice(index, 1); + return c; + } + } +} \ No newline at end of file diff --git a/engine/core/stack.js b/engine/core/stack.js new file mode 100644 index 0000000..ef10304 --- /dev/null +++ b/engine/core/stack.js @@ -0,0 +1,48 @@ +import Card from './card.js'; + +class Stack { + constructor() { + /** @type {Array(Card)} */ + this.stack; + /** @type {Array{Card}} */ + this.discard; + } + + /** + * @returns {Card|null} + */ + drawACard() { + if (this.stack.length > 0) { + return this.stack.pop(); + } else { + if (this.discard.length == 0) { + return null; + } + while (this.discard.length > 0) { + let randomIndex = Math.floor(Math.random() * this.discard.length); + this.stack.push(this.discard.at(randomIndex)); + this.stack.splice(randomIndex, 1); + } + return this.stack.pop(); + } + } + + /** + * + * @param {card} card + */ + discardACard(card) { + this.discard.push(card); + } + + /** + * @description Shuffle the stack + */ + shuffle() { + let index = this.stack.length - 1; + while (index > 0) { + let randomIndex = Math.floor(Math.random() * index); + [this.stack[index], this.stack[randomIndex]] = [this.stack[randomIndex], this.stack[index]]; + } + } +} \ No newline at end of file diff --git a/engine/core/team.js b/engine/core/team.js index e246adf..a69d3e4 100644 --- a/engine/core/team.js +++ b/engine/core/team.js @@ -1,5 +1,6 @@ import Piece from './piece.js'; import PieceColor from './piece.js'; +import Hand from './hand.js'; class Team { /** @@ -11,6 +12,10 @@ class Team { this.color = color; /** @type {Piece} */ this.king = king; + /** @type {Hand} */ + this.hand = new this.hand(); + /** @type {boolean} */ + this.hasMadeAction = false; } /**