Game.vue 12.4 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')+')'}">
C
changjiuxiong 已提交
3
      <audio muted autoplay loop controls style="position: fixed; left: 0;bottom: 0">
微笑面对bug's avatar
bgm  
微笑面对bug 已提交
4 5 6 7
          <source src="../audio/bgm.mp3">
          您的浏览器不支持 audio 元素。
      </audio>

C
changjiuxiong 已提交
8 9 10 11 12 13 14 15 16
      <div v-if="game.stage==='play'" :style="{ marginLeft: dizhuPokerMarginLeft + 'px' }" style="position: fixed;top:10px;width: 100%;height: 100px">
          <div style="color: red">
              地主牌
          </div>
          <div v-for="item in game.dizhuPokerList" class="pokerDizhu" :class="{ s:item.number===16, x:item.number===17 }">
              <span v-show="item.number<16">
                  {{item.text}}
              </span>
          </div>
微笑面对bug's avatar
微笑面对bug 已提交
17
      </div>
微笑面对bug's avatar
微笑面对bug 已提交
18

19
      <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 已提交
20 21 22 23 24
          <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 已提交
25

26 27 28 29 30 31 32 33
      <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>

      <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 已提交
34
          你是 <span style="color:red;font-size: 20px">{{game.playerList[0].type==='nongmin'?'农民':'地主'}}</span>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
35
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
36
      <div :style="{ marginLeft: playerMarginLeft + 'px' }" style="position: fixed;bottom:0;width: 100%;height: 200px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
37 38 39 40
          <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 已提交
41 42 43
          </div>
      </div>

微笑面对bug's avatar
微笑面对bug 已提交
44
      <div v-show="game.currentPlayer===game.playerList[0]" style="position: fixed;bottom:200px;width: 100%;height: 100px;text-align:left;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
45 46 47 48
          <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 已提交
49 50
                  请在{{game.second}}秒内出牌
              </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
51
          </div>
微笑面对bug's avatar
微笑面对bug 已提交
52 53
      </div>

微笑面对bug's avatar
界面  
微笑面对bug 已提交
54
      <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 已提交
55 56 57 58
          <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 已提交
59
          </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
60 61
      </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 已提交
62
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
63 64 65
              pass
          </div>
      </div>
C
changjiuxiong 已提交
66 67
      <div v-if="game.stage==='jiaoFen'&&game.playerList[0].jiaoFen!=-1" :style="{ marginLeft: playerJiaoFenMargin + 'px' }" style="position: fixed;bottom:350px;width: 100%;height: 200px">
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
C
changjiuxiong 已提交
68 69 70 71 72 73
              <span v-if="game.playerList[0].jiaoFen!=0">
                  {{game.playerList[0].jiaoFen}}
              </span>
              <span v-if="game.playerList[0].jiaoFen==0">
                  不叫
              </span>
C
changjiuxiong 已提交
74 75
          </div>
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
76 77

      <div style="position: fixed;top:40px;left: 20px;height:200px;width:100px;border: solid 1px;border-radius: 8px;background-color: azure;text-align: center">
78
          <p v-show="game.stage==='play'" style="color:red;font-size: 20px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
