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

新增 金币系统

上级 1d2e18cf
...@@ -30,9 +30,12 @@ ...@@ -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> <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>
<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> 你是 <span style="color:red;font-size: 20px">{{game.playerList[0].type==='nongmin'?'农民':'地主'}}</span>
</div> </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 :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=""> <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"> <span v-show="item.number<16">
...@@ -81,6 +84,9 @@ ...@@ -81,6 +84,9 @@
<p> <p>
{{game.playerList[2].name}} {{game.playerList[2].name}}
</p> </p>
<p>
金币: <span style="color:green;">{{game.playerList[2].money}}</span>
</p>
<p> <p>
剩余 {{game.playerList[2].pokerList.length}} 剩余 {{game.playerList[2].pokerList.length}}
</p> </p>
...@@ -122,6 +128,9 @@ ...@@ -122,6 +128,9 @@
<p> <p>
{{game.playerList[1].name}} {{game.playerList[1].name}}
</p> </p>
<p>
金币: <span style="color:green;">{{game.playerList[1].money}}</span>
</p>
<p> <p>
剩余 {{game.playerList[1].pokerList.length}} 剩余 {{game.playerList[1].pokerList.length}}
</p> </p>
......
...@@ -3,6 +3,8 @@ import Poker from "./Poker"; ...@@ -3,6 +3,8 @@ import Poker from "./Poker";
class Game{ class Game{
constructor() { constructor() {
this.testModel = false; //测试模式 三个AI自动打牌
this.playerList = []; this.playerList = [];
this.pokerList = []; this.pokerList = [];
this.dizhuPokerList = []; this.dizhuPokerList = [];
...@@ -12,8 +14,10 @@ class Game{ ...@@ -12,8 +14,10 @@ class Game{
this.currentJiaoFenPlayer = null; this.currentJiaoFenPlayer = null;
this.jiaoFenCount = 0; this.jiaoFenCount = 0;
this.dizhu = null; this.dizhu = null;
this.MaxSecond = 60; this.MaxSecond = 20;
this.second = this.MaxSecond; this.second = this.MaxSecond;
this.BaseScore = 1; //每局底分
this.score = this.BaseScore; //当前局分
this.stage = 'ready'; //阶段 ready\jiaoFen\play this.stage = 'ready'; //阶段 ready\jiaoFen\play
this.init(); this.init();
...@@ -40,12 +44,17 @@ class Game{ ...@@ -40,12 +44,17 @@ class Game{
someOneJiaoFen(){ someOneJiaoFen(){
let that = this; let that = this;
this.jiaoFenCount++; this.jiaoFenCount++;
let timeWait = 1000;
if(that.testModel){
timeWait = 0;
}
if(this.jiaoFenCount === 3){ if(this.jiaoFenCount === 3){
setTimeout(function () { setTimeout(function () {
that.setDiZhu(); that.setDiZhu();
},1000); },timeWait);
return; return;
}else{ }else{
this.currentJiaoFenPlayer = this.currentJiaoFenPlayer.next; this.currentJiaoFenPlayer = this.currentJiaoFenPlayer.next;
...@@ -53,8 +62,22 @@ class Game{ ...@@ -53,8 +62,22 @@ class Game{
} }
setDiZhu(){ setDiZhu(){
let sortList = this.playerList.slice(0).sort(this.sortByJiaoFen); 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'; dizhu.type = 'dizhu';
this.dizhu = dizhu; this.dizhu = dizhu;
...@@ -115,17 +138,37 @@ class Game{ ...@@ -115,17 +138,37 @@ class Game{
this.jiaoFenCount = 0; this.jiaoFenCount = 0;
this.dizhu = null; this.dizhu = null;
this.second = this.MaxSecond; this.second = this.MaxSecond;
this.score = this.BaseScore;
this.stage = 'ready'; this.stage = 'ready';
this.initPokerList(); this.initPokerList();
} }
next(){ //有玩家出牌
someOneSendPoker(obj){
this.clearDesk();
this.deskPokerObj = obj;
this.checkBoom(obj);
let over = this.checkGameOver(); let over = this.checkGameOver();
if(over){ if(over){
this.gameOver(); this.gameOver();
return; 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.resetTime();
this.currentPlayer = this.currentPlayer.next; this.currentPlayer = this.currentPlayer.next;
if(this.currentPlayer.isRobot){ if(this.currentPlayer.isRobot){
...@@ -134,11 +177,41 @@ class Game{ ...@@ -134,11 +177,41 @@ class Game{
} }
gameOver(){ 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(); 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(){ checkGameOver(){
if(this.currentPlayer.pokerList.length === 0) { if(this.currentPlayer.pokerList.length === 0) {
return true; return true;
...@@ -178,10 +251,11 @@ class Game{ ...@@ -178,10 +251,11 @@ class Game{
} }
initPlayerList(){ initPlayerList(){
let that = this;
this.playerList = []; this.playerList = [];
let player0 = new Player({ let player0 = new Player({
name: 'player', name: 'player',
isRobot: false, isRobot: that.testModel,
game: this, game: this,
}); });
let player1 = new Player({ let player1 = new Player({
......
...@@ -4,6 +4,7 @@ import AI from "./AI"; ...@@ -4,6 +4,7 @@ import AI from "./AI";
class Player{ class Player{
constructor(param) { constructor(param) {
param = param || {}; param = param || {};
this.money = 1000; //金币
this.ready = false; //已准备 this.ready = false; //已准备
this.jiaoFen = -1; //叫分 this.jiaoFen = -1; //叫分
this.pokerList = []; this.pokerList = [];
...@@ -32,19 +33,25 @@ class Player{ ...@@ -32,19 +33,25 @@ class Player{
loopRobot(){ loopRobot(){
let that = this; let that = this;
if(that.isRobot){
if(!that.ready){ let timeWait = 1000;
that.setReady(); if(that.game.testModel){
} timeWait = 0;
}
if(that.game.stage==='jiaoFen' && that.game.currentJiaoFenPlayer === that){
let fen = that.ai.getJiaoFen();
that.setJiaoFen(fen);
} }
setTimeout(function(){ 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(); that.loopRobot();
},2000); },timeWait);
} }
setReady(){ setReady(){
...@@ -96,6 +103,11 @@ class Player{ ...@@ -96,6 +103,11 @@ class Player{
that.getClassifyObj(); that.getClassifyObj();
let timeWait = 1000;
if(that.game.testModel){
timeWait = 0;
}
setTimeout(function () { setTimeout(function () {
let lastObj = that.getLastObj(); let lastObj = that.getLastObj();
if(lastObj){ if(lastObj){
...@@ -103,16 +115,15 @@ class Player{ ...@@ -103,16 +115,15 @@ class Player{
}else{ }else{
that.ai.playByAllType(); that.ai.playByAllType();
} }
},1000); },timeWait);
} }
sendPoker(obj){ sendPoker(obj){
obj.player = this; obj.player = this;
this.game.clearDesk();
this.lastSendObj = obj; this.lastSendObj = obj;
this.game.deskPokerObj = obj;
this.game.next(); this.game.someOneSendPoker(obj);
} }
deleteFromPokerListAndSendByObj(obj){ deleteFromPokerListAndSendByObj(obj){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册