Browse Source

日常开发

林旭祥 1 week ago
parent
commit
fca8fde8b2

BIN
public/static/images/game/square.png


+ 0 - 855
src/components/SquareGame/index copy.vue

@@ -1,855 +0,0 @@
-<!DOCTYPE html>
-<html>
-  <head>
-    <meta charset="utf-8" />
-    <title>Square Jump</title>
-    <style type="text/css">
-      * {
-        padding: 0px;
-        margin: 0px;
-      }
-      a {
-        text-decoration: none;
-        list-style: none;
-        color: rgb(0, 0, 0);
-      }
-      #main_box {
-        margin: 0px auto;
-        width: 420px;
-        height: 580px;
-        background: skyblue;
-        position: relative;
-        overflow: hidden;
-      }
-      .can {
-        position: absolute;
-        top: 0px;
-        left: 0px;
-      }
-      #score {
-        width: auto;
-        height: 40px;
-        font-size: 22px;
-        color: #7fffd4;
-        position: absolute;
-        top: 10px;
-        left: 10px;
-        display: none;
-      }
-      #game_title {
-        display: none;
-        position: absolute;
-        width: 240px;
-        height: 80px;
-        line-height: 80px;
-        text-align: center;
-        top: 35%;
-        left: 50%;
-        margin-left: -120px;
-        font-size: 42px;
-        font-family: "century gothic";
-        font-weight: bolder;
-        text-shadow: 4px 3px 2px black;
-        color: #fff;
-      }
-      #login_btn {
-        display: none;
-        position: absolute;
-        bottom: 100px;
-        left: 50%;
-        width: 100px;
-        height: 40px;
-        margin-left: -50px;
-        line-height: 40px;
-        text-align: center;
-        border-radius: 12px;
-        border: 2px solid #ffffff;
-        font-size: 18px;
-        color: #000000;
-        font-weight: normal;
-        background: peachpuff;
-      }
-      #login_btn:hover {
-        color: #fff;
-      }
-      #login_btn:active {
-        background: #ffffff;
-        color: #000000;
-      }
-      #square_main {
-        width: 40px;
-        height: 40px;
-        position: absolute;
-        top: 0px;
-        left: 0px;
-        border: 2px solid #ffffff;
-        display: none;
-        background: #ff6688;
-      }
-      #state {
-        width: 280px;
-        height: 60px;
-        font-size: 18px;
-        font-weight: bolder;
-        text-shadow: #fdf5e6;
-        color: blueviolet;
-        font-family: "arial narrow";
-        position: absolute;
-        top: 45%;
-        left: 50%;
-        line-height: 60px;
-        text-align: center;
-        margin-left: -140px;
-        display: none;
-      }
-      #colorChangeTime_div {
-        width: 200px;
-        height: 50px;
-        line-height: 50px;
-        position: absolute;
-        text-align: center;
-        top: 3%;
-        left: 50%;
-        display: none;
-        color: #ffffff;
-        font-size: 40px;
-      }
-    </style>
-  </head>
-  <body>
-    <div id="main_box">
-      <canvas id="myCanvas1" class="can"></canvas>
-      <canvas id="myCanvas2" class="can"></canvas>
-      <a href="javascript:loginGame()" id="login_btn">开始游戏</a>
-      <div id="score"></div>
-      <div id="game_title">方&nbsp;块&nbsp;跳&nbsp;跃</div>
-      <div id="state"></div>
-      <span id="square_main"></span>
-      <div id="colorChangeTime_div">10</div>
-    </div>
-    <script>
-      var can1;
-      var can2;
-      var ctx1;
-      var ctx2;
-      var canWidth = 820;
-      var canHeight = 640;
-      var maxHeight = window.innerHeight;
-      var maxWidth = window.innerWidth;
-
-      var beginGame;
-      var gameOver;
-
-      var backrgound;
-      var squares;
-      var mySquare;
-
-      var beginAnim; //开始界面动画
-
-      var lastTime;
-      var changeColorTime;
-      var changeTimeArrays = [
-        "10",
-        "9",
-        "8",
-        "7",
-        "6",
-        "5",
-        "4",
-        "3",
-        "2",
-        "1",
-        "color change!",
-      ];
-      var changeColorindex = 0;
-      var totalSpeed = 3;
-
-      var isStep;
-
-      var colorChangeTimeW = 0;
-
-      var score;
-
-      let AnimPX = [];
-      let AnimPY = [];
-      let jump_count = 0;
-
-      const squareColor = [
-        "#FF6688",
-        "#00FF00",
-        "#3399FF",
-        "#FFDAB9",
-        "blueviolet",
-      ];
-      document.body.onload = game;
-
-
-      function init() {
-        score = 0;
-        beginGame = false;
-        gameOver = false;
-        isStep = false;
-
-        lastTime = Date.now();
-
-        can1 = document.getElementById("myCanvas1");
-        ctx1 = can1.getContext("2d");
-        can2 = document.getElementById("myCanvas2");
-        ctx2 = can2.getContext("2d");
-
-        if (maxWidth != canWidth) {
-          canWidth = maxWidth;
-        }
-        if (maxHeight != canHeight) {
-          canHeight = maxHeight;
-        }
-
-        const mainBox = document.getElementById("main_box");
-        mainBox.style.width = canWidth + "px";
-        mainBox.style.height = canHeight + "px";
-
-        can1.width = canWidth;
-        can2.width = canWidth;
-        can1.height = canHeight;
-        can2.height = canHeight;
-
-        // 模拟 slideDown 效果
-        const gameTitle = document.getElementById("game_title");
-        gameTitle.style.display = "block";
-        gameTitle.style.height = "0";
-        gameTitle.style.overflow = "hidden";
-        setTimeout(() => {
-          gameTitle.style.height = "auto";
-        }, 0);
-
-        // 模拟 delay 和 slideToggle 效果
-        const loginBtn = document.getElementById("login_btn");
-        setTimeout(() => {
-          loginBtn.style.display = "block";
-          loginBtn.style.height = "0";
-          loginBtn.style.overflow = "hidden";
-          setTimeout(() => {
-            loginBtn.style.height = "auto";
-          }, 10);
-        }, 500);
-
-        colorChangeTimeW = (canHeight > canWidth ? canWidth : canHeight) * 0.5;
-        const colorChangeTimeDiv = document.getElementById(
-          "colorChangeTime_div"
-        );
-        colorChangeTimeDiv.style.width = colorChangeTimeW * 1.6 + "px";
-        colorChangeTimeDiv.style.height = colorChangeTimeW * 0.5 + "px";
-        colorChangeTimeDiv.style.marginLeft = -colorChangeTimeW * 0.8 + "px";
-        colorChangeTimeDiv.style.lineHeight = colorChangeTimeW * 0.5 + "px";
-        colorChangeTimeDiv.style.fontSize = colorChangeTimeW * 0.3 + "px";
-
-        backrgound = new backgroundObj();
-        backrgound.init();
-
-        squares = new squareObj();
-        squares.init();
-
-        mySquare = new mySquareObj();
-        mySquare.init();
-
-        beginAnim = new beginAnimObj();
-        beginAnim.init();
-      }
-
-      function restartInit() {
-        AnimPX = new Array();
-        AnimPY = new Array();
-        changeColorindex = 0;
-        jump_count = 0;
-
-        // 隐藏元素
-        document.getElementById("colorChangeTime_div").style.display = "none";
-        document.getElementById("score").style.display = "none";
-
-        // 初始化动画
-        beginAnim.init();
-
-        // 设置游戏状态
-        beginGame = false;
-        gameOver = true;
-        lastTime = Date.now();
-
-        // 设置游戏标题
-        const gameTitle = document.getElementById("game_title");
-        gameTitle.innerHTML = "方&nbsp;块&nbsp;跳&nbsp;跃";
-
-        // 显示游戏标题(模拟slideDown效果)
-        gameTitle.style.display = "block";
-        gameTitle.style.height = "0";
-        gameTitle.style.overflow = "hidden";
-        setTimeout(() => {
-          gameTitle.style.height = "auto";
-        }, 0);
-
-        // 延迟显示登录按钮(模拟delay和slideToggle效果)
-        const loginBtn = document.getElementById("login_btn");
-        setTimeout(() => {
-          loginBtn.style.display = "block";
-          loginBtn.style.height = "0";
-          loginBtn.style.overflow = "hidden";
-          setTimeout(() => {
-            loginBtn.style.height = "auto";
-          }, 10);
-        }, 500);
-
-        // 设置登录按钮文本
-        loginBtn.innerHTML = "再来一次";
-
-        // 显示状态(模拟slideDown效果)
-        const state = document.getElementById("state");
-        state.style.display = "block";
-        state.style.height = "0";
-        state.style.overflow = "hidden";
-        setTimeout(() => {
-          state.style.height = "auto";
-        }, 500);
-
-        // 设置状态文本
-        state.innerHTML = "游戏结束,得分:" + Math.floor(score);
-      }
-
-      function game() {
-        init();
-        loop = setInterval(gameloop, 20);
-      }
-      function restart() {
-        // 调用初始化方法
-        backrgound.init();
-        squares.init();
-        mySquare.init();
-
-        // 更新时间戳
-        lastTime = Date.now();
-
-        // 隐藏元素
-        document.getElementById("state").style.display = "none";
-        document.getElementById("game_title").style.display = "none";
-        document.getElementById("login_btn").style.display = "none";
-
-        // 显示分数
-        document.getElementById("score").style.display = "block";
-
-        // 重置分数和速度
-        score = 0;
-        totalSpeed = 3;
-      }
-      function gameloop() {
-        backrgound.draw();
-        ctx2.clearRect(0, 0, canWidth, canHeight);
-        ctx2.save();
-
-        if (beginAnim.isLive && Date.now() - lastTime > 1000) {
-          beginAnim.draw();
-        }
-
-        if (beginGame && !gameOver) {
-          document.getElementById("score").innerHTML =
-            "得分:" + Math.floor(score);
-          addSpeed();
-          squares.draw();
-          mySquare.draw();
-          squaresToMy();
-
-          // 添加点击事件监听器
-          const mainBox = document.getElementById("main_box");
-          mainBox.addEventListener("click", function () {
-            mySquare.jump();
-          });
-        } else if (gameOver && !beginGame) {
-          // 这里可以添加游戏结束时的逻辑
-        }
-
-        ctx2.restore();
-      }
-      function loginGame() {
-        changeColorTime = Date.now();
-
-        // 显示颜色变化时间div
-        const colorChangeTimeDiv = document.getElementById(
-          "colorChangeTime_div"
-        );
-        colorChangeTimeDiv.style.display = "block";
-
-        // 随机设置颜色
-        const randomColor =
-          squareColor[Math.floor(Math.random() * squareColor.length)];
-        colorChangeTimeDiv.style.color = randomColor;
-
-        // 设置颜色变化时间div的内容
-        colorChangeTimeDiv.innerHTML = "" + changeTimeArrays[changeColorindex];
-
-        if (!gameOver && !beginGame) {
-          // 显示分数,隐藏游戏标题和方块
-          document.getElementById("score").style.display = "block";
-          document.getElementById("game_title").style.display = "none";
-          document.getElementById("square_main").style.display = "none";
-
-          // 设置游戏状态
-          beginGame = true;
-
-          // 隐藏登录按钮
-          document.getElementById("login_btn").style.display = "none";
-        } else if (gameOver && !beginGame) {
-          // 重新开始游戏
-          restart();
-
-          // 更新游戏状态
-          gameOver = false;
-          beginGame = true;
-        }
-
-        // 设置动画状态
-        beginAnim.isLive = false;
-
-        // 隐藏方块
-        document.getElementById("square_main").style.display = "none";
-      }
-      function addSpeed() {
-        totalSpeed += 0.04 * 0.05;
-        score += 0.04;
-      }
-      function squaresToMy() {
-        for (var i = 0; i < squares.num; i++) {
-          if (squares.isLive[i]) {
-            if (squares.color[i] != mySquare.color) {
-              if (mySquare.isLive) {
-                if (
-                  ((mySquare.x + mySquare.l - 1 > squares.x[i] &&
-                    mySquare.x + mySquare.l - 1 < squares.x[i] + squares.w[i] &&
-                    mySquare.x + mySquare.l - 30 > squares.x[i] &&
-                    mySquare.x + mySquare.l - 30 <
-                      squares.x[i] + squares.w[i]) ||
-                    (mySquare.x > squares.x[i] &&
-                      mySquare.x + 10 < squares.x[i] + squares.w[i] &&
-                      mySquare.x + 10 > squares.x[i] &&
-                      mySquare.x + 10 < squares.x[i] + squares.w[i])) &&
-                  mySquare.y + mySquare.l > squares.y[i] &&
-                  mySquare.y + mySquare.l < squares.y[i] + squares.h[i]
-                ) {
-                  mySquare.y = squares.y[i] - mySquare.l;
-                  mySquare.toVSpeed = -totalSpeed * 0.2;
-                  mySquare.toDownSpeed = 0;
-                  jump_count = 0;
-                }
-                if (
-                  mySquare.x + mySquare.l > squares.x[i] &&
-                  mySquare.x + mySquare.l < squares.x[i] + squares.w[i] &&
-                  mySquare.y + mySquare.l > squares.y[i] &&
-                  mySquare.y + mySquare.l < squares.y[i] + squares.h[i]
-                ) {
-                  mySquare.x = squares.x[i] - mySquare.l;
-                }
-              }
-            }
-          }
-        }
-      }
-
-      class backgroundObj {
-        constructor() {
-          this.x = [];
-          this.y = [];
-          this.w = [];
-          this.h = [];
-          this.isLive = [];
-          this.num = 3;
-        }
-
-        init() {
-          for (let i = 0; i < this.num; i++) {
-            this.x[i] =
-              i === 0
-                ? canWidth * 0.1 * Math.random()
-                : this.x[i - 1] +
-                  this.w[i - 1] +
-                  canWidth * 0.2 * i * Math.random();
-
-            this.w[i] = canWidth * 0.08 + canHeight * Math.random() * 0.3;
-            this.h[i] = canHeight * 0.08 + canWidth * Math.random() * 0.3;
-            this.y[i] = canHeight * 0.2 * Math.random();
-            this.isLive[i] = true;
-          }
-        }
-
-        cloudBorn() {
-          for (let i = 0; i < this.num; i++) {
-            if (!this.isLive[i]) {
-              this.w[i] = canWidth * 0.08 + canWidth * Math.random() * 0.3;
-              this.h[i] = canHeight * 0.08 + canHeight * Math.random() * 0.3;
-              this.y[i] = canHeight * 0.2 * Math.random();
-
-              this.x[i] = i === 0 ? canWidth : canWidth + i * this.w[i - 1];
-
-              this.isLive[i] = true;
-            }
-          }
-        }
-
-        draw() {
-          ctx1.clearRect(0, 0, canWidth, canHeight);
-          ctx1.save();
-
-          for (let i = 0; i < this.num; i++) {
-            if (!this.isLive[i]) continue;
-
-            this.x[i] -= 0.1 * totalSpeed;
-            const maxSize = Math.max(this.h[i], this.w[i]) * 0.15;
-            const smallSize = Math.max(this.h[i], this.w[i]) * 0.1;
-
-            // 绘制云朵的各个部分
-            const cloudParts = [
-              { x: 0.4, y: 0.1, size: maxSize },
-              { x: 0.1, y: 0.2, size: maxSize },
-              { x: 0.6, y: 0.25, size: maxSize },
-              { x: 0.5, y: 0.3, size: maxSize },
-              { x: 0.65, y: 0.22, size: maxSize },
-              { x: 0.2, y: 0.35, size: maxSize },
-              { x: 0.35, y: 0.35, size: smallSize },
-              { x: 0.3, y: 0.1, size: maxSize },
-            ];
-
-            ctx1.fillStyle = "#ffffff";
-            cloudParts.forEach((part) => {
-              ctx1.beginPath();
-              ctx1.arc(
-                this.x[i] + this.w[i] * part.x,
-                this.y[i] + this.h[i] * part.y,
-                part.size,
-                0,
-                Math.PI * 2
-              );
-              ctx1.fill();
-              ctx1.closePath();
-            });
-
-            if (this.x[i] + this.w[i] < 0) {
-              this.isLive[i] = false;
-            }
-          }
-
-          ctx1.restore();
-          this.cloudBorn();
-        }
-      }
-
-      class squareObj {
-        constructor() {
-          this.num = 12;
-          this.x = [];
-          this.y = [];
-          this.w = [];
-          this.h = [];
-          this.color = [];
-          this.isLive = [];
-        }
-
-        init() {
-          let repeatColorCount = 0;
-
-          for (let i = 0; i < this.num; i++) {
-            // Random color selection with constraints
-            this.color[i] = this.getRandomColor(i, repeatColorCount);
-
-            // Position and size initialization
-            if (i === 0) {
-              this.x[i] = 0;
-            } else {
-              this.x[i] = this.x[i - 1] + this.w[i - 1] + 1;
-            }
-
-            this.h[i] = canHeight * 0.3 + canHeight * 0.25 * Math.random();
-            this.w[i] = canWidth * 0.15 + canWidth * 0.06 * Math.random();
-            this.y[i] = canHeight - this.h[i];
-            this.isLive[i] = true;
-
-            // Update repeat color count
-            repeatColorCount =
-              this.color[i] === this.color[i - 1] ? repeatColorCount + 1 : 0;
-
-            // Handle consecutive colors
-            if (repeatColorCount > 1) {
-              this.adjustColor(i);
-            }
-          }
-        }
-
-        getRandomColor(i, repeatColorCount) {
-          const randomIndex = Math.floor(Math.random() * squareColor.length);
-          let color = squareColor[randomIndex];
-
-          // For the first element, check against last element
-          if (i === 0 && color === this.color[this.num - 1]) {
-            const lastColorIndex = squareColor.indexOf(
-              this.color[this.num - 1]
-            );
-            color =
-              squareColor[
-                (lastColorIndex - 1 + squareColor.length) % squareColor.length
-              ];
-          }
-          // For other elements, check against previous element
-          else if (
-            i > 0 &&
-            color === this.color[i - 1] &&
-            repeatColorCount > 1
-          ) {
-            const currentColorIndex = squareColor.indexOf(color);
-            color = squareColor[(currentColorIndex + 1) % squareColor.length];
-          }
-
-          return color;
-        }
-
-        adjustColor(i) {
-          if (i === 0) {
-            const lastColorIndex = squareColor.indexOf(
-              this.color[this.num - 1]
-            );
-            this.color[i] =
-              squareColor[
-                (lastColorIndex - 1 + squareColor.length) % squareColor.length
-              ];
-          } else {
-            const currentColorIndex = squareColor.indexOf(this.color[i]);
-            this.color[i] =
-              squareColor[(currentColorIndex + 1) % squareColor.length];
-          }
-        }
-
-        squareBorn() {
-          const maxX = Math.max(
-            ...this.x.map((val, idx) => val + (this.w[idx] || 0))
-          );
-          const maxI = this.x.indexOf(
-            maxX - (this.w[this.x.indexOf(maxX)] || 0)
-          );
-
-          for (let i = 0; i < this.num; i++) {
-            if (!this.isLive[i]) {
-              this.x[i] = maxX + 1;
-              this.h[i] = canHeight * 0.25 + canHeight * 0.35 * Math.random();
-              this.w[i] = canWidth * 0.14 + canWidth * 0.1 * Math.random();
-              this.y[i] = canHeight - this.h[i];
-
-              let repeatColorCount = 0;
-              if (i === 0 && this.isLive[this.num - 1]) {
-                this.color[i] = this.getRandomColorForBorn(
-                  this.num - 1,
-                  repeatColorCount
-                );
-              } else if (i > 0 && this.isLive[i - 1]) {
-                this.color[i] = this.getRandomColorForBorn(
-                  i - 1,
-                  repeatColorCount
-                );
-              }
-
-              this.isLive[i] = true;
-              return;
-            }
-          }
-        }
-
-        getRandomColorForBorn(prevIndex, repeatColorCount) {
-          const randomIndex = Math.floor(Math.random() * 3);
-          let color = squareColor[randomIndex];
-
-          if (color === this.color[prevIndex] && repeatColorCount > 1) {
-            const currentColorIndex = squareColor.indexOf(color);
-            color = squareColor[(currentColorIndex + 1) % squareColor.length];
-          }
-
-          return color;
-        }
-
-        draw() {
-          for (let i = 0; i < this.num; i++) {
-            if (this.isLive[i]) {
-              ctx2.fillStyle = this.color[i];
-              ctx2.beginPath();
-              ctx2.fillRect(this.x[i], this.y[i], this.w[i], this.h[i]);
-              ctx2.fill();
-              ctx2.closePath();
-              this.x[i] -= totalSpeed;
-            }
-
-            if (this.x[i] + this.w[i] < 0) {
-              this.isLive[i] = false;
-            }
-          }
-
-          this.squareBorn();
-        }
-      }
-
-      class mySquareObj {
-        constructor() {
-          this.x;
-          this.y;
-          this.isLive; // 生命状态
-          this.l = 40; // 正方形边长
-          this.color;
-          this.toDownSpeed = 0; // 垂直方向速度
-          this.toVSpeed = 0; // 水平方向速度
-        }
-
-        init() {
-          this.isLive = true;
-          this.x = 0;
-          this.y = 0;
-          this.l = 40;
-          this.toDownSpeed = 0;
-          this.toVSpeed = 0;
-          this.color = squareColor[0];
-        }
-
-        jump() {
-          if (this.isLive) {
-            this.toDownSpeed = -15;
-            this.toVSpeed = 2;
-            jump_count++;
-            if (this.x + this.l > canWidth) {
-              this.x = canWidth - this.l;
-            }
-          }
-        }
-
-        toDown() {
-          if (this.isLive) {
-            this.toDownSpeed += 9.8 * 1 * 0.06;
-            this.y += this.toDownSpeed;
-            this.x += this.toVSpeed;
-            if (this.y + this.l > canHeight) {
-              this.isLive = false;
-            }
-          }
-        }
-
-        draw() {
-          if (this.isLive) {
-            const now = Date.now();
-            if (now - changeColorTime > 1000) {
-              changeColorindex = ++changeColorindex % changeTimeArrays.length;
-              const strColor =
-                "" +
-                squareColor[Math.floor(Math.random() * squareColor.length)];
-
-              // 获取元素
-              const colorChangeTimeDiv = document.getElementById(
-                "colorChangeTime_div"
-              );
-
-              // 设置颜色和内容
-              colorChangeTimeDiv.style.color = strColor;
-              colorChangeTimeDiv.textContent =
-                "" + changeTimeArrays[changeColorindex];
-
-              if (changeColorindex === 10) {
-                colorChangeTimeDiv.style.fontSize =
-                  colorChangeTimeW * 0.15 + "px";
-                this.color = strColor;
-              } else {
-                colorChangeTimeDiv.style.fontSize =
-                  colorChangeTimeW * 0.3 + "px";
-              }
-
-              changeColorTime = now;
-            }
-            ctx2.fillStyle = this.color + "";
-            ctx2.rect(this.x, this.y, this.l, this.l);
-            ctx2.fill();
-            ctx2.lineWidth = 3;
-            ctx2.radiusX = 3;
-
-            ctx2.strokeStyle = "#ffffff";
-            ctx2.stroke();
-            if (this.x < -100) {
-              this.isLive = false;
-            }
-          } else {
-            restartInit();
-          }
-          this.toDown();
-        }
-      }
-
-      class beginAnimObj {
-        constructor() {
-          this.x;
-          this.y;
-          this.isLive;
-          this.l = 40; // 正方形边长
-          this.color;
-          this.toDownSpeed = 0; // 垂直方向速度
-          this.toVSpeed = canWidth * 0.021; // 水平方向速度
-        }
-
-        init() {
-          this.isLive = true;
-          this.x = 0;
-          this.y = 0;
-          this.toDownSpeed = 0;
-          this.toVSpeed = canWidth * 0.021;
-          this.color = squareColor[0];
-        }
-
-        jump() {
-          if (this.isLive) {
-            this.toDownSpeed = -this.toDownSpeed;
-            this.toVSpeed = canWidth * 0.021 * 0.5;
-            jump_count++;
-            if (this.x + this.l > canWidth) {
-              this.x = canWidth - this.l;
-            }
-            this.x += this.toVSpeed;
-            if (this.toVSpeed + 2 < 3) {
-              this.toVSpeed += 1;
-            }
-          }
-        }
-
-        toDown() {
-          if (this.isLive) {
-            this.toDownSpeed += 9.8 * 1 * 0.06;
-            this.y += this.toDownSpeed;
-            this.x += this.toVSpeed;
-            if (this.y > canHeight) {
-              this.isLive = false;
-            }
-          }
-        }
-
-        draw() {
-          if (this.isLive) {
-            const squareMain = document.getElementById("square_main");
-            const gameTitle = document.getElementById("game_title");
-
-            squareMain.style.display = "block";
-            squareMain.style.left = this.x + "px";
-            squareMain.style.top = this.y + "px";
-
-            if (
-              this.y + this.l > canHeight * 0.35 &&
-              this.x + this.l * 0.5 < canWidth * 0.5 + 120 &&
-              this.x + this.l * 0.5 > canWidth * 0.5 - 120
-            ) {
-              this.jump();
-              gameTitle.innerHTML =
-                "方&nbsp;块&nbsp;<i style='font-size: 46px;color:#FF6688;'>跳&nbsp;</i>跃";
-            }
-
-            ctx2.restore();
-            this.toDown();
-          } else {
-            document.getElementById("square_main").style.display = "none";
-          }
-        }
-      }
-    </script>
-  </body>
-</html>