79 80 81 82 83 84 85 86 87 88 89 90
              {{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>
91
          <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 已提交
92 93
              {{game.playerList[2].ready?'已准备':'未准备'}}
          </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
94
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
95
      <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 已提交
96 97 98 99
          <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 已提交
100 101 102
          </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 已提交
103
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
104 105 106
              pass
          </div>
      </div>
C
changjiuxiong 已提交
107
      <div v-if="game.stage==='jiaoFen'&&game.playerList[2].jiaoFen!=-1" style="position: fixed;top:100px;left:200px;height: 200px;">
108
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
C
changjiuxiong 已提交
109 110 111 112 113 114
              <span v-if="game.playerList[2].jiaoFen!=0">
                  {{game.playerList[2].jiaoFen}}
              </span>
              <span v-if="game.playerList[2].jiaoFen==0">
                  不叫
              </span>
115 116
          </div>
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
117 118

      <div style="position: fixed;top:40px;right: 20px;height:200px;width:100px;border: solid 1px;border-radius: 8px;background-color: azure;text-align: center">
119
          <p v-show="game.stage==='play'" style="color:red;font-size: 20px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
120 121 122 123 124 125 126 127 128 129 130
              {{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>
131
          <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 已提交
132 133
              {{game.playerList[1].ready?'已准备':'未准备'}}
          </div>
微笑面对bug's avatar
微笑面对bug 已提交
134
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
135
      <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 已提交
136 137 138 139
          <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 已提交
140 141 142
          </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 已提交
143
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
144 145 146
              pass
          </div>
      </div>
C
changjiuxiong 已提交
147
      <div v-if="game.stage==='jiaoFen'&&game.playerList[1].jiaoFen!=-1" style="position: fixed;top:100px;right:200px;height: 200px;">
148
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;color:#ff0000">
C
changjiuxiong 已提交
149 150 151 152 153 154
              <span v-if="game.playerList[1].jiaoFen!=0">
                  {{game.playerList[1].jiaoFen}}
              </span>
              <span v-if="game.playerList[1].jiaoFen==0">
                  不叫
              </span>
155 156
          </div>
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
157

微笑面对bug's avatar
微笑面对bug 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
  </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 已提交
176 177 178 179
      playerMarginLeft: function(){
          return (window.innerWidth - (this.game.playerList[0].pokerList.length*50))/2;
      },
      deskPokerMarginLeft: function(){
微笑面对bug's avatar
界面  
微笑面对bug 已提交
180
          return (window.innerWidth - (this.game.playerList[0].lastSendObj.poker.length*50))/2;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
181 182
      },
      buttonMarginLeft: function(){
微笑面对bug's avatar
界面  
微笑面对bug 已提交
183
          return (window.innerWidth - 400)/2;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
184
      },
C
changjiuxiong 已提交
185 186 187
      playerJiaoFenMargin: function(){
          return window.innerWidth/2 - 30;
      },
C
changjiuxiong 已提交
188 189
      dizhuPokerMarginLeft: function(){
          return (window.innerWidth - (this.game.dizhuPokerList.length*50))/2;
微笑面对bug's avatar
微笑面对bug 已提交
190 191 192 193
      },
  },
  mounted() {
    this.data = this.game.playerList[1].name;
微笑面对bug's avatar
微笑面对bug 已提交
194
    window.game = this.game;
微笑面对bug's avatar
微笑面对bug 已提交
195 196
  },
  methods:{
微笑面对bug's avatar
微笑面对bug 已提交
197 198 199 200 201 202

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

微笑面对bug's avatar
交互  
微笑面对bug 已提交
203 204 205 206 207
      enter: function(e, poker){
          if(e.buttons === 1){
              this.pickPoker(poker);
          }
      },
微笑面对bug's avatar
微笑面对bug 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

      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=[];
          }
      },

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

  },
}
</script>

<style scoped>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
240 241 242
    .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 已提交
243
        background-repeat: no-repeat;background-size: cover;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
244
    }
微笑面对bug's avatar
界面  
微笑面对bug 已提交
245

C
changjiuxiong 已提交
246 247 248 249 250 251
    .pokerDizhu{
        height:100%;width:50px;border: solid 1px;border-radius: 8px;float: left;margin-left:-25px;background-color: azure;
        font-size: 20px;
        background-repeat: no-repeat;background-size: cover;
    }

微笑面对bug's avatar
微笑面对bug 已提交
252 253 254 255 256 257 258
    .poker:hover{
        background-color: antiquewhite;
    }

    .selected{
        margin-top: -20px;
    }
微笑面对bug's avatar
界面  
微笑面对bug 已提交
259 260 261 262 263 264 265 266

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

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