template for cards
This commit is contained in:
parent
eabc7dbaff
commit
cec32fa08a
6 changed files with 103 additions and 0 deletions
12
engine/core/card.js
Normal file
12
engine/core/card.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import Effect from './effect.js';
|
||||||
|
|
||||||
|
class Card {
|
||||||
|
constructor() {
|
||||||
|
/** @type {string} */
|
||||||
|
this.name;
|
||||||
|
/** @type {string} */
|
||||||
|
this.description;
|
||||||
|
/** @type {Effect} */
|
||||||
|
this.effect;
|
||||||
|
}
|
||||||
|
}
|
||||||
3
engine/core/effect.js
Normal file
3
engine/core/effect.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
class Effect {
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
|
import Board from './board.js';
|
||||||
|
import Team from './team.js';
|
||||||
|
import Stack from './stack.js';
|
||||||
|
|
||||||
class GameState {
|
class GameState {
|
||||||
constructor() {
|
constructor() {
|
||||||
/** @type {Board} */
|
/** @type {Board} */
|
||||||
this.board = new Board();
|
this.board = new Board();
|
||||||
|
/** @type {Stack} */
|
||||||
|
this.stack = new Stack();
|
||||||
/** @type {Team} */
|
/** @type {Team} */
|
||||||
this.whiteTeam = new Team("white");
|
this.whiteTeam = new Team("white");
|
||||||
/** @type {Team} */
|
/** @type {Team} */
|
||||||
|
|
|
||||||
29
engine/core/hand.js
Normal file
29
engine/core/hand.js
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
48
engine/core/stack.js
Normal file
48
engine/core/stack.js
Normal file
|
|
@ -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]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import Piece from './piece.js';
|
import Piece from './piece.js';
|
||||||
import PieceColor from './piece.js';
|
import PieceColor from './piece.js';
|
||||||
|
import Hand from './hand.js';
|
||||||
|
|
||||||
class Team {
|
class Team {
|
||||||
/**
|
/**
|
||||||
|
|
@ -11,6 +12,10 @@ class Team {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
/** @type {Piece} */
|
/** @type {Piece} */
|
||||||
this.king = king;
|
this.king = king;
|
||||||
|
/** @type {Hand} */
|
||||||
|
this.hand = new this.hand();
|
||||||
|
/** @type {boolean} */
|
||||||
|
this.hasMadeAction = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue