Game.vue 13.5 KB
Newer Older
微笑面对bug's avatar
微笑面对bug 已提交
1
<template>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
2
  <div style="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')+')'}">
微笑面对bug's avatar
bgm  
微笑面对bug 已提交
3 4 5 6 7
      <audio muted autoplay loop controls :style="{ marginLeft: buttonMarginLeft + 'px' }">
          <source src="../audio/bgm.mp3">
          您的浏览器不支持 audio 元素。
      </audio>

微笑面对bug's avatar
微笑面对bug 已提交
8 9 10 11 12 13 14 15 16 17 18
<!--      <div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; left: 0; top: 0px; background-color: aliceblue; text-align: center">-->
<!--        <span>-->
<!--            手牌:{{player2Str[1]}}-->
<!--        </span>-->
<!--    </div>-->

<!--    <div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; right: 0; top: 0px; background-color: aliceblue; text-align: center">-->
<!--        <span>-->
<!--            手牌:{{player1Str[1]}}-->
<!--        </span>-->
<!--    </div>-->
微笑面对bug's avatar
微笑面对bug 已提交
19

微笑面对bug's avatar
界面  
微笑面对bug 已提交
20
    <div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; left: 600px; top: 0px; background-color: aliceblue; text-align: center">
微笑面对bug's avatar
微笑面对bug 已提交
21
      <div style="width: 300px;word-wrap: break-word;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
22 23
          已出的牌:
          <br/>
微笑面对bug's avatar
微笑面对bug 已提交
24 25 26 27
          {{deskStr[1]}}
      </div>
    </div>

微笑面对bug's avatar
微笑面对bug 已提交
28 29 30 31
<!--    <div style="position: fixed;left: 10px;bottom: 10px;">-->
<!--      <button @click="reStart" style="height: 50px;font-size:30px;">开始新一局</button>-->
<!--    </div>-->

32
      <div v-show="game.stage==='ready'" :style="{ marginLeft: playerMarginLeft-40 + 'px' }" style="font-size: 20px;color:white;position: fixed;bottom:200px;z-index: 999;">
微笑面对bug's avatar
微笑面对bug 已提交
33 34 35 36 37
          <button v-show="!game.playerList[0].ready" @mousedown="setReady" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">{{game.playerList[0].ready?'已准备':'准备'}}</button>
          <div v-show="game.playerList[0].ready" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;">
              {{game.playerList[0].ready?'已准备':'未准备'}}
          </div>
      </div>
微笑面对bug's avatar
微笑面对bug 已提交
38

39 40 41 42 43 44 45 46 47 48 49
      <div v-show="game.stage==='jiaoFen'&&game.currentJiaoFenPlayer===game.playerList[0]" :style="{ marginLeft: playerMarginLeft-40 + 'px' }" style="font-size: 20px;color:white;position: fixed;bottom:200px;z-index: 999;">
          <button v-show="true" @mousedown="game.playerList[0].setJiaoFen(0)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">不叫</button>
          <button v-show="true" @mousedown="game.playerList[0].setJiaoFen(1)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">1分</button>
          <button v-show="true" @mousedown="game.playerList[0].setJiaoFen(2)" style="font-size: 40px;height: 60px;line-height: 30px;border-radius: 4px;background-color: lawngreen;">2分</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 v-show="game.playerList[0].ready" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;">-->
<!--              {{game.playerList[0].ready?'已准备':'未准备'}}-->
<!--          </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;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
50
          你是 <span style="color:red;font-size: 20px">{{game.playerList[0].type==='nongmin'?'农民':'地主'}}</span>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
51
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
52
      <div :style="{ marginLeft: playerMarginLeft + 'px' }" style="position: fixed;bottom:0;width: 100%;height: 200px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
53 54 55 56
          <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">
                  {{item.text}}
              </span>
微笑面对bug's avatar
微笑面对bug 已提交
57 58 59
          </div>
      </div>

微笑面对bug's avatar
微笑面对bug 已提交
60
      <div v-show="game.currentPlayer===game.playerList[0]" style="position: fixed;bottom:200px;width: 100%;height: 100px;text-align:left;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
61 62 63 64
          <div :style="{ marginLeft: buttonMarginLeft + 'px' }" style="width: 400px;height: 60px;">
              <button @click="pass" style="height: 60px;border-radius: 4px;float:left;font-size:40px;background-color: red">不出</button>
              <button @click="sendPoker2" style="height: 60px;border-radius: 4px;float:right;font-size:40px;background-color: lawngreen">出牌</button>
              <div v-show="game.currentPlayer===game.playerList[0]" style="color: red;width:150px;border: solid;border-radius: 4px;float: left;margin-left: 20px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
65 66
                  请在{{game.second}}秒内出牌
              </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
67
          </div>
微笑面对bug's avatar
微笑面对bug 已提交
68 69
      </div>

微笑面对bug's avatar
界面  
微笑面对bug 已提交
70
      <div v-if="game.playerList[0].lastSendObj&&game.playerList[0].lastSendObj.poker[0].text" :style="{ marginLeft: deskPokerMarginLeft + 'px' }" style="position: fixed;bottom:350px;width: 100%;height: 200px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
