import BasicCanvas from './basic_canvas.js'; import Human from './human.js'; import Bot from './bot.js'; import Card from './card.js'; /* Images */ export default class Room extends BasicCanvas { constructor(name) { super(); this._name = name; this._players = []; this._cards = []; this._used_cards = []; // Fill room name this._ctx.font = "32px Arial"; this._ctx.fillText(name, 10, 10); } addHuman(name) { this._players.push( new Human(name, this._players.length) ); console.log(this._players); } addBot() { this._players.push( new Bot('bot', this._players.length) ); console.log(this._players); } initDeck() { for (let x=0; x<14; x++) { for (let y=0; y<8; y++) { if ( (x === 0) && (y >= 4) ) { // Skip blank card continue; } if ( (x === 13) && (y >= 4) ) { // +4 cards x = 14; } this._cards.push( new Card(x, y%4) ); } } console.log(this._cards); } shuffleDeck() { this._players.forEach( (player) => { for (let i=0; i<7; i++) { player.addCard( this.draw() ); } }); console.log(this._players); } draw() { /* Draw randomly */ const card_i = Math.floor( Math.random() * this._cards.length ); return this._cards.splice(card_i, 1)[0]; } updateView() { const inner_w = window.innerWidth; const inner_h = window.innerHeight; // Drw top card this._top_card.drawImageFront(inner_w/2, inner_h/2); // Draw players card this._players.forEach( (player) => { for (let i=0; i setTimeout(resolve, 1000)); if (player.isEmpty()) { console.log('player: ' + player.name + ' has no card left. Game end'); break } current_turn = (current_turn >= this._players.length-1) ? 0 : ++current_turn; count++; } } }