疯狂数钞票H5游戏

移动端微信h5
在这里插入图片描述

<template>
  <div class="container" id="container">
    <div class="regBag"></div>
    <div class="moneyBox">
      <transition
        v-for="(item,index) in showImgList"
        :key="index"
        appear
        name="animate__animated animate__bounce"
        enter-active-class="animate__bounceOutUp"
        leave-active-class="animate__bounceOutDown"
      >
        <div class="money" key="img" style="z-index: 0;width: 104%;"></div>
      </transition>
      <div class="money" style="z-index: -50;"></div>
      <div class="money" style="z-index: -49;"></div>
      <div class="money" style="z-index: -48;"></div>
      <div class="money" style="z-index: -47;"></div>
      <div class="money" style="z-index: -46;"></div>
      <div class="money" style="z-index: -45;"></div>
      <div class="money" style="z-index: -44;"></div>
      <div class="money" style="z-index: -43;"></div>
      <div class="money" style="z-index: -42;"></div>
    </div>
    <div class="wait_tips" v-if="!startType" id="wait_tips" style="opacity: 1; transform: scale(1, 1);">
      <img src="@/assets/images/ready.png" v-if="readySrc == 0">
      <img src="@/assets/images/3.png" v-else-if="readySrc == 1">
      <img src="@/assets/images/2.png" v-else-if="readySrc == 2">
      <img src="@/assets/images/1.png" v-else-if="readySrc == 3">
      <img src="@/assets/images/go.png" v-else-if="readySrc == 4">
    </div>
    <div class="mask"></div>
    <div class="gold"></div>
    <div class="time">
      <div class="timeTxt">倒计时</div>
      <span id="time">{{ timeCount }}</span>
    </div>
    <div class="totalScore">
      积分:<span>{{ count }}</span>
    </div>
    <div class="opt">
      <div class="back_ico" id="backBtn" @click.stop="toBackIndex()"></div>
      <div class="rank_ico" id="rankBtn" v-if="rankBtnShow" @click.stop="openRankList()"></div>
    </div>
    <div class="playTips" id="playTips" :class="{touchend:touchState}" v-if="newVal === 4">
      <div class="arrow"></div>
      <div class="hand"></div>
    </div>
    <div class="rank_mask" id="rank_list" v-if="rankShow">
      <div style="height: 3em;"></div>
      <div class="close" id="closeBtn" @click.stop="closeRankList()"></div>
      <div class="rank_box"></div>
      <div class="rank_list_box">
          <div class="rank_dec"></div>
          <div class="rank_list_ranking">
              <div class="rank_list_rankingBs">
                  <div class="my_rank">
                      <p class="my_rankTop"><span class="my-rank-title">您当前排名为</span>&nbsp;&nbsp;<span class="rank_myTop" id="myTop">{{ curRank }}</span>&nbsp;&nbsp;</p>
                  </div>
                  <div class="rank" id="rankBox" style="height: 232px;">
                    <div class="rank-row" :class="{'rank-active': index === curRank - 1}" v-for="(item, index) in rankList" :key="index">
                      <span>{{ index + 1 }}</span>
                      <img :src="item.headimgurl" alt="">
                      <span class="rank-name">{{ item.nickName }}</span>
                      <span class="rank-score">{{ item.scores }}</span>
                    </div>
                  </div>
              </div>
          </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import wx from 'weixin-js-sdk';
import { getSign, getRedirectUrl, getOpenId, getUserInfo, getRankList } from "@/api/login.ts"

const showImgList = ref([])
const touchInfo = reactive({
    startX: 0,
    startY: 0
})
const touchState = ref(false)
const rankShow = ref(false)
const rankBtnShow = ref(false)
const count = ref(0)
const timeCount = ref(30)
const gameTimer = ref(null)
const codeStr:any = new URLSearchParams(window.location.search).get('code')
const openId = ref('')
const rankList = ref([])
const startType = ref(false)
const readySrc = ref(0)
const curRank = ref(0)
const getRankListData = () => {
    getRankList().then((res: any) => {
        if (res.code === 200) {
            rankList.value = res.data
            curRank.value = rankList.value.findIndex((item: any) => item.openId === openId.value) + 1
        }
    })
}
watch(timeCount, (newVal) => {
    if (newVal <= 0) {
        getRankListData()
        clearInterval(gameTimer.value);
        gameTimer.value = null
        rankShow.value = true
        readySrc.value = 0
        startType.value = false
        rankBtnShow.value = true
    }
})
watch(readySrc, (newVal) => {
    if (newVal === 4) {
        setTimeout(() => {
            startType.value = true
            timeCount.value = 30
            gameTimer.value = setInterval(function () {
                timeCount.value -= 1
            }, 1000);
        }, 1000);
    }
})
let websocket = null
// const wsUrl = 'ws://8.140.57.214:890/websocket'
const wsUrl = 'wss://h5.xqiot.top/game-socket/websocket'
const getAngle = (angx, angy) => (Math.atan2(angy, angx) * 180) / Math.PI;
const getDirection = (startx, starty, endx, endy) => {
    const angx = endx - startx;
    const angy = endy - starty;
    let result = 0;

    //如果滑动距离太短
    if (Math.abs(angx) < 2 && Math.abs(angy) < 2) {
        console.log('==>点击了一下');
        return result;
    }
    const angle = getAngle(angx, angy);
    if (angle < 0 && -90 < angle) {
        result = 1
        console.log('往【右上】滑动1');
    } else if (angle < -90 && -180 < angle) {
        result = 2
        console.log('往【左上】滑动2');
    } else if (angle < 90 && 0 < angle) {
        result = 3
        console.log('往【右下】滑动0');
    } else {
        result = 4
        console.log('往【左下】滑动0');
    }
    return result;
};
//排行榜关闭
const closeRankList = () => {
    rankShow.value = false
}
//打开排行榜
const openRankList = () => {
    getRankListData()
    rankShow.value = true
}