71 72 73 74
          <div v-for="item in game.playerList[0].lastSendObj.poker" class="pokerDesk" :class="{ s:item.number===16, x:item.number===17 }">
              <span v-show="item.number<16">
                  {{item.text}}
              </span>
微笑面对bug's avatar
微笑面对bug 已提交
75
          </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
76 77
      </div>
      <div v-if="game.playerList[0].lastSendObj&&!game.playerList[0].lastSendObj.poker[0].text" :style="{ marginLeft: deskPokerMarginLeft + 'px' }" style="position: fixed;bottom:350px;width: 100%;height: 200px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
78
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
79 80 81 82 83
              pass
          </div>
      </div>

      <div style="position: fixed;top:40px;left: 20px;height:200px;width:100px;border: solid 1px;border-radius: 8px;background-color: azure;text-align: center">
84
          <p v-show="game.stage==='play'" style="color:red;font-size: 20px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
85 86 87 88 89 90 91 92 93 94 95 96
              {{game.playerList[2].type==='nongmin'?'农民':'地主'}}
          </p>
          <p>
              {{game.playerList[2].name}}
          </p>
          <p>
              剩余 {{game.playerList[2].pokerList.length}}
          </p>

          <div v-show="game.currentPlayer===game.playerList[2]" style="color: red;width:150px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;left: 0">
              请在{{game.second}}秒内出牌
          </div>
97
          <div v-show="game.stage==='ready'" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;left: 0;z-index: 999;">
微笑面对bug's avatar
微笑面对bug 已提交
98 99
              {{game.playerList[2].ready?'已准备':'未准备'}}
          </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
100
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
101
      <div v-if="game.playerList[2].lastSendObj&&game.playerList[2].lastSendObj.poker[0].text" style="position: fixed;top:100px;left:200px;height: 200px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
102 103 104 105
          <div v-for="item in game.playerList[2].lastSendObj.poker" class="pokerDesk" :class="{ s:item.number===16, x:item.number===17 }">
              <span v-show="item.number<16">
                  {{item.text}}
              </span>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
106 107 108
          </div>
      </div>
      <div v-if="game.playerList[2].lastSendObj&&!game.playerList[2].lastSendObj.poker[0].text" style="position: fixed;top:100px;left:200px;height: 200px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
109
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
110 111 112
              pass
          </div>
      </div>
113 114 115 116 117
      <div v-if="game.stage==='jiaoFen'" style="position: fixed;top:100px;left:200px;height: 200px;">
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
              {{game.playerList[2].jiaoFen}}
          </div>
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
118 119

      <div style="position: fixed;top:40px;right: 20px;height:200px;width:100px;border: solid 1px;border-radius: 8px;background-color: azure;text-align: center">
120
          <p v-show="game.stage==='play'" style="color:red;font-size: 20px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
121 122 123 124 125 126 127 128 129 130 131
              {{game.playerList[1].type==='nongmin'?'农民':'地主'}}
          </p>
          <p>
              {{game.playerList[1].name}}
          </p>
          <p>
              剩余 {{game.playerList[1].pokerList.length}}
          </p>
          <div v-show="game.currentPlayer===game.playerList[1]" style="color: red;width:150px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;right: 0">
              请在{{game.second}}秒内出牌
          </div>
132
          <div v-show="game.stage==='ready'" style="color: red;width:80px;border: solid;border-radius: 4px;position: absolute;bottom:-50px;right: 0;z-index: 999;">
微笑面对bug's avatar
微笑面对bug 已提交
133 134
              {{game.playerList[1].ready?'已准备':'未准备'}}
          </div>
微笑面对bug's avatar
微笑面对bug 已提交
135
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
136
      <div v-if="game.playerList[1].lastSendObj&&game.playerList[1].lastSendObj.poker[0].text" style="position: fixed;top:100px;right:200px;height: 200px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
137 138 139 140
          <div v-for="item in game.playerList[1].lastSendObj.poker" class="pokerDesk" :class="{ s:item.number===16, x:item.number===17 }">
              <span v-show="item.number<16">
                  {{item.text}}
              </span>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
141 142 143
          </div>
      </div>
      <div v-if="game.playerList[1].lastSendObj&&!game.playerList[1].lastSendObj.poker[0].text" style="position: fixed;top:100px;right:200px;height: 200px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
144
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
145 146 147
              pass
          </div>
      </div>
148 149 150 151 152
      <div v-if="game.stage==='jiaoFen'" style="position: fixed;top:100px;right:200px;height: 200px;">
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
              {{game.playerList[1].jiaoFen}}
          </div>
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
153

微笑面对bug's avatar
微笑面对bug 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
  </div>
</template>


<script>
  import Game from "../doudizhu/Game";
