提交 5a32fcc4 编写于 作者: C changjiuxiong

新增 金币系统

上级 1d2e18cf
......@@ -30,9 +30,12 @@
<button v-show="true" @mousedown="game.playerList[0].setJiaoFen(3)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">3分</button>
</div>
<div v-show="game.stage==='play'" :style="{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 200px;line-height: 200px;">
<div v-show="game.stage==='play'" :style="{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 200px;">
你是 <span style="color:red;font-size: 20px">{{game.playerList[0].type==='nongmin'?'农民':'地主'}}</span>
</div>
<div :style="{ marginLeft: playerMarginLeft-150 + 'px' }" style="color:white;position: fixed;bottom:0;width: 100%;height: 100px;">
金币: <span style="color:greenyellow;font-size: 20px">{{game.playerList[0].money}}</span>
</div>
<div :style="{ marginLeft: playerMarginLeft + 'px' }" style="position: fixed;bottom:0;width: 100%;height: 200px;">
<div @mouseenter="enter($event,item)" @mousedown="pickPoker(item)" v-for="item in game.playerList[0].pokerList" :class="{ selected: item.selected, s:item.number===16, x:item.number===17 }" class="poker pokerDesk" style="">
<span v-show="item.number<16">
......@@ -81,6 +84,9 @@
<p>
{{game.playerList[2].name}}
</p>
<p>
金币: <span style="color:green;">{{game.playerList[2].money}}</span>
</p>
<p>
剩余 {{game.playerList[2].pokerList.length}}
</p>
......@@ -122,6 +128,9 @@
<p>
{{game.playerList[1].name}}
</p>
<p>
金币: <span style="color:green;">{{game.playerList[1].money}}</span>
</p>
<p>
剩余 {{game.playerList[1].pokerList.length}}
</p>
......
......@@ -3,6 +3,8 @@ import Poker from "./Poker";
class Game{
constructor() {
this.testModel = false; //测试模式 三个AI自动打牌
this.playerList = [];
this.pokerList = [];
this.dizhuPokerList = [];
......@@ -12,8 +14,10 @@ class Game{
this.currentJiaoFenPlayer = null;
this.jiaoFenCount = 0;
this.dizhu = null;
this.MaxSecond = 60;
this.MaxSecond = 20;
this.second = this.MaxSecond;
this.BaseScore = 1; //每局底分
this.score = this.BaseScore; //当前局分
this.stage = 'ready'; //阶段 ready\jiaoFen\play
this.init();
......@@ -40,12 +44,17 @@ class Game{
someOneJiaoFen(){
let that = this;
this.jiaoFenCount++;
let timeWait = 1000;
if(that.testModel){
timeWait = 0;
}
if(this.jiaoFenCount === 3){
setTimeout(function () {
that.setDiZhu();
},1000);
},timeWait);
return;
}else{
this.currentJiaoFenPlayer = this.currentJiaoFenPlayer.next;
......@@ -53,8 +62,22 @@ class Game{
}
setDiZhu(){
let sortList = this.playerList.slice(0).sort(this.sortByJiaoFen);
let dizhu = sortList[0];
let dizhu;
if(sortList[0].jiaoFen === sortList[1].jiaoFen){
if(sortList[0].jiaoFen === sortList[2].jiaoFen){
let index = this.getRandomIntInclusive(0,2);
dizhu = sortList[index];
}else{
let index = this.getRandomIntInclusive(0,1);
dizhu = sortList[index];
}
}else{
dizhu = sortList[0];
}
dizhu.type = 'dizhu';
this.dizhu = dizhu;
......@@ -115,17 +138,37 @@ class Game{
this.jiaoFenCount = 0;
this.dizhu = null;
this.second = this.MaxSecond;
this.score = this.BaseScore;
this.stage = 'ready';
this.initPokerList();
}
next(){
//有玩家出牌
someOneSendPoker(obj){
this.clearDesk();
this.deskPokerObj = obj;
this.checkBoom(obj);
let over = this.checkGameOver();
if(over){
this.gameOver();
return;
}
this.next();
}
//炸弹分数翻1番 火箭翻2番
checkBoom(obj){
if(obj.type === 'four'){
this.score *= 2;
}else if(obj.type === 'four'){
this.score *= 4;
}
}
next(){
this.resetTime();
this.currentPlayer = this.currentPlayer.next;
if(this.currentPlayer.isRobot){
......@@ -134,11 +177,41 @@ class Game{
}
gameOver(){
alert('游戏结束! '+this.currentPlayer.name+' ['+this.currentPlayer.type+'] 胜!');
if(!this.testModel){
alert('游戏结束! '+this.currentPlayer.name+' ['+this.currentPlayer.type+'] 胜!');
}else{
console.log(this.playerList[0].money+' '+this.playerList[1].money+' '+this.playerList[2].money+' ');
}
this.settleMoney();
this.reset();
}
//结算金币得失
settleMoney(){
if(this.currentPlayer.type === 'nongmin'){
this.currentPlayer.money += this.score;
if(this.currentPlayer.next.type === 'nongmin'){
this.currentPlayer.next.money += this.score;
}else{
this.currentPlayer.next.money -= this.score*2;
}
if(this.currentPlayer.last.type === 'nongmin'){
this.currentPlayer.last.money += this.score;
}else{
this.currentPlayer.last.money -= this.score*2;
}
}else{
this.currentPlayer.money += this.score*2;
this.currentPlayer.next.money -= this.score;
this.currentPlayer.last.money -= this.score;
}
}
checkGameOver(){
if(this.currentPlayer.pokerList.length === 0) {
return true;
......@@ -178,10 +251,11 @@ class Game{
}
initPlayerList(){
let that = this;
this.playerList = [];
let player0 = new Player({
name: 'player',
isRobot: false,
isRobot: that.testModel,
game: this,
});
let player1 = new Player({
......
......@@ -4,6 +4,7 @@ import AI from "./AI";
class Player{
constructor(param) {
param = param || {};
this.money = 1000; //金币
this.ready = false; //已准备
this.jiaoFen = -1; //叫分
this.pokerList = [];
......@@ -32,19 +33,25 @@ class Player{
loopRobot(){
let that = this;
if(that.isRobot){
if(!that.ready){
that.setReady();
}
}
if(that.game.stage==='jiaoFen' && that.game.currentJiaoFenPlayer === that){
let fen = that.ai.getJiaoFen();
that.setJiaoFen(fen);
let timeWait = 1000;
if(that.game.testModel){
timeWait = 0;
}
setTimeout(function(){
if(that.isRobot){
if(!that.ready){
that.setReady();
}
}
if(that.game.stage==='jiaoFen' && that.game.currentJiaoFenPlayer === that){
let fen = that.ai.getJiaoFen();
that.setJiaoFen(fen);
}
that.loopRobot();
},2000);
},timeWait);
}
setReady(){
......@@ -96,6 +103,11 @@ class Player{
that.getClassifyObj();
let timeWait = 1000;
if(that.game.testModel){
timeWait = 0;
}
setTimeout(function () {
let lastObj = that.getLastObj();
if(lastObj){
......@@ -103,16 +115,15 @@ class Player{
}else{
that.ai.playByAllType();
}
},1000);
},timeWait);
}
sendPoker(obj){
obj.player = this;
this.game.clearDesk();
this.lastSendObj = obj;
this.game.deskPokerObj = obj;
this.game.next();
this.game.someOneSendPoker(obj);
}
deleteFromPokerListAndSendByObj(obj){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册