const getCode = () => {
    getRedirectUrl().then((res: any) => {
        if (res.code === 200) {
            window.location.href = res.data
        }
    })
}
const getSignInfo = () => {
    const params = {
        url:encodeURIComponent(location.href.split('#')[0])
    }
    getSign(params).then((res: { data: any;code:number }) => {
        if(res.code === 200) {
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                appId: 'xxx', // 必填,公众号的唯一标识
                timestamp: res.data.timestamp, // 必填,生成签名的时间戳
                nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
                signature: res.data.cardSign, // 必填,签名
                jsApiList: ['closeWindow']
            });
            getCode()
        }
    });
}

const toBackIndex = () => {
    window.location.href = 'https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=xxx==#wechat_redirect'
}
//获取随机数
const randomNum = (length = 32) => {//默认32位
    const arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
    let num = '';
    for(let i = 0;i < length;i++) {
        num += arr[parseInt(Math.random() * arr.length)];
    }
    return num;
}


const getUserData = () => {
    getUserInfo({wxCode:codeStr}).then((res:any) => {
        if(res.code === 200) {
            websocket = new WebSocket(wsUrl, openId.value)
            const msgPayload = JSON.stringify({nickname: res.data.nickname, headimgurl: res.data.headimgurl})
            websocket.onopen = function () {
                websocket.send(JSON.stringify({msgId:randomNum(32), messageType:3, msgPayload, openId:openId.value }))
            }
            websocket.onmessage = function (event) {
                const eventInfo = JSON.parse(event.data)
                if (eventInfo.messageType === 5) {
                    for (let index = 0; index < 5; index++) {
                        setTimeout(() => {
                            readySrc.value = index
                        }, index * 1000);
                    }
                }
            }
        }
    })
}
onBeforeMount(() => {
    if(!codeStr) {
        getSignInfo()
    }else{
        getOpenId({wxCode:codeStr}).then((res:any) => {
            if(res.code === 200) {
                openId.value = res.data.openid
                websocket = new WebSocket(wsUrl, openId.value);
                if(res.data.subscribe === 0) {
                    toBackIndex()
                }else{
                    getUserData()
                }

            }
        })

    }
})
onMounted(() => {

    //手指接触屏幕
    document.getElementById('container').addEventListener(
        'touchstart',
        function (e) {
            touchInfo.startX = `${e.touches[0].pageX}`;
            touchInfo.startY = `${e.touches[0].pageY}`;
            e.stopPropagation();
        },
        false
    );

    document.getElementById('container').addEventListener(
        'touchend',
        function (e) {
            const endX = e.changedTouches[0].pageX;
            const endY = e.changedTouches[0].pageY;
            const direction = getDirection(touchInfo.startX, touchInfo.startY, endX, endY);
            if(direction !== 0 && readySrc.value === 4) {
                if(touchState.value) {
                    showImgList.value.push(direction)
                    count.value += 100
                    websocket.send(JSON.stringify({ msgId: randomNum(32), messageType: 7, msgPayload: 100, openId: openId.value }))
                }
                touchState.value = true;
            }
            e.stopPropagation();
        },
        false
    );

});

</script>

<style lang='scss' scoped>
@-webkit-keyframes handSwipe {
  0% {
      top: 70vh;
      opacity: 1;
  }
  70% {
      top: 200px;
      opacity: 1;
  }
  100% {
      top: 200px;
      opacity: 0;
  }
}

@-moz-keyframes handSwipe {
  0% {
      top: 70vh;
      opacity: 1;
  }
  70% {
      top: 200px;
      opacity: 1;
  }
  100% {
      top: 200px;
      opacity: 0;
  }
}