export default {
  name: 'HelloWorld',
  data(){
    return {
        data:'fuck1',
        game: new Game(),
        playerStr: '',
        pokerList: [],
    }
  },
  computed: {

微笑面对bug's avatar
界面  
微笑面对bug 已提交
172 173 174 175
      playerMarginLeft: function(){
          return (window.innerWidth - (this.game.playerList[0].pokerList.length*50))/2;
      },
      deskPokerMarginLeft: function(){
微笑面对bug's avatar
界面  
微笑面对bug 已提交
176
          return (window.innerWidth - (this.game.playerList[0].lastSendObj.poker.length*50))/2;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
177 178
      },
      buttonMarginLeft: function(){
微笑面对bug's avatar
界面  
微笑面对bug 已提交
179
          return (window.innerWidth - 400)/2;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
180 181
      },

微笑面对bug's avatar
微笑面对bug 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195
      deskPoker: function(){
          if(this.game.deskPokerObj && this.game.deskPokerObj.poker){
              if(this.game.deskPokerObj.poker[0] && this.game.deskPokerObj.poker[0].text){
                return this.game.deskPokerObj.poker;
              }
          }
          return [];
      },
        player2Str: function () {
          let game = this.game;
          let i = 2;
          return [
              game.playerList[i].name+' : '+game.playerList[i].type+' : '+game.playerList[i].pokerList.length,
              game.playerList[i].pokerListToString(),
微笑面对bug's avatar
界面  
微笑面对bug 已提交
196
              game.playerList[i].lastSendObjToString()
微笑面对bug's avatar
微笑面对bug 已提交
197 198 199 200 201 202 203 204
          ];
        },
      player1Str: function () {
          let game = this.game;
          let i = 1;
          return [
              game.playerList[i].name+' : '+game.playerList[i].type+' : '+game.playerList[i].pokerList.length,
              game.playerList[i].pokerListToString(),
微笑面对bug's avatar
界面  
微笑面对bug 已提交
205
              game.playerList[i].lastSendObjToString()
微笑面对bug's avatar
微笑面对bug 已提交
206 207 208 209 210 211 212 213
          ];
      },
      player0Str: function () {
          let game = this.game;
          let i = 0;
          return [
              game.playerList[i].name+' : '+game.playerList[i].type+' : '+game.playerList[i].pokerList.length,
              game.playerList[i].pokerListToString(),
微笑面对bug's avatar
界面  
微笑面对bug 已提交
214
              game.playerList[i].lastSendObjToString()
微笑面对bug's avatar
微笑面对bug 已提交
215 216 217 218 219 220 221 222 223 224 225 226
          ];
      },
      deskStr: function () {
          let game = this.game;
          return [
              'desk',
              game.pokerListToString()
          ];
      },
  },
  mounted() {
    this.data = this.game.playerList[1].name;
微笑面对bug's avatar
微笑面对bug 已提交
227
    window.game = this.game;
微笑面对bug's avatar
微笑面对bug 已提交
228 229
  },
  methods:{
微笑面对bug's avatar
微笑面对bug 已提交
230 231 232 233 234 235

      setReady: function() {
          let that = this;
          that.game.playerList[0].setReady();
      },

微笑面对bug's avatar
交互  
微笑面对bug 已提交
236 237 238 239 240
      enter: function(e, poker){
          if(e.buttons === 1){
              this.pickPoker(poker);
          }
      },
微笑面对bug's avatar
微笑面对bug 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285

      pickPoker(poker){
          if(!poker.selected){
              poker.selected = true;
              this.pokerList.push(poker);
          }else{
              poker.selected = false;
              for(let i=0; i<this.pokerList.length; i++){
                  if(this.pokerList[i] === poker){
                      this.pokerList.splice(i,1);
                  }
              }
          }
      },

      sendPoker2() {
          let game = this.game;
          let success = game.playerList[0].playByPokerList(this.pokerList);
          if(success){
              this.pokerList=[];
          }
      },

      sendPoker() {
        let game = this.game;
        let success = game.playerList[0].playByString(this.playerStr);
        if(success){
            this.playerStr='';
        }
      },

    pass() {
      this.game.playerList[0].playByString('pass');
    },

    reStart() {
        this.game = new Game();
        this.playerStr='';
    },

  },
}
</script>

<style scoped>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
286 287 288
    .pokerDesk{
        height:100%;width:100px;border: solid 1px;border-radius: 16px;float: left;margin-left:-50px;background-color: azure;
        font-size: 30px;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
289
        background-repeat: no-repeat;background-size: cover;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
290
    }
微笑面对bug's avatar
界面  
微笑面对bug 已提交
291

微笑面对bug's avatar
微笑面对bug 已提交
292 293 294 295 296 297 298
    .poker:hover{
        background-color: antiquewhite;
    }

    .selected{
        margin-top: -20px;
    }
微笑面对bug's avatar
界面  
微笑面对bug 已提交
299 300 301 302 303 304 305 306

    .s{
        background-image: url("../img/s.jpg");
    }

    .x{
        background-image: url("../img/x.png");
    }
微笑面对bug's avatar
微笑面对bug 已提交
307
</style>