+ 2 - 1
src/router/index.ts

@@ -20,7 +20,6 @@ const router = createRouter({
         { path: '/train/run', component: () => import('@/views/train/run.vue') },
         { path: '/train/multiple', component: () => import('@/views/train/multiple.vue') },
         { path: '/train/device', component: () => import('@/views/train/device.vue') },
-        { path: '/train/game', component: () => import('@/views/train/game.vue') },
         { path: '/test', component: () => import('@/views/test/index.vue') },
         { path: '/set', component: () => import('@/views/set/index.vue') },
         { path: '/set/config', component: () => import('@/views/set/config.vue') },
@@ -31,6 +30,8 @@ const router = createRouter({
         { path: '/analysis/index', component: () => import('@/views/analysis/index.vue') },
         { path: '/analysis/detail', component: () => import('@/views/analysis/detail.vue') },
         { path: '/sunshineRun', component: () => import('@/views/sunshineRun/index.vue') },
+        { path: '/game', component: () => import('@/views/game/index.vue') },
+        { path: '/game/square', component: () => import('@/views/game/square.vue') },
       ]
     }
   ]

+ 5 - 1
src/types/components.d.ts

@@ -9,14 +9,18 @@ declare module 'vue' {
   export interface GlobalComponents {
     ChooseStudent: typeof import('./../components/ChooseStudent/index.vue')['default']
     copy: typeof import('./../components/SquareGame/index copy.vue')['default']
+    ElAvatar: typeof import('element-plus/es')['ElAvatar']
+    ElButton: typeof import('element-plus/es')['ElButton']
     ElIcon: typeof import('element-plus/es')['ElIcon']
     ElInput: typeof import('element-plus/es')['ElInput']
     ElOption: typeof import('element-plus/es')['ElOption']
+    ElPagination: typeof import('element-plus/es')['ElPagination']
     ElSelect: typeof import('element-plus/es')['ElSelect']
     ElSwitch: typeof import('element-plus/es')['ElSwitch']
+    ElTable: typeof import('element-plus/es')['ElTable']
+    ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
     FaceWindow: typeof import('./../components/FaceWindow/index.vue')['default']
     Header: typeof import('./../components/Header/index.vue')['default']
-    'Index copy': typeof import('./../components/SquareGame/index copy.vue')['default']
     JumpRopeGame: typeof import('./../components/JumpRopeGame/index.vue')['default']
     MultipleItem: typeof import('./../components/MultipleItem/index.vue')['default']
     MultipleItemRanking: typeof import('./../components/MultipleItemRanking/index.vue')['default']

+ 247 - 0
src/views/game/index.vue

@@ -0,0 +1,247 @@
+<template>
+  <div class="game">
+    <Header @confirmExit="getExit" :showTool="false" closeClass="close2"></Header>
+    <div class="menu" v-if="projectList.length" :class="projectList.length <= 12 ? 'menu1' : 'menu2'"
+      :key="projectList.length">
+      <swiper :slides-per-view="6" :modules="[Grid]" :grid="{
+        fill: projectList.length <= 12 ? 'row' : 'column',
+        rows: 2,
+      }" :space-between="20" :slides-per-group="12">
+        <swiper-slide v-for="(item, index) in projectList" :key="index" @click="getJump(item)">
+          <div class="li">
+            <div>
+              <div class="pic"><img :src="'static/images/game/' + item.key + '.png'" /></div>
+              <div class="name">
+                {{ item.name }}
+              </div>
+            </div>
+          </div>
+        </swiper-slide>
+      </swiper>
+    </div>
+  </div>
+</template>
+
+<script setup name="TrainIndex" lang="ts">
+import { initSpeech, speckText, playMusic, controlMusic, speckCancel, chineseNumber } from '@/utils/speech';
+import { Swiper, SwiperSlide } from 'swiper/vue';
+import { Grid } from 'swiper/modules';
+import 'swiper/css';
+import 'swiper/css/grid';
+
+const router = useRouter();
+const { proxy } = getCurrentInstance() as any;
+
+const data = reactive<any>({
+  projectList: [],
+});
+const { projectList } = toRefs(data);
+
+
+//跳转
+const getJump = (data: any) => {
+  router.push({
+    path: `/game/${data.key}`, query: {
+      project: 'jumprope',
+      time: 60,
+      area: 11,
+      gesture: 'true',
+      classes: '1'
+    }
+  });
+};
+
+/**
+ * 退出
+ */
+const getExit = () => {
+  // router.go(-1);
+  router.push({ path: '/home' });
+};
+
+onBeforeMount(async () => {
+
+});
+
+onMounted(() => {
+  //停止播报;
+  speckCancel();
+  projectList.value = [{ name: "方块跳一跳", key: "square" }]
+});
+
+onBeforeUnmount(() => {
+
+});
+</script>
+
+<style lang="scss" scoped>
+$topPadding: 5.19rem;
+$waiPadding: 6.51rem;
+
+.menu {
+  width: calc(100% - ($waiPadding * 2));
+  height: 72vh;
+  padding-top: 10rem;
+  margin: 0 auto;
+  display: flex;
+
+  .li {
+    // width: calc((100% / 6) - 1rem + (1rem/6));
+    // margin-right: 1rem;
+    // margin-bottom: 1rem;
+    width: 100%;
+    height: calc((72vh / 2) - 20px);
+    padding: 2.2vh 0;
+    border-radius: 1.6rem;
+    box-sizing: border-box;
+    box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.9046), inset 0px 3px 6px 0px rgba(0, 0, 0, 0.0851);
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    cursor: pointer;
+
+    .pic {
+      width: 11.36vw;
+      height: 11.36vw;
+      border-radius: 50%;
+      background: radial-gradient(78% 78% at 53% 50%, #07121a 0%, #2a4256 49%, #5180a9 100%);
+      box-shadow: 0px 0px 2px 2px #ffffff;
+      margin-bottom: 2.5vh;
+      overflow: hidden;
+      display: flex;
+      align-items: center;
+      justify-content: center;
+      flex-shrink: 0;
+
+      img {
+        max-width: 88%;
+        max-height: 88%;
+        transition: all 1s;
+      }
+    }
+
+    .name {
+      width: 100%;
+      font-size: 2.48rem;
+      color: #1a293a;
+      text-align: center;
+    }
+
+    &:hover {
+      img {
+        transform: translateY(-0.5vw);
+      }
+    }
+  }
+
+  .swiper-slide {
+    border-radius: 1.6rem;
+    overflow: hidden;
+  }
+}
+
+.menu1 {
+  align-items: center;
+
+  .swiper-slide {
+    margin-bottom: 20px;
+
+    .li {
+      background: radial-gradient(96% 96% at 2% 32%, #ffffff 0%, #fcfdfd 54%, #e1e4e7 100%);
+    }
+
+    &:nth-child(2),
+    &:nth-child(4),
+    &:nth-child(6),
+    &:nth-child(7),
+    &:nth-child(9),
+    &:nth-child(11) {
+      .li {
+        background: radial-gradient(167% 126% at 97% 6%, #35ffc6 0%, #00ffe8 100%);
+      }
+    }
+  }
+}
+
+.menu2 {
+  display: flex;
+
+  .swiper-slide {
+
+    &:nth-child(1),
+    &:nth-child(4),
+    &:nth-child(5),
+    &:nth-child(8),
+    &:nth-child(9),
+    &:nth-child(12),
+    &:nth-child(13),
+    &:nth-child(16),
+    &:nth-child(17),
+    &:nth-child(20),
+    &:nth-child(21),
+    &:nth-child(24),
+    &:nth-child(25),
+    &:nth-child(28),
+    &:nth-child(29),
+    &:nth-child(32),
+    &:nth-child(33),
+    &:nth-child(36),
+    &:nth-child(37),
+    &:nth-child(40),
+    &:nth-child(41),
+    &:nth-child(44) {
+      .li {
+        background: radial-gradient(96% 96% at 2% 32%, #ffffff 0%, #fcfdfd 54%, #e1e4e7 100%);
+      }
+    }
+
+    &:nth-child(2),
+    &:nth-child(3),
+    &:nth-child(6),
+    &:nth-child(7),
+    &:nth-child(10),
+    &:nth-child(11),
+    &:nth-child(14),
+    &:nth-child(15),
+    &:nth-child(18),
+    &:nth-child(19),
+    &:nth-child(22),
+    &:nth-child(23),
+    &:nth-child(26),
+    &:nth-child(27),
+    &:nth-child(30),
+    &:nth-child(31),
+    &:nth-child(34),
+    &:nth-child(35),
+    &:nth-child(38),
+    &:nth-child(39),
+    &:nth-child(42),
+    &:nth-child(43) {
+      .li {
+        background: radial-gradient(167% 126% at 97% 6%, #35ffc6 0%, #00ffe8 100%);
+      }
+    }
+  }
+}
+
+::v-deep(.menu) {
+  .swiper-horizontal {
+    width: 100%;
+  }
+}
+
+@media screen and (max-width: 1450px) {
+  .menu {
+    .li {
+      .name {
+        font-size: 1.8rem;
+      }
+
+      .pic {
+        width: 10vw;
+        height: 10vw;
+      }
+    }
+  }
+}
+</style>

+ 28 - 30
src/views/train/game.vue → src/views/game/square.vue

@@ -1,5 +1,6 @@
 <template>
   <div class="test">
+    <SquareGame></SquareGame>
     <Header @confirmExit="confirmExit" @setMusic="setMusic"></Header>
     <div class="main">
       <div class="main-left">
@@ -18,8 +19,10 @@
             </div>
           </div>
           <div class="top-right">
-            <Transition :enter-active-class="proxy?.animate.dialog.enter" :leave-active-class="proxy?.animate.dialog.leave">
-              <div class="time" v-show="needStart && [42].includes(examState) && !['basketballv1', 'footballv1'].includes(parameter.project)">
+            <Transition :enter-active-class="proxy?.animate.dialog.enter"
+              :leave-active-class="proxy?.animate.dialog.leave">
+              <div class="time"
+                v-show="needStart && [42].includes(examState) && !['basketballv1', 'footballv1'].includes(parameter.project)">
                 {{
                   time.countdownNum
                 }}
@@ -29,15 +32,15 @@
               <img v-if="parameter.gesture" src="@/assets/images/test/ready1.png" />
               <img v-if="!parameter.gesture" src="@/assets/images/test/ready2.png" />
             </div>
-            <div
-              class="complete"
-              :class="{ 'complete2': needStart && [42].includes(examState) }"
-              v-if="faceCheckStu.student_id && time.ready <= 0 && examState != 43 && examState != 41"
-            >
+            <div class="complete" :class="{ 'complete2': needStart && [42].includes(examState) }"
+              v-if="faceCheckStu.student_id && time.ready <= 0 && examState != 43 && examState != 41">
               <div class="scoreBox">
-                <div class="score" v-if="currentResultObj?.count && currentResultObj.count>=0">{{ currentResultObj.count }}</div>
-                <div class="prompt" v-if="currentResultObj?.count && currentResultObj.count==0 && examState == 42">请开始测试</div>
-                <div class="unit" v-if="!['basketballv1', 'footballv1'].includes(parameter.project) && currentResultObj.count && !needStart">
+                <div class="score" v-if="currentResultObj?.count && currentResultObj.count >= 0">{{ currentResultObj.count
+                  }}</div>
+                <div class="prompt" v-if="currentResultObj?.count && currentResultObj.count == 0 && examState == 42">请开始测试
+                </div>
+                <div class="unit"
+                  v-if="!['basketballv1', 'footballv1'].includes(parameter.project) && currentResultObj.count && !needStart">
                   {{ unit }}
                 </div>
               </div>
@@ -56,7 +59,8 @@
               </div>
             </div>
             <div class="foulBox" v-if="examState == 42 && backReason.length">
-              <Transition :enter-active-class="proxy?.animate.mask.enter" :leave-active-class="proxy?.animate.mask.leave">
+              <Transition :enter-active-class="proxy?.animate.mask.enter"
+                :leave-active-class="proxy?.animate.mask.leave">
                 <div class="foul" v-show="backReasonStr ? true : false">
                   <div class="lable">!</div>
                   <div class="value">{{ backReasonStr }}</div>
@@ -90,7 +94,8 @@
             <div v-show="examState == 43 && !faceCheckStu.student_id">
               <div class="btn btn2" @click="getChooseStudent">点击重新识别</div>
             </div>
-            <div class="btn" @click="getReady" v-if="needStart && examState == 43 && faceCheckStu.student_id && !time.ready && readyState">开 始</div>
+            <div class="btn" @click="getReady"
+              v-if="needStart && examState == 43 && faceCheckStu.student_id && !time.ready && readyState">开 始</div>
             <!-- <div v-if="needStart"> -->
             <!-- <div class="btn" @click="getOpenOneTestAndStartFace" v-if="examState < 41">开始识别</div> -->
             <!-- <div class="btn" @click="getStopFace" v-if="examState == 41 && !parameter.gesture">停止人脸识别</div> -->
@@ -116,7 +121,8 @@
     </div>
     <FaceWindow ref="faceWindowRef" :faceCheckStu="faceCheckStu" :gesture="parameter.gesture" />
     <ChooseStudent ref="chooseStudentRef" @returnData="returnStudent" />
-    <JumpRopeGame ref="gameContainer" v-if="['test'].includes(parameter.project) && (!readyState || [42].includes(examState))" />
+    <JumpRopeGame ref="gameContainer"
+      v-if="['test'].includes(parameter.project) && (!readyState || [42].includes(examState))" />
     <div class="close" @click="confirmExit"></div>
   </div>
 </template>
@@ -378,7 +384,7 @@ const getRetestFace = () => {
         }
       }
     })
-    .finally(() => {});
+    .finally(() => { });
 };
 
 /**
@@ -454,7 +460,7 @@ const confirmExit = () => {
     .then(() => {
       getExit();
     })
-    .finally(() => {});
+    .finally(() => { });
 };
 
 /**
@@ -465,16 +471,7 @@ const getExit = () => {
   examEnds(); //通知工作站关闭
   speckCancel(); //停止播报
   window.onbeforeunload = null; //移除事件处理器
-  let handcontroller_id = parameter.value.handcontroller;
-  if (handcontroller_id) {
-    router.push({ path: '/gesture' });
-  } else {
-    if (parameter.value.taskId) {
-      router.push({ path: '/test' });
-    } else {
-      router.push({ path: '/train' });
-    }
-  }
+  router.push({ path: '/game' });
 };
 
 /**
@@ -712,9 +709,9 @@ const getAchievement = (data: any) => {
     if (['basketballv1', 'footballv1'].includes(type)) {
       speckText(
         faceCheckStu?.value.name +
-          '成绩为' +
-          (chineseNumber(proxy?.$utils.runTime(data?.[dic.typeResultKey[type]], false, 0, 1)) || 0) +
-          ',请下一位准备!' || ''
+        '成绩为' +
+        (chineseNumber(proxy?.$utils.runTime(data?.[dic.typeResultKey[type]], false, 0, 1)) || 0) +
+        ',请下一位准备!' || ''
       );
     } else {
       speckText(faceCheckStu?.value.name + '成绩为' + (chineseNumber(count) || 0) + unit.value + ',请下一位准备!' || '');
@@ -772,7 +769,7 @@ const getMusic = async () => {
 /**
  * 设置音乐
  */
-const setMusic = async (data:any) => {
+const setMusic = async (data: any) => {
   //console.log("data",data)
   parameter.value.music = data;
 };
@@ -786,7 +783,7 @@ const getDevice = async () => {
     startDevice({ deviceid: deviceid });
   } else {
     proxy?.$modal.msgError(`缺少设备信息请重新登录!`);
-    await proxy?.$http.common.logout({}).then((res: any) => {});
+    await proxy?.$http.common.logout({}).then((res: any) => { });
     proxy?.$modal?.closeLoading();
     //清空缓存
     // localStorage.clear();
@@ -1560,6 +1557,7 @@ $waiPadding: 6.51rem;
     overflow: hidden;
   }
 }
+
 .close {
   position: absolute;
   // right: calc($waiPadding - 3.2rem);

+ 9 - 9
src/views/home/index.vue

@@ -1,6 +1,5 @@
 <template>
   <div class="home">
-    <!-- <SquareGame></SquareGame> -->
     <Header :showClose="false" :showTool="true" logoClass="logo2"></Header>
     <div class="menu">
       <div class="left">
@@ -91,14 +90,15 @@ const getJump = (url: string, name: string) => {
       })
       .finally(() => { });
   } else if (url == '/game') {
-    proxy?.$modal.msgWarning('暂不开放使用,敬请期待!');
-    // router.push({ path: url,query: {
-    //   project:'jumprope',
-    //   time:60,
-    //   area:1,
-    //   gesture:'true',
-    //   classes:'1'
-    // } });
+    // proxy?.$modal.msgWarning('暂不开放使用,敬请期待!');
+    proxy?.$modal
+      .prompt('请输入密码')
+      .then((e: any) => {
+        if (e.action == 'confirm' && e.value == 'trops') {
+          router.push({ path: url });
+        }
+      })
+      .finally(() => { });
   }
   else {
     router.push({ path: url });