@keyframes handSwipe {
  0% {
      top: 70vh;
      opacity: 1;
  }
  70% {
      top: 200px;
      opacity: 1;
  }
  100% {
      top: 200px;
      opacity: 0;
  }
}
.container {
  width: 100%;
  height: 100vh;
  background: url("@/assets/images/bg.jpg");
  background-size: 100% 100%;
  position: relative;
  overflow: hidden;
  bottom: 0;
  top: 0;
  left: 0;
  .regBag{
    background: url('@/assets/images/red_bag.png') no-repeat center bottom;
    width: 86%;
    height: 100%;
    position: absolute;
    bottom: -20px;
    background-size: 100% auto;
    left: 7%;
  }
  .moneyBox{
    width: 60%;
    height: 100%;
    position: relative;
    margin: 0 auto;
    .money{
      background: url('@/assets/images/money.png') no-repeat center bottom;
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      background-size: 100% auto;
      pointer-events: none;
    }
  }
  .wait_tips {
    position: absolute;
    top: 50%;
    margin-top: -50px;
    color: #fdbe22;
    font-size: 2.5rem;
    width: 100%;
    font-weight: bold;
    background: rgba(17, 17, 17, 0.6);
    padding: 20px 0;
    text-align: center;
    z-index: 998;
  }
  .mask{
    width: 86%;
    height: 135px;
    position: absolute;
    bottom: -20px;
    left: 7%;
    background: url("@/assets/images/mask.png") no-repeat center 0;
    background-size: 100% auto;
    z-index: 501;
    pointer-events: none;
  }
  .gold{
    width: 100%;
    height: 60px;
    position: absolute;
    bottom: 0;
    background: url("@/assets/images/gold.png") no-repeat center 0;
    background-size: 100% auto;
    z-index: 502;
    pointer-events: none;
  }
  .time{
    position: absolute;
    top: 15px;
    right: 20px;
    font-weight: bold;
    font-size: 1.875rem;
    color: #fff;
    div{
      display: inline-block;
      position: relative;
      top: -5px;
    }
    span{
      font-size: 3rem;
      color: #fdbe23;
      font-weight: bold;
      padding: 0 5px;
    }
  }
  .playTips{
    position: absolute;
    background-color: rgba(0, 0, 0, .5);
    z-index: 999;
    top: 0;
    width: 100%;
    height: 100%;
    .arrow{
      width: 40%;
      height: 100%;
      background: url('@/assets/images/arrow.png') no-repeat center;
      background-size: contain;
      margin: 0 auto;
    }
    .hand{
      width: 120px;
      height: 120px;
      background: url('@/assets/images/hand.png') no-repeat center;
      background-size: contain;
      position: absolute;
      top: 90vh;
      left: 50%;
      -webkit-animation: handSwipe 1.8s ease infinite;
      -moz-animation: handSwipe 1.8s ease infinite;
      animation: handSwipe 1.8s ease infinite;
    }
  }
  .touchend{
    display: none;
  }
  .totalScore{
    position: absolute;
    z-index: 10;
    top: 14%;
    width: 100%;
    text-align: center;
    color: #ffff4d;
    font-size: 2rem;
  }
  /*排行榜公共样式*/
  .rank_mask {
    position: absolute;
    background-color: rgba(0, 0, 0, .5);
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    .close {
      width: 32px;
      height: 32px;
      background: url('@/assets/images/rank_close.png') no-repeat center;
      position: absolute;
      top: 30px;
      right: 20px;
      background-size: contain;
      z-index: 10;
    }
    .rank_dec {
      width: 100%;
      height: 178px;
      background: url('@/assets/images/rank_list_dec.png') no-repeat center;
      background-size: contain;
      position: absolute;
      top: -89px;
      left: 0;
    }
    .rank_list_box {
      background: url('@/assets/images/rank_list_boxBs.png') no-repeat;
      background-size: 100% 100%;
      width: 89%;
      margin: 0 auto;
      position: relative;
      border-bottom-left-radius: 2em;
      border-bottom-right-radius: 2em;
      margin-top: 7%;
      padding: 0 11px 18px;
      .rank_list_ranking {
        padding-top: 70px;
        width: 100%;
        margin: 10px auto 0;
        .rank_list_rankingBs {
          background: url('@/assets/images/rankBs.png') no-repeat;
          background-size: 100% 100%;
          padding-bottom: 14px;
          .my_rank {
            padding-top: 18px;
            padding-bottom: 10px;
            .my_rankTop {
              margin: 0 auto;
              background-image: -webkit-linear-gradient(bottom, #c58726, #843a06, #211e14);
              -webkit-background-clip: text;
              -webkit-text-fill-color: #d8a8a800;
              .rank_myTop {
                color: #9a5612;
                text-shadow: -2px -2px 0 #fff033;
                font-size: 2rem;
              }
            }
          }
          .rank{
            height: 300px;
            overflow-y: auto;
            padding: 5px 18px;
            .rank-active{
              margin-top: 10px!important;
              margin-bottom: 10px!important;
              span{
                font-size: 1.25rem!important;
              }
            }
            .rank-row {
              margin-top: 5px;
              margin-left: 5px;
              color: #bb5b15;
              font-weight: bold;
              img {
                width: 28px;
                height: 28px;
                vertical-align: middle;
                border-radius: 50%;
                position: relative;
                top: 0;
                margin-left: 4px;
              }
              span {
                display: inline-block;
              }
              .rank-score {
                padding-left: 3px;
                width: 58px;
                text-align: right;
                padding-right: 3px;
                border-left: 2px solid #ce7e61;
                color: #c56a09;
                font-weight: bold;
              }
              .rank-name {
                width: 115px;
                text-align: left;
                padding-left: 7px;
                text-overflow: ellipsis;
                overflow: hidden;
                white-space: nowrap;
                position: relative;
                top: 3px;
              }
            }

          }
          .my_rank,.my_money{
            font-size: 1.4rem;
            font-weight: bold;
            text-align: center;
            height: 43px;
            background-size: 87%;
          }
        }
      }
    }
  }
  .opt {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 1001;
    font-size: 1.4rem;
    .back_ico {
      width: 50px;
      background: url("@/assets/images/back_ico.png") no-repeat center;
      background-size: contain;
      display: inline-block;
      padding-top: 41px;
      font-weight: bold;
      color: #fdbe22;
    }
    .rank_ico {
      width: 50px;
      background: url("cd /mnt/zctq/game/rank_ico.png") no-repeat center;
      background-size: contain;
      padding-top: 41px;
      display: inline-block;
      font-weight: bold;
      color: #fdbe22;
    }
  }
}
</style>

pc服务端

在这里插入图片描述

<!-- eslint-disable no-alert -->
<!-- eslint-disable no-alert -->

<template>
  <div class="container" id="container">
    <div id="shu-money" class="shu-money">
      <!-- 门帘 -->
      <div class="shu-money-curtain"></div>
      <!--飘钱-->
      <div id="leafContainer" v-if="playStatus !== 1">
        <div
             style="top: -15%; left: 73%; animation-name: fade, drop; animation-duration: 5.55652s, 5.55652s; animation-delay: 0.34065s, 0.34065s;">
          <img src="@/assets/images/realLeaf2.png" style="animation-name: clockwiseSpin; animation-duration: 4.71845s;">
        </div>
        <div
             style="top: -15%; left: 43%; animation-name: fade, drop; animation-duration: 6.24451s, 6.24451s; animation-delay: 1.19191s, 1.19191s;">
          <img src="@/assets/images/realLeaf3.png"
               style="animation-name: counterclockwiseSpinAndFlip; animation-duration: 5.4802s;">
        </div>
        <div
             style="top: -15%; left: 94%; animation-name: fade, drop; animation-duration: 6.0655s, 6.0655s; animation-delay: 4.09718s, 4.09718s;">
          <img src="@/assets/images/realLeaf4.png" style="animation-name: clockwiseSpin; animation-duration: 7.04969s;">
        </div>
        <div
             style="top: -15%; left: 79%; animation-name: fade, drop; animation-duration: 5.61894s, 5.61894s; animation-delay: 4.42144s, 4.42144s;">
          <img src="@/assets/images/realLeaf4.png" style="animation-name: clockwiseSpin; animation-duration: 7.69046s;">
        </div>
        <div
             style="top: -15%; left: 66%; animation-name: fade, drop; animation-duration: 8.84404s, 8.84404s; animation-delay: 4.98969s, 4.98969s;">
          <img src="@/assets/images/realLeaf1.png" style="animation-name: clockwiseSpin; animation-duration: 7.70195s;">
        </div>
        <div
             style="top: -15%; left: 40%; animation-name: fade, drop; animation-duration: 9.01992s, 9.01992s; animation-delay: 0.744s, 0.744s;">
          <img src="@/assets/images/realLeaf2.png"
               style="animation-name: counterclockwiseSpinAndFlip; animation-duration: 4.07854s;">
        </div>
        <div
             style="top: -15%; left: 90%; animation-name: fade, drop; animation-duration: 8.0395s, 8.0395s; animation-delay: 2.08446s, 2.08446s;">
          <img src="@/assets/images/realLeaf3.png"
               style="animation-name: counterclockwiseSpinAndFlip; animation-duration: 5.32582s;">
        </div>
        <div
             style="top: -15%; left: 18%; animation-name: fade, drop; animation-duration: 9.71313s, 9.71313s; animation-delay: 2.77519s, 2.77519s;">
          <img src="@/assets/images/realLeaf3.png" style="animation-name: clockwiseSpin; animation-duration: 5.03659s;">
        </div>
        <div
             style="top: -15%; left: 59%; animation-name: fade, drop; animation-duration: 5.23788s, 5.23788s; animation-delay: 4.55604s, 4.55604s;">
          <img src="@/assets/images/realLeaf1.png"
               style="animation-name: counterclockwiseSpinAndFlip; animation-duration: 7.3365s;">
        </div>
        <div
             style="top: -15%; left: 66%; animation-name: fade, drop; animation-duration: 10.4667s, 10.4667s; animation-delay: 3.90653s, 3.90653s;">
          <img src="@/assets/images/realLeaf2.png"
               style="animation-name: counterclockwiseSpinAndFlip; animation-duration: 6.4902s;">
        </div>
        <div
             style="top: -15%; left: 29%; animation-name: fade, drop; animation-duration: 9.36064s, 9.36064s; animation-delay: 1.39082s, 1.39082s;">
          <img src="@/assets/images/realLeaf4.png" style="animation-name: clockwiseSpin; animation-duration: 5.90662s;">
        </div>
        <div
             style="top: -15%; left: 34%; animation-name: fade, drop; animation-duration: 5.75967s, 5.75967s; animation-delay: 2.69622s, 2.69622s;">
          <img src="@/assets/images/realLeaf2.png" style="animation-name: clockwiseSpin; animation-duration: 4.10586s;">
        </div>
        <div
             style="top: -15%; left: 11%; animation-name: fade, drop; animation-duration: 6.39992s, 6.39992s; animation-delay: 1.7334s, 1.7334s;">
          <img src="@/assets/images/realLeaf1.png"
               style="animation-name: counterclockwiseSpinAndFlip; animation-duration: 5.01956s;">
        </div>
        <div
             style="top: -15%; left: 51%; animation-name: fade, drop; animation-duration: 9.27916s, 9.27916s; animation-delay: 4.90076s, 4.90076s;">
          <img src="@/assets/images/realLeaf3.png" style="animation-name: clockwiseSpin; animation-duration: 6.13165s;">
        </div>
        <div
             style="top: -15%; left: 75%; animation-name: fade, drop; animation-duration: 7.84955s, 7.84955s; animation-delay: 2.18257s, 2.18257s;">
          <img src="@/assets/images/realLeaf1.png" style="animation-name: clockwiseSpin; animation-duration: 7.25751s;">
        </div>
        <div
             style="top: -15%; left: 70%; animation-name: fade, drop; animation-duration: 9.56084s, 9.56084s; animation-delay: 2.74761s, 2.74761s;">
          <img src="@/assets/images/realLeaf1.png" style="animation-name: clockwiseSpin; animation-duration: 4.97211s;">
        </div>
        <div
             style="top: -15%; left: 63%; animation-name: fade, drop; animation-duration: 7.37261s, 7.37261s; animation-delay: 4.42492s, 4.42492s;">
          <img src="@/assets/images/realLeaf1.png" style="animation-name: clockwiseSpin; animation-duration: 6.98456s;">
        </div>
        <div
             style="top: -15%; left: 97%; animation-name: fade, drop; animation-duration: 6.81612s, 6.81612s; animation-delay: 2.50155s, 2.50155s;">
          <img src="@/assets/images/realLeaf4.png"
               style="animation-name: counterclockwiseSpinAndFlip; animation-duration: 5.5112s;">
        </div>
      </div>
      <!-- <div class="SecondRound" v-if="playStatus == 1">
        <div class="game_SecondRound_div">
          <div class="game_SecondRound_style"><span class="game_SecondRound">{{ playCount }}</span></div>
        </div>
      </div> -->
      <div class="shu-rank-list">
        <div class="shu-rank-item" v-for="(items,index) in readyList" :key="items.openId">
          <div class="shu-rank-item-info" v-if="Number(items.scores) > 0">
            <span class="shu-rank-item-score">{{ items.scores?items.scores:0 }}</span>
            <p class="shu-rank-item-name">{{ items.nickName?items.nickName:'' }}</p>
            <img :src="items.headimgurl">
            <span class="ranking">{{ index + 1 }}</span>
          </div>
          <div class="shu-rank-item-head"></div>
          <div class="shu-rank-item-body"></div>
          <div class="shu-rank-item-desk"></div>
          <div class="shu-rank-item-footer"></div>
        </div>
      </div>
      <div class="number-ani-box" v-if="timeShow && !gameOver">
        <img v-if="countDownNum == 30" src="@/assets/images/03.png" class="img-num imgNumberImg">
        <img v-else-if="countDownNum <30&&countDownNum >19" src="@/assets/images/02.png" class="img-num imgNumberImg">
        <img v-else-if="countDownNum <20&&countDownNum >9" src="@/assets/images/01.png" class="img-num imgNumberImg">
        <img v-else src="@/assets/images/00.png" class="img-num imgNumberImg">
        <img v-if="countDownNum == 29||countDownNum == 19||countDownNum == 9" src="@/assets/images/09.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 28||countDownNum == 18||countDownNum == 8" src="@/assets/images/08.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 27||countDownNum == 17||countDownNum == 7" src="@/assets/images/07.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 26||countDownNum == 16||countDownNum == 6" src="@/assets/images/06.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 25||countDownNum == 15||countDownNum == 5" src="@/assets/images/05.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 24||countDownNum == 14||countDownNum == 4" src="@/assets/images/04.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 23||countDownNum == 13||countDownNum == 3" src="@/assets/images/03.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 22||countDownNum == 12||countDownNum == 2" src="@/assets/images/02.png" class="img-num imgNumberImg2">
        <img v-else-if="countDownNum == 21||countDownNum == 11||countDownNum == 1" src="@/assets/images/01.png" class="img-num imgNumberImg2">
        <img v-else src="@/assets/images/00.png" class="img-num imgNumberImg2">
      </div>
      <div class="box-end" v-if="gameOver"></div>
      <!-- 准备游戏 -->
      <div class="game-cover-man" v-if="playStatus == 1">
        <div class="game-cover-manTop">
          <img src="@/assets/images/new-back-topbs.png">
        </div>
        <div class="game-cover-manCircleDiv">
          <div class="game-cover-manCircle">
          </div>
        </div>
        <div class="game-cover-manBottom"></div>
        <div class="game-cover-div">
          <div class="cover-box">
            <div class="circle-light circle-light1"></div>
            <div class="ribbon-flag"></div>
            <div class="red-lefthand red-hand1"></div>
            <div class="red-righthand red-hand1"></div>
            <div class="red-build"></div>
            <div class="glass-light"></div>
            <div class="dai-left red-hand1"></div>
            <div class="dai-right red-hand1"></div>
            <div class="icon-coin1"></div>
            <div class="icon-coin2"></div>
            <div class="icon-coin3"></div>
          </div>
          <div class="game-coverTextDiv">
            <div class="game-coverTitle">
              <span class="game-coverTitleSpan">疯狂数钞票</span>
              <span class="game-coverTitleSpan2">疯狂数钞票</span>
            </div>
          </div>
        </div>
      </div>
      <!-- 开始游戏 -->
      <div class="game-waiting-container" v-if="playStatus == 2">
        <div class="game-waiting-body">
          <div class="player-txt"></div>
          <div class="player-count">{{ readyList.length }}</div>
          <div class="player-box" style="overflow-x: auto;overflow-y:hidden">
            <span v-for="(item,index) in readyList" :key="item.openId" class="waiting-box" :style="{left: 114*Number(index)+'px',opacity: 1}">
              <img :src="item.headimgurl">
            </span>
          </div>
          <div class="game-waiting-title">
            <div class="game-w-title" data-text="疯狂数钞票">疯狂数钞票</div>
          </div>
          <!-- <div class="game-waiting-note">
            <div class="game-w-note"></div>
          </div> -->
        </div>
      </div>
      <div class="winner-container" v-if="gameOver">
        <div class="winner-body">
          <div class="box-title animate__animated animate__backInDown">
            <div class="title animate__animated animate__bounceIn animate__delay-1s"></div>
          </div>
          <div class="list-win-box">
            <div class="list-item">
              <div v-for="(items,index) in readyList" :key="items.openId"  class="box-win" style="opacity: 1;">
                <span class="name a" >{{ items.nickName }}</span>
                  <img class="a" alt="" :src="items.headimgurl" >
                  <div class="border a" style="">{{ index + 1 }}</div>
                  <span class="score a" style="">得分:<span class="score-num">{{ items.scores }}</span>
                </span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="game-countdown-divs-bg" v-if="playStatus == 3 && !timeShow && !gameOver">
        <div class="game-countdown-divs">
          <div class="game-titles-content">疯狂数钞票</div>
          <div class="game-titles">疯狂数钞票</div>
          <div class="wait-time" style="opacity: 1; transform: scale(1, 1);">
            <img src="@/assets/images/ready.png" v-if="readySrc == 0">
            <img src="@/assets/images/3.png" v-else-if="readySrc == 1">
            <img src="@/assets/images/2.png" v-else-if="readySrc == 2">
            <img src="@/assets/images/1.png" v-else-if="readySrc == 3">
            <img src="@/assets/images/go.png" v-else-if="readySrc == 4">
          </div>'
          <div class="wait-num-name"></div>
        </div>
      </div>
      <div class="hd-game-btn-container" v-if="playStatus == 1">
        <div class="hd-game-btn" @click.stop="setFullScreen()">
          <i class="iconfont icon-expand"></i>
          <span>全屏</span>
        </div>
        <div class="hd-game-btn" @click.stop="readyGame()">
          <i class="iconfont icon-go"></i>
          <span>准备</span>
        </div>
      </div>
      <div class="hd-game-btn-container" v-if="playStatus == 2">
        <div class="hd-game-btn" @click.stop="setFullScreen()">
          <i class="iconfont tools-ico icon-expand"></i>
          <span>全屏</span>
        </div>
        <div class="hd-game-btn" @click.stop="startGame()">
          <i class="iconfont icon-go"></i>
          <span>开始</span>
        </div>
      </div>
      <div class="hd-game-btn-container" v-if="playStatus == 3 && !timeShow && gameOver">
        <!-- <div class="hd-game-btn" @click.stop="rePlayGame()">
          <i class="iconfont icon-refresh"></i>
          <span>再玩</span>
        </div> -->
        <div class="hd-game-btn" @click.stop="setFullScreen()">
          <i class="iconfont tools-ico icon-expand"></i>
          <span>全屏</span>
        </div>
        <div class="hd-game-btn" @click.stop="resetGame()">
          <i class="iconfont icon-lajitong"></i>
          <span>重置</span>
        </div>
      </div>
    </div>
    <span v-if="playStatus==1" style="writing-mode: vertical-lr;
    position: relative;
    z-index: 999;
    color: #9975b3;
    font-size: 50px;
    top: 37%;
    left: 20%;">众诚天麒</span>
    <span v-if="playStatus==1" style="writing-mode: vertical-lr;
    position: relative;
    z-index: 999;
    color: #9975b3;
    font-size: 50px;
    top: 37%;
    left: 72%;">小麒物联</span>
    <div class="qr_code"  style="display: block;" v-if="playStatus!=3">
      <div class="qr_movediv" v-drag
      oncontextmenu="return false;"
      onselectstart="return false;">
        <div class="qr_code_img">
          <img src="@/assets/images/game.png" style="width: 154px;height: 154px;" alt="">
        </div>
        <span style="color: #fff;
    width: 154px;
    font-size: 30px;
    display: inline-block;
    text-align-last: justify;">小麒物联</span>
      </div>
    </div>
    <img src="@/assets/images/logo.png" style="width: 200px;height: auto;position: absolute;
    z-index: 999;
    right: 50px;top: 50px;" alt="">
  </div>
</template>

<script setup lang="ts">
import screenfull from 'screenfull'

const wsUrl = 'xxx'
const playCount = ref(1)
const playStatus = ref(1)

const readySrc = ref(0)
const timeShow = ref(false)
const countDownNum = ref(30)
const gameOver = ref(false)
const readyList = ref([])
// eslint-disable-next-line no-var
let websocket = null
let timer = null
// eslint-disable-next-line consistent-return
const setFullScreen = () => {
    //screenfull.isEnabled  此方法返回布尔值,判断当前能不能进入全屏
    if (!screenfull.isEnabled) {
        return false
    }
    //screenfull.toggle 此方法是执行全屏化操作。如果已是全屏状态,则退出全屏
    screenfull.toggle()

}
//获取随机数
const randomNum = (length = 32) => {//默认32位
    const arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
    let num = '';
    for (let i = 0; i < length; i++) {
        num += arr[parseInt(Math.random() * arr.length)];
    }
    return num;
}


watch(readySrc, (newVal) => {
    if (newVal === 4) {
        setTimeout(() => {
            timeShow.value = true
            countDownNum.value = 30
            for (let index = 0; index < 31; index++) {
                setTimeout(() => {
                    countDownNum.value = 30 - index
                }, index * 1000);
            }
        }, 1000);
    }
})
watch(countDownNum, (newVal) => {
    if (newVal === 0) {
        setTimeout(() => {
            gameOver.value = true
            timeShow.value = false
            clearInterval(timer);
            timer = null
        }, 1000);
    }
})

//准备按钮
const readyGame = () => {
    readyList.value = []
    playStatus.value = 2

    const websocket = new WebSocket(wsUrl, "943305991471");


    websocket.onopen = function () {
        timer = setInterval(function () {
            if (playStatus.value === 3) {
                clearInterval(timer);//如果距离顶部距离为0 清除定时器
            }
            websocket.send(JSON.stringify({ msgId: randomNum(32), messageType: 9, msgPayload: "", openId: '943305991471' }))
        }, 2000);
    }
    websocket.onmessage = function (event) {
        const eventInfo = JSON.parse(event.data)
        if (eventInfo.messageType === 8) {
            const list = JSON.parse(JSON.parse(event.data).msgPayload)
            if(list.length < 11) {
                readyList.value = JSON.parse(JSON.parse(event.data).msgPayload)
            }else{
                readyList.value = list.slice(0, 10)
            }
        }
    }

}
//开始按钮
const startGame = () => {
    const websocket = new WebSocket(wsUrl, "943305991471");
    websocket.onopen = function () {
        websocket.send(JSON.stringify({ msgId: randomNum(32), messageType: 5, msgPayload: "", openId: '943305991471' }))
    }
    websocket.onmessage = function (event) {
        const eventInfo = JSON.parse(event.data)
        if (eventInfo.messageType === 8) {
            const list = JSON.parse(JSON.parse(event.data).msgPayload)
            if(list.length < 11) {
                readyList.value = JSON.parse(JSON.parse(event.data).msgPayload)
            }else{
                readyList.value = list.slice(0, 10)
            }
        }
    }
    playStatus.value = 3
    clearInterval(timer);
    timer = null
    for (let index = 0; index < 5; index++) {
        setTimeout(() => {
            readySrc.value = index
        }, index * 1000);
    }
}
//再玩
// const rePlayGame = () => {
//     playCount.value++
//     playStatus.value = 1
//     gameOver.value = false
// }
//重置
const resetGame = () => {
    playStatus.value = 1
    playCount.value = 1
    gameOver.value = false
}


onMounted(() => {
    //判断当前浏览器是否支持WebSocket
    if ('WebSocket' in window) {
        websocket = new WebSocket(wsUrl, "943305991471");
    } else {
    // eslint-disable-next-line no-alert
        alert('Not support websocket');
    }
    websocket.onopen = function () {
        setInterval(function () {
            websocket.send(JSON.stringify({ msgId: randomNum(32), messageType: 2, msgPayload: "", openId: '943305991471' }));
        }, 60000);
    }
    //连接发生错误的回调方法
    websocket.onerror = function () {
    // eslint-disable-next-line no-alert
        alert("打开连接失败");
    };
    //接收到消息的回调方法
    websocket.onmessage = function (event) {
        const eventInfo = JSON.parse(event.data)
        console.log('eventInfo898', eventInfo)
    }
    //连接关闭的回调方法
    websocket.onclose = function () {
    // eslint-disable-next-line no-alert
        // alert("关闭连接成功");
    }
    //监听窗口关闭事件,当窗口关闭时,主动关闭WebSocket连接
    window.onbeforeunload = function () {
        websocket.close();
    }
})
</script>

<style lang='scss' scoped></style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/456028.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

微服务技术栈之rabbitMQ高级(二)

我们该如何确保MQ消息的可靠性&#xff1f; 如果真的发送失败&#xff0c;有没有其它的兜底方案&#xff1f; 这些问题&#xff0c;在这一次的学习中都会找到答案。 生产者的可靠性 首先&#xff0c;我们一起分析一下消息丢失的可能性有哪些。 消息从发送者发送消息&#…

leetcode一天一题-第1天

为了增加自己的代码实战能力&#xff0c;希望通过刷leetcode的题目&#xff0c;不断提高自己&#xff0c;增加对代码的理解&#xff0c;同时开拓自己的思维方面。 题目名称&#xff1a;两数之和 题目编号&#xff1a;1 题目介绍&#xff1a; 给定一个整数数组 nums 和一个整数…

Instant --java学习笔记

Instant 时间线上的某个时刻 / 时间戳过获取lnstant的对象可以拿到此刻的时间&#xff0c;该时间由两部分组成:从1970-01-01 00:00:00 开始走到此刻的总秒数不够1秒的纳秒数 Instant的常见方法&#xff1a; Instant可以用来记录代码的执行时间&#xff0c;或用于记录用户操作某…

利用Nginx正向代理实现局域网电脑访问外网

引言 在网络环境中&#xff0c;有时候我们需要让局域网内的电脑访问外网&#xff0c;但是由于网络策略或其他原因&#xff0c;直接访问外网是不可行的。这时候&#xff0c;可以借助 Nginx 来搭建一个正向代理服务器&#xff0c;实现局域网内电脑通过 Nginx 转发访问外网的需求。…

macbook使用Parallels Desktop虚拟机中使用外接拓展屏幕

macbook使用安装了windows虚拟机后&#xff0c;想让windows使用macbook外接的拓展屏&#xff0c;其实很简单&#xff0c;只需要在parallels desktop中点击全屏开启&#xff1a; 就可以在windows全屏模式下使用拓展屏幕了

Docker 镜像源配置

目录 一、 Docker 镜像源1.1 加速域名1.2 阿里云镜像源&#xff08;推荐&#xff09; 二、Docker 镜像源配置2.1 修改配置文件2.1.1 Docker Desktop 配置2.1.2 命令行配置 2.2 重启 Docker 服务2.2.1 Docker Desktop 重启2.2.2 命令行重启 2.3 检查是否配置成功 参考资料 一、 …

嘿!终于等到了!应用开发云资源套餐如约而至!

MemFire Cloud平台更新啦&#xff01;&#xff01;此次更新我们推出了万众期待的计费套餐&#xff0c;下面给大家带来详细的介绍~ 计费模式为“基础套餐按量付费”&#xff0c;您可选择购买带有一定配额的基础套餐&#xff0c;超出配额部分可以通过开启“超限按量”功能来转为…

清华大学:《AIGC发展研究资料2.0》

清华大学发布了《AIGC发展研究资料2.0》&#xff0c;该报告旨在聚焦AIGC产业发展的现状、趋势&#xff0c;从技术篇、产业篇、评测篇、职业篇、风险篇等多种角度分析产业发展。 报告还强调了该技术的应用潜力将在教育、医疗、工业制造、交通运输、法律服务等领域发挥&#xff0…

学会这几步,让酷开系统的使用体验更加出色!

在当今数字化快速发展的时代&#xff0c;用户体验&#xff08;User Experience, UX&#xff09;已成为产品和服务成功的关键因素之一。随着市场竞争的加剧&#xff0c;仅仅提供功能性强大的产品已不足以满足用户的需求&#xff0c;如何提升整体体验、确保用户的满意度和忠诚度&…

AutoMQ 社区双周精选第八期(2024.02.26~2024.03.08)

本期概要 本周新增贡献者&#xff1a; tisonkun: 优化了 E2E 测试在 Fork 仓库的定期执行问题。 funky-eyes: 修复了 s3url 未透传 pathStyle 的问题&#xff0c;并支持 HTTP S3 接入点。 版本发布重大更新&#xff1a; AutoMQ 1.0.0 GA : 经过长时间的自动化测试验证&…

OSCP-Challenge 1 - Medtech

文章目录 121靶机122靶机14靶机11靶机83靶机82靶机12靶机13靶机10靶机120靶机121靶机 进入首页后有个登录功能,点击跳转到login.aspx 在用户名处存在sql注入,sql类型是mssql。 直接用xp_cmdshell执行命令。 后面想着用powershell来反弹shell或者下载文件,发现均失败,然后…

从零开始写 Docker(六)---实现 mydocker run -v 支持数据卷挂载

本文为从零开始写 Docker 系列第六篇&#xff0c;实现类似 docker -v 的功能&#xff0c;通过挂载数据卷将容器中部分数据持久化到宿主机。 完整代码见&#xff1a;https://github.com/lixd/mydocker 欢迎 Star 推荐阅读以下文章对 docker 基本实现有一个大致认识&#xff1a; …

基于YOLOv8/YOLOv7/YOLOv6/YOLOv5的人群密度检测系统(深度学习模型+UI界面+训练数据集)

摘要&#xff1a;开发人群密度检测系统对于公共安全等领域具有关键作用。本篇博客详细介绍了如何运用深度学习构建一个人群密度检测系统&#xff0c;并提供了完整的实现代码。该系统基于强大的YOLOv8算法&#xff0c;并对比了YOLOv7、YOLOv6、YOLOv5&#xff0c;展示了不同模型…

4 配置静态IP

当我们安装好Linux后&#xff0c;需要进行网络配置&#xff0c;保障windows和linux网络相通&#xff0c;以及通过Linux可以访问外网。 1、设置VM网络&#xff1a; 1.1 选择编辑---虚拟网络编辑器 1.2 选择VMnet8设置&#xff0c;可以使用默认网段52也可以通过点击更改设置对其…

iOS 17.4 Not Installed

iOS15以后&#xff0c;下载了xcode安装好后&#xff0c;并不会自动下载好模拟器&#xff0c;需要手动下载。 有两种下载方式 xcode下载 xcode -> Settings 打开面板 xcode下载虽然方便&#xff0c;但是有个问题是&#xff0c;这里下载如果断网了不会断点续传&#xff0c;…

Rocky Linux - Primavera P6 EPPM 安装及分享

引言 继上一期发布的Redhat Linux版环境发布之后&#xff0c;近日我又制作了基于Rocky Enterprise Linux 的P6虚拟机环境&#xff0c;同样里面包含了全套P6 最新版应用服务 此虚拟机仅用于演示、培训和测试目的。如您在生产环境中使用此虚拟机&#xff0c;请先与Oracle Primav…

Matlab|计及源-荷双重不确定性的虚拟电厂/微网日前随机优化调度

目录 主要内容 1.1 场景生成及缩减 1.2 随机优化调度 程序结果&#xff1a; 主要内容 程序主要做的是一个虚拟电厂或者微网单元的日前优化调度模型&#xff0c;考虑了光伏出力和负荷功率的双重不确定性&#xff0c;采用随机规划法处理不确定性变量&#xff0c;构建了…

vscode插件开发-发布插件

安装vsce vsce是“Visual Studio Code Extensions”的缩写&#xff0c;是一个用于打包、发布和管理VS Code扩展的命令行工具。 确保您安装了Node.js。然后运行&#xff1a; npm install -g vscode/vsce 您可以使用vsce轻松打包和发布扩展&#xff1a; // 打包插件生成name…

欧盟通过全球首个重磅人工智能监管法案,预计5月生效

以下文章来源&#xff1a;华尔街见闻 欧盟的AI法案于周三获得欧盟议会批准&#xff0c;预计将于5月生效。届时&#xff0c;所有的欧盟成员国都将遵守AI法案规定。3月13日周三&#xff0c;欧盟议会批准了AI法案。该法案为AI技术设置严格的规则&#xff0c;旨在确保AI的使用不会侵…

vue插槽的基本使用

1.默认插槽 在Vue.js中&#xff0c;可以通过使用默认插槽来在组件中插入内容。默认插槽允许你在父组件中传递任意内容给子组件&#xff0c;并在子组件中使用这些内容。如果在子组件中的slot中写内容,则为默认内容,父组件未插入值的情况下显示,插入则被覆盖 父组件 <temp…
最新文章