Game.vue 10.0 KB
Newer Older
微笑面对bug's avatar
微笑面对bug 已提交
1
<template>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
2 3
  <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')+')'}">
    <div v-show="false" style="width: 300px;height:300px;float: left; position: fixed ; left: 0; top: 0px; background-color: aliceblue; text-align: center">
微笑面对bug's avatar
微笑面对bug 已提交
4
        <span>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
5
            手牌:{{player2Str[1]}}
微笑面对bug's avatar
微笑面对bug 已提交
6 7 8
        </span>
    </div>

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

微笑面对bug's avatar
界面  
微笑面对bug 已提交
15
    <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 已提交
16
      <div style="width: 300px;word-wrap: break-word;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
17 18
          已出的牌:
          <br/>
微笑面对bug's avatar
微笑面对bug 已提交
19 20 21 22
          {{deskStr[1]}}
      </div>
    </div>

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

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

微笑面对bug's avatar
界面  
微笑面对bug 已提交
38
      <div style="position: fixed;bottom:200px;width: 100%;height: 100px;text-align:left;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
39 40 41 42
          <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 已提交
43 44
                  请在{{game.second}}秒内出牌
              </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
45
          </div>
微笑面对bug's avatar
微笑面对bug 已提交
46 47
      </div>

微笑面对bug's avatar
界面  
微笑面对bug 已提交
48
      <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 已提交
49 50 51 52
          <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 已提交
53
          </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
54 55 56
      </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">
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
57 58 59 60 61
              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">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
62
          <p style="color:red;font-size: 20px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75
              {{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>
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
76
      <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 已提交
77 78 79 80
          <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 已提交
81 82 83 84 85 86 87
          </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;">
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;">
              pass
          </div>
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
88 89

      <div style="position: fixed;top:40px;right: 20px;height:200px;width:100px;border: solid 1px;border-radius: 8px;background-color: azure;text-align: center">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
90
          <p style="color:red;font-size: 20px">
微笑面对bug's avatar
界面  
微笑面对bug 已提交
91 92 93 94 95 96 97 98 99 100 101
              {{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>
微笑面对bug's avatar
微笑面对bug 已提交
102
      </div>
微笑面对bug's avatar
界面  
微笑面对bug 已提交
103
      <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 已提交
104 105 106 107
          <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 已提交
108 109 110 111 112 113 114 115
          </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;">
          <div style="height:100%;width:100px;float: left;margin-left:-50px;font-size: 50px;">
              pass
          </div>
      </div>

微笑面对bug's avatar
微笑面对bug 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
  </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 已提交
134 135 136 137
      playerMarginLeft: function(){
          return (window.innerWidth - (this.game.playerList[0].pokerList.length*50))/2;
      },
      deskPokerMarginLeft: function(){
微笑面对bug's avatar
界面  
微笑面对bug 已提交
138
          return (window.innerWidth - (this.game.playerList[0].lastSendObj.poker.length*50))/2;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
139 140
      },
      buttonMarginLeft: function(){
微笑面对bug's avatar
界面  
微笑面对bug 已提交
141
          return (window.innerWidth - 400)/2;
微笑面对bug's avatar
界面  
微笑面对bug 已提交
142 143
      },

微笑面对bug's avatar
微笑面对bug 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157
      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 已提交
158
              game.playerList[i].lastSendObjToString()
微笑面对bug's avatar
微笑面对bug 已提交
159 160 161 162 163 164 165 166
          ];
        },
      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 已提交
167
              game.playerList[i].lastSendObjToString()
微笑面对bug's avatar
微笑面对bug 已提交
168 169 170 171 172 173 174 175
          ];
      },
      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 已提交
176
              game.playerList[i].lastSendObjToString()
微笑面对bug's avatar
微笑面对bug 已提交
177 178 179 180 181 182 183 184 185 186 187 188
          ];
      },
      deskStr: function () {
          let game = this.game;
          return [
              'desk',
              game.pokerListToString()
          ];
      },
  },
  mounted() {
    this.data = this.game.playerList[1].name;
微笑面对bug's avatar
微笑面对bug 已提交
189
    window.game = this.game;
微笑面对bug's avatar
微笑面对bug 已提交
190 191
  },
  methods:{
微笑面对bug's avatar
交互  
微笑面对bug 已提交
192 193 194 195 196
      enter: function(e, poker){
          if(e.buttons === 1){
              this.pickPoker(poker);
          }
      },
微笑面对bug's avatar
微笑面对bug 已提交
197 198 199 200 201 202 203 204 205 206 207 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 240 241

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

微笑面对bug's avatar
微笑面对bug 已提交
248 249 250 251 252 253 254
    .poker:hover{
        background-color: antiquewhite;
    }

    .selected{
        margin-top: -20px;
    }
微笑面对bug's avatar
界面  
微笑面对bug 已提交
255 256 257 258 259 260 261 262

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

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