\n
\n \n {{player2Str[0]}}\n \n {{player2Str[1]}}\n \n {{player2Str[2]}}\n \n
\n\n
\n \n {{player1Str[0]}}\n \n {{player1Str[1]}}\n \n {{player1Str[2]}}\n \n
\n\n
\n
\n {{player0Str[0]}}\n \n {{player0Str[1]}}\n \n {{player0Str[2]}}\n \n
\n \n \n \n
\n
\n\n
\n
\n {{deskStr[0]}}\n \n {{deskStr[1]}}\n
\n
\n\n
\n \n
\n
\n\n\n\n\n\n\n","import mod from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./HelloWorld.vue?vue&type=script&lang=js&\"; export default mod; export * from \"-!../../node_modules/cache-loader/dist/cjs.js??ref--12-0!../../node_modules/thread-loader/dist/cjs.js!../../node_modules/babel-loader/lib/index.js!../../node_modules/cache-loader/dist/cjs.js??ref--0-0!../../node_modules/vue-loader/lib/index.js??vue-loader-options!./HelloWorld.vue?vue&type=script&lang=js&\"","import { render, staticRenderFns } from \"./HelloWorld.vue?vue&type=template&id=62298b0c&scoped=true&\"\nimport script from \"./HelloWorld.vue?vue&type=script&lang=js&\"\nexport * from \"./HelloWorld.vue?vue&type=script&lang=js&\"\n\n\n/* normalize component */\nimport normalizer from \"!../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n \"62298b0c\",\n null\n \n)\n\nexport default component.exports","var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticStyle:{\"user-select\":\"none\",\"position\":\"fixed\",\"left\":\"0\",\"right\":\"0\",\"top\":\"0\",\"bottom\":\"0\",\"background-repeat\":\"no-repeat\",\"background-size\":\"cover\"},style:({backgroundImage:'url('+require('../img/scene.jpg')+')'})},[_c('audio',{style:({ marginLeft: _vm.buttonMarginLeft + 'px' }),attrs:{\"muted\":\"\",\"autoplay\":\"\",\"loop\":\"\",\"controls\":\"\"}},[_c('source',{attrs:{\"src\":require(\"../audio/bgm.mp3\")}}),_vm._v(\" 您的浏览器不支持 audio 元素。 \")]),_c('div',{directives:[{name:\"show\",rawName:\"v-show\",value:(false),expression:\"false\"}],staticStyle:{\"width\":\"300px\",\"height\":\"300px\",\"float\":\"left\",\"position\":\"fixed\",\"left\":\"0\",\"top\":\"0px\",\"background-color\":\"aliceblue\",\"text-align\":\"center\"}},[_c('span',[_vm._v(\" 手牌:\"+_vm._s(_vm.player2Str[1])+\" \")])]),_c('div',{directives:[{name:\"show\",rawName:\"v-show\",value:(false),expression:\"false\"}],staticStyle:{\"width\":\"300px\",\"height\":\"300px\",\"float\":\"left\",\"position\":\"fixed\",\"right\":\"0\",\"top\":\"0px\",\"background-color\":\"aliceblue\",\"text-align\":\"center\"}},[_c('span',[_vm._v(\" 手牌:\"+_vm._s(_vm.player1Str[1])+\" \")])]),_c('div',{directives:[{name:\"show\",rawName:\"v-show\",value:(false),expression:\"false\"}],staticStyle:{\"width\":\"300px\",\"height\":\"300px\",\"float\":\"left\",\"position\":\"fixed\",\"left\":\"600px\",\"top\":\"0px\",\"background-color\":\"aliceblue\",\"text-align\":\"center\"}},[_c('div',{staticStyle:{\"width\":\"300px\",\"word-wrap\":\"break-word\"}},[_vm._v(\" 已出的牌: \"),_c('br'),_vm._v(\" \"+_vm._s(_vm.deskStr[1])+\" \")])]),_c('div',{staticStyle:{\"position\":\"fixed\",\"left\":\"10px\",\"bottom\":\"10px\"}},[_c('button',{staticStyle:{\"height\":\"50px\",\"font-size\":\"30px\"},on:{\"click\":_vm.reStart}},[_vm._v(\"开始新一局\")])]),_c('div',{staticStyle:{\"color\":\"white\",\"position\":\"fixed\",\"bottom\":\"0\",\"width\":\"100%\",\"height\":\"200px\",\"line-height\":\"200px\"},style:({ marginLeft: _vm.playerMarginLeft-150 + 'px' })},[_vm._v(\" 你是 \"),_c('span',{staticStyle:{\"color\":\"red\",\"font-size\":\"20px\"}},[_vm._v(_vm._s(_vm.game.playerList[0].type==='nongmin'?'农民':'地主'))])]),_c('div',{staticStyle:{\"position\":\"fixed\",\"bottom\":\"0\",\"width\":\"100%\",\"height\":\"200px\"},style:({ marginLeft: _vm.playerMarginLeft + 'px' })},_vm._l((_vm.game.playerList[0].pokerList),function(item){return _c('div',{staticClass:\"poker pokerDesk\",class:{ selected: item.selected, s:item.number===16, x:item.number===17 },on:{\"mouseenter\":function($event){return _vm.enter($event,item)},\"mousedown\":function($event){return _vm.pickPoker(item)}}},[_c('span',{directives:[{name:\"show\",rawName:\"v-show\",value:(item.number<16),expression:\"item.number<16\"}]},[_vm._v(\" \"+_vm._s(item.text)+\" \")])])}),0),_c('div',{staticStyle:{\"position\":\"fixed\",\"bottom\":\"200px\",\"width\":\"100%\",\"height\":\"100px\",\"text-align\":\"left\"}},[_c('div',{staticStyle:{\"width\":\"400px\",\"height\":\"60px\"},style:({ marginLeft: _vm.buttonMarginLeft + 'px' })},[_c('button',{staticStyle:{\"height\":\"60px\",\"border-radius\":\"4px\",\"float\":\"left\",\"font-size\":\"40px\",\"background-color\":\"red\"},on:{\"click\":_vm.pass}},[_vm._v(\"不出\")]),_c('button',{staticStyle:{\"height\":\"60px\",\"border-radius\":\"4px\",\"float\":\"right\",\"font-size\":\"40px\",\"background-color\":\"lawngreen\"},on:{\"click\":_vm.sendPoker2}},[_vm._v(\"出牌\")]),_c('div',{directives:[{name:\"show\",rawName:\"v-show\",value:(_vm.game.currentPlayer===_vm.game.playerList[0]),expression:\"game.currentPlayer===game.playerList[0]\"}],staticStyle:{\"color\":\"red\",\"width\":\"150px\",\"border\":\"solid\",\"border-radius\":\"4px\",\"float\":\"left\",\"margin-left\":\"20px\"}},[_vm._v(\" 请在\"+_vm._s(_vm.game.second)+\"秒内出牌 \")])])]),(_vm.game.playerList[0].lastSendObj&&_vm.game.playerList[0].lastSendObj.poker[0].text)?_c('div',{staticStyle:{\"position\":\"fixed\",\"bottom\":\"350px\",\"width\":\"100%\",\"height\":\"200px\"},style:({ marginLeft: _vm.deskPokerMarginLeft + 'px' })},_vm._l((_vm.game.playerList[0].lastSendObj.poker),function(item){return _c('div',{staticClass:\"pokerDesk\",class:{ s:item.number===16, x:item.number===17 }},[_c('span',{directives:[{name:\"show\",rawName:\"v-show\",value:(item.number<16),expression:\"item.number<16\"}]},[_vm._v(\" \"+_vm._s(item.text)+\" \")])])}),0):_vm._e(),(_vm.game.playerList[0].lastSendObj&&!_vm.game.playerList[0].lastSendObj.poker[0].text)?_c('div',{staticStyle:{\"position\":\"fixed\",\"bottom\":\"350px\",\"width\":\"100%\",\"height\":\"200px\"},style:({ marginLeft: _vm.deskPokerMarginLeft + 'px' })},[_c('div',{staticStyle:{\"height\":\"100%\",\"width\":\"100px\",\"float\":\"left\",\"margin-left\":\"-50px\",\"font-size\":\"50px\",\"color\":\"#ff0000\"}},[_vm._v(\" pass \")])]):_vm._e(),_c('div',{staticStyle:{\"position\":\"fixed\",\"top\":\"40px\",\"left\":\"20px\",\"height\":\"200px\",\"width\":\"100px\",\"border\":\"solid 1px\",\"border-radius\":\"8px\",\"background-color\":\"azure\",\"text-align\":\"center\"}},[_c('p',{staticStyle:{\"color\":\"red\",\"font-size\":\"20px\"}},[_vm._v(\" \"+_vm._s(_vm.game.playerList[2].type==='nongmin'?'农民':'地主')+\" \")]),_c('p',[_vm._v(\" \"+_vm._s(_vm.game.playerList[2].name)+\" \")]),_c('p',[_vm._v(\" 剩余 \"+_vm._s(_vm.game.playerList[2].pokerList.length)+\" 张 \")]),_c('div',{directives:[{name:\"show\",rawName:\"v-show\",value:(_vm.game.currentPlayer===_vm.game.playerList[2]),expression:\"game.currentPlayer===game.playerList[2]\"}],staticStyle:{\"color\":\"red\",\"width\":\"150px\",\"border\":\"solid\",\"border-radius\":\"4px\",\"position\":\"absolute\",\"bottom\":\"-50px\",\"left\":\"0\"}},[_vm._v(\" 请在\"+_vm._s(_vm.game.second)+\"秒内出牌 \")])]),(_vm.game.playerList[2].lastSendObj&&_vm.game.playerList[2].lastSendObj.poker[0].text)?_c('div',{staticStyle:{\"position\":\"fixed\",\"top\":\"100px\",\"left\":\"200px\",\"height\":\"200px\"}},_vm._l((_vm.game.playerList[2].lastSendObj.poker),function(item){return _c('div',{staticClass:\"pokerDesk\",class:{ s:item.number===16, x:item.number===17 }},[_c('span',{directives:[{name:\"show\",rawName:\"v-show\",value:(item.number<16),expression:\"item.number<16\"}]},[_vm._v(\" \"+_vm._s(item.text)+\" \")])])}),0):_vm._e(),(_vm.game.playerList[2].lastSendObj&&!_vm.game.playerList[2].lastSendObj.poker[0].text)?_c('div',{staticStyle:{\"position\":\"fixed\",\"top\":\"100px\",\"left\":\"200px\",\"height\":\"200px\"}},[_c('div',{staticStyle:{\"height\":\"100%\",\"width\":\"100px\",\"float\":\"left\",\"margin-left\":\"-50px\",\"font-size\":\"50px\",\"color\":\"#ff0000\"}},[_vm._v(\" pass \")])]):_vm._e(),_c('div',{staticStyle:{\"position\":\"fixed\",\"top\":\"40px\",\"right\":\"20px\",\"height\":\"200px\",\"width\":\"100px\",\"border\":\"solid 1px\",\"border-radius\":\"8px\",\"background-color\":\"azure\",\"text-align\":\"center\"}},[_c('p',{staticStyle:{\"color\":\"red\",\"font-size\":\"20px\"}},[_vm._v(\" \"+_vm._s(_vm.game.playerList[1].type==='nongmin'?'农民':'地主')+\" \")]),_c('p',[_vm._v(\" \"+_vm._s(_vm.game.playerList[1].name)+\" \")]),_c('p',[_vm._v(\" 剩余 \"+_vm._s(_vm.game.playerList[1].pokerList.length)+\" 张 \")]),_c('div',{directives:[{name:\"show\",rawName:\"v-show\",value:(_vm.game.currentPlayer===_vm.game.playerList[1]),expression:\"game.currentPlayer===game.playerList[1]\"}],staticStyle:{\"color\":\"red\",\"width\":\"150px\",\"border\":\"solid\",\"border-radius\":\"4px\",\"position\":\"absolute\",\"bottom\":\"-50px\",\"right\":\"0\"}},[_vm._v(\" 请在\"+_vm._s(_vm.game.second)+\"秒内出牌 \")])]),(_vm.game.playerList[1].lastSendObj&&_vm.game.playerList[1].lastSendObj.poker[0].text)?_c('div',{staticStyle:{\"position\":\"fixed\",\"top\":\"100px\",\"right\":\"200px\",\"height\":\"200px\"}},_vm._l((_vm.game.playerList[1].lastSendObj.poker),function(item){return _c('div',{staticClass:\"pokerDesk\",class:{ s:item.number===16, x:item.number===17 }},[_c('span',{directives:[{name:\"show\",rawName:\"v-show\",value:(item.number<16),expression:\"item.number<16\"}]},[_vm._v(\" \"+_vm._s(item.text)+\" \")])])}),0):_vm._e(),(_vm.game.playerList[1].lastSendObj&&!_vm.game.playerList[1].lastSendObj.poker[0].text)?_c('div',{staticStyle:{\"position\":\"fixed\",\"top\":\"100px\",\"right\":\"200px\",\"height\":\"200px\"}},[_c('div',{staticStyle:{\"height\":\"100%\",\"width\":\"100px\",\"float\":\"left\",\"margin-left\":\"-50px\",\"font-size\":\"50px\",\"color\":\"#ff0000\"}},[_vm._v(\" pass \")])]):_vm._e()])}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","
+
@@ -64,7 +81,7 @@
-
+
{{game.playerList[2].type==='nongmin'?'农民':'地主'}}
@@ -77,6 +94,9 @@
请在{{game.second}}秒内出牌
+
+ {{game.playerList[2].ready?'已准备':'未准备'}}
+
+
+
+ {{game.playerList[2].jiaoFen}}分
+
+
-
+
{{game.playerList[1].type==='nongmin'?'农民':'地主'}}
@@ -104,6 +129,9 @@
请在{{game.second}}秒内出牌
+
+ {{game.playerList[1].ready?'已准备':'未准备'}}
+
@@ -117,6 +145,11 @@
pass
+
+
+ {{game.playerList[1].jiaoFen}}分
+
+
@@ -194,6 +227,12 @@ export default {
window.game = this.game;
},
methods:{
+
+ setReady: function() {
+ let that = this;
+ that.game.playerList[0].setReady();
+ },
+
enter: function(e, poker){
if(e.buttons === 1){
this.pickPoker(poker);
diff --git a/src/doudizhu/Game.js b/src/doudizhu/Game.js
index 06de767ad9b491b2e2196695c96f199610c2efcd..2f87bed5c334104b77ddca2afa0566b67d1edc69 100644
--- a/src/doudizhu/Game.js
+++ b/src/doudizhu/Game.js
@@ -7,11 +7,13 @@ class Game{
this.pokerList = [];
this.deskPokerObj = null;
this.oldPokerList = [];
- this.currentPlayer = [];
+ this.currentPlayer = null;
+ this.currentJiaoFenPlayer = null;
+ this.jiaoFenCount = 0;
this.dizhu = null;
this.MaxSecond = 60;
this.second = this.MaxSecond;
- this.isOver = true;
+ this.stage = 'ready'; //阶段 ready\jiaoFen\play
this.init();
}
@@ -19,17 +21,55 @@ class Game{
init(){
this.initPokerList();
this.initPlayerList();
- this.sendPoker();
+ }
+
+ setReady(){
+ if(this.playerList[0]&&this.playerList[0].ready&&this.playerList[1]&&this.playerList[1].ready&&this.playerList[2]&&this.playerList[2].ready){
+ this.sendPoker();
+ this.startJiaoFen();
+ }
+ }
+
+ //开始叫分
+ startJiaoFen(){
+ this.stage = 'jiaoFen';
+ let index = this.getRandomIntInclusive(0,2);
+ this.currentJiaoFenPlayer = this.playerList[index];
+ }
+
+ someOneJiaoFen(){
+ let that = this;
+
+ this.jiaoFenCount++;
+ if(this.jiaoFenCount === 3){
+ setTimeout(function () {
+ that.setDiZhu();
+ },1000);
+ return;
+ }else{
+ this.currentJiaoFenPlayer = this.currentJiaoFenPlayer.next;
+ }
+ }
+
+ setDiZhu(){
+ let sortList = this.playerList.slice(0).sort(this.sortByJiaoFen);
+ let dizhu = sortList[0];
+ dizhu.type = 'dizhu';
+ this.dizhu = dizhu;
this.start();
}
+ sortByJiaoFen(a, b){
+ return b.jiaoFen - a.jiaoFen;
+ }
+
resetTime(){
this.second = this.MaxSecond;
}
timeLoop(){
- if(this.isOver){
+ if(this.stage !== 'play'){
return;
}
this.second--;
@@ -50,7 +90,7 @@ class Game{
start(){
- this.isOver = false;
+ this.stage = 'play';
this.timeLoop();
this.currentPlayer = this.dizhu;
if(this.currentPlayer.isRobot){
@@ -58,6 +98,25 @@ class Game{
}
}
+ reset(){
+
+ this.playerList[0].reset();
+ this.playerList[1].reset();
+ this.playerList[2].reset();
+
+ this.pokerList = [];
+ this.deskPokerObj = null;
+ this.oldPokerList = [];
+ this.currentPlayer = null;
+ this.currentJiaoFenPlayer = null;
+ this.jiaoFenCount = 0;
+ this.dizhu = null;
+ this.second = this.MaxSecond;
+ this.stage = 'ready';
+
+ this.initPokerList();
+ }
+
next(){
let over = this.checkGameOver();
if(over){
@@ -73,7 +132,8 @@ class Game{
gameOver(){
alert('游戏结束! '+this.currentPlayer.name+' ['+this.currentPlayer.type+'] 胜!');
- this.isOver = true;
+
+ this.reset();
}
checkGameOver(){
@@ -89,6 +149,15 @@ class Game{
}
}
+ sendDiZhuPoker(){
+ do{
+ let poker = this.pokerList.splice(0,1)[0];
+ this.dizhu.addPoker(poker);
+ }while(this.pokerList.length>0);
+
+ this.dizhu.sortPoker();
+ }
+
sendPoker(){
let player = this.playerList[0];
do{
@@ -98,11 +167,6 @@ class Game{
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