import Player from "./Player"; import Poker from "./Poker"; class Game{ constructor() { this.playerList = []; this.pokerList = []; this.deskPokerObj = null; this.oldPokerList = []; this.currentPlayer = []; this.dizhu = null; this.MaxSecond = 60; this.second = this.MaxSecond; this.isOver = true; this.init(); } init(){ this.initPokerList(); this.initPlayerList(); this.sendPoker(); this.start(); } resetTime(){ this.second = this.MaxSecond; } timeLoop(){ if(this.isOver){ return; } this.second--; if(this.second === 0){ this.timeout(); } let that = this; setTimeout(function () { that.timeLoop(); },1000); } timeout(){ this.currentPlayer.playByString('pass'); } start(){ this.isOver = false; this.timeLoop(); this.currentPlayer = this.dizhu; if(this.currentPlayer.isRobot){ this.currentPlayer.playByAI(); } } next(){ let over = this.checkGameOver(); if(over){ this.gameOver(); return; } this.resetTime(); this.currentPlayer = this.currentPlayer.next; if(this.currentPlayer.isRobot){ this.currentPlayer.playByAI(); } } gameOver(){ alert('游戏结束! '+this.currentPlayer.name+' ['+this.currentPlayer.type+'] 胜!'); this.isOver = true; } checkGameOver(){ if(this.currentPlayer.pokerList.length === 0) { return true; } } clearDesk(){ if(this.deskPokerObj){ this.oldPokerList.push(this.deskPokerObj); this.deskPokerObj = null; } } sendPoker(){ let player = this.playerList[0]; do{ let index = this.getRandomIntInclusive(0,this.pokerList.length-1); let poker = this.pokerList.splice(index,1)[0]; player.addPoker(poker); player = player.next; }while(this.pokerList.length>3); do{ let poker = this.pokerList.splice(0,1)[0]; this.dizhu.addPoker(poker); }while(this.pokerList.length>0); for(let i=0; i