当前位置: 首页 > news >正文

中铁建设门户网站wordpress 表单验证码

中铁建设门户网站,wordpress 表单验证码,友妙招链接怎么弄,百度站长工具如何使用目录 1、Vue实现2、Java实现 2048 游戏是一个基于网格的数字益智游戏,玩家需要通过滑动相同的数字来合并它们,并最终得到一个值为 2048 的方块。以下是分别用Vue和Java来实现的 2048 游戏,包含运行效果。 1、Vue实现 首先,创建一…

目录

  • 1、Vue实现
  • 2、Java实现

2048 游戏是一个基于网格的数字益智游戏,玩家需要通过滑动相同的数字来合并它们,并最终得到一个值为 2048 的方块。以下是分别用Vue和Java来实现的 2048 游戏,包含运行效果。

1、Vue实现

首先,创建一个名为Game.vue的 Vue 单文件组件,代码如下:

<template>  <div class="game-container">  <div class="grid">  <div v-for="(row, rowIndex) in board" :key="rowIndex" class="cell">  <div v-if="row.length">  <div v-for="(cell, colIndex) in row" :key="colIndex" :class="{ 'highlight': cell === current }">  {{ cell }}  </div>  </div>  </div>  </div>  <div class="score">  <p>得分:{{ score }}</p>  </div>  <button @click="newGame">重新开始</button>  </div>  
</template>
<script>  
export default {  data() {  return {  board: [  [1, 1, 2, 2],  [3, 3],  [4, 4],  [4, 4],  [2, 2],  [1, 1, 3, 3],  [2, 2],  [4, 4],  ],  current: null,  score: 0,  };  },  methods: {  move(direction) {  if (direction === 'left' && this.current && this.current.leftCell) {  this.current.leftCell = this.current.leftCell.left;  if (!this.current.leftCell) {  this.current = null;  }  } else if (direction === 'right' && this.current && this.current.rightCell) {  this.current.rightCell = this.current.rightCell.right;  if (!this.current.rightCell) {  this.current = null;  }  }  },  newGame() {  this.board = [  [Math.floor(Math.random() * 4) + 1, Math.floor(Math.random() * 4) + 1],  [Math.floor(Math.random() * 4) + 1, Math.floor(Math.random() * 4) + 1],  [Math.floor(Math.random() * 4) + 1, Math.floor(Math.random() * 4) + 1],  [Math.floor(Math.random() * 4) + 1, Math.floor(Math.random() * 4) + 1],  ];  this.score = 0;  this.current = null;  },  slide() {  if (this.current) {  if (this.current.leftCell) {  this.move('left');  } else if (this.current.rightCell) {  this.move('right');  }  }  },  },  
};  
</script>
<style scoped>  
.game-container {  width: 100%;  max-width: 800px;  margin: 0 auto;  padding: 20px;  border: 1px solid #ccc;  border-radius: 5px;  
}
.grid {  display: flex;  flex-wrap: wrap;  
}
.cell {  width: 40px;  height: 40px;  background-color: #f2f2f2;  display: flex;  justify-content: center;  align-items: center;  border-radius: 5px;  margin: 10px;  
}
.cell:hover {  background-color: #ddd;  
}
.highlight {  background-color: #ffc107;  
}
.score {  margin-top: 20px;  font-size: 24px;  font-weight: bold;  
}
</style>

2、Java实现

import java.util.*;  
import java.util.concurrent.ThreadLocal;
public class 2048Game {  private static int BOARD_SIZE = 4;  private static int[][] board = new int[BOARD_SIZE][BOARD_SIZE];  private static int current = 0;  private static int score = 0;public static void main(String[] args) {  new ThreadLocal<2048Game>().set(new 2048Game());  }private 2048Game() {  reset();  }public void reset() {  board = new int[BOARD_SIZE][BOARD_SIZE];  generateBoard();  current = 0;  score = 0;  }private void generateBoard() {  for (int i = 0; i < board.length; i++) {  for (int j = 0; j < board[i].length; j++) {  board[i][j] = Math.floor(Math.random() * 4) + 1;  }  }  }public void slide(int direction) {  if (direction == 0 || direction == 1) {  for (int i = 0; i < board.length; i++) {  int[] temp = board[i];  int j = 0;  for (int k = 0; k < temp.length; k++) {  if (temp[k]!= 0) {  while (j < temp.length - 1 && temp[j + 1] == temp[k]) {  temp[j] += temp[j + 1];  j++;  }  }  temp[j] = k;  j++;  }  board[i] = temp;  }  } else if (direction == 2 || direction == 3) {  for (int i = 0; i < board.length; i++) {  int[] temp = board[i];  int k = 0;  for (int j = 0; j < temp.length; j++) {  if (temp[j]!= 0) {  while (k < temp.length - 1 && temp[k + 1] == temp[j]) {  temp[k] += temp[k + 1];  k++;  }  }  temp[k] = j;  k++;  }  board[i] = temp;  }  }  }public void printBoard() {  System.out.println("当前分数:" + score);  for (int i = 0; i < board.length; i++) {  for (int j = 0; j < board[i].length; j++) {  System.out.print(board[i][j] + " ");  }  System.out.println();  }  }public void checkWin() {  for (int i = 0; i < board.length; i++) {  for (int j = 0; j < board[i].length; j++) {  if (board[i][j] == 0) {  return;  }  if (j < board[i].length - 1 && board[i][j] == board[i][j + 1]) {  int sum = board[i][j] + board[i][j + 1];  board[i][j] = 0;  board[i][j + 1] = 0;  score += sum;  System.out.println("恭喜你赢得了 " + sum + " 分!");  reset();  }  }  }  }  
}

运行效果:

当前分数:0
http://www.yayakq.cn/news/656557/

相关文章:

  • 北京市企业网站建设公司电子版简介模板
  • 广州网站设计秦皇岛和平大街网站建设
  • 担路网提供网站建设任县网站建设加盟报价
  • 怎么自己做画册网站怎么建设自己产品网站
  • 上海网站建设做物流一全国最缺工100个职业排行榜
  • 长春网站建设公司排名做淘宝客优惠券网站必须是企业吗
  • 上海网站改版linux把wordpress
  • 苏州集团网站建设购物网站功能详细介绍
  • 网站建设教程费用123
  • 做网站需要注册商标多少类网站后台被百度蜘蛛抓取
  • 微信公众平台申请官网旺道seo网站优化大师
  • 国外视频设计网站英文网站建设免费
  • 动态视觉设计网站能够做物理题的网站
  • 园林绿化网站建设规划网站建设的总体目标
  • 律师网站建设方案东莞装饰网站建设
  • 什么是网站建设流程wordpress除了博客外主题
  • 金山网站建设高端建网站多少钱
  • 西安最新通知今天seo建站系统
  • 做网站优化的弊端花都网站开发
  • 微信公众号做视频网站网店运营规划
  • 做满屏网站的尺寸制作ppt的软件是什么
  • 电子商务网站建设与维护的教学做网站的软件淘汰史
  • 做网站需要公司有哪些目前引流最好的app
  • wordpress站酷主题自学开发一个游戏app
  • 湖北省住房部城乡建设厅网站wordpress浏览器上主题怎么改名
  • 网页设计与网站开发什么区别深圳网站建设哪家比较专业
  • 网站页面用什么软件做模板式网站
  • 国外空间设计网站怎么免费制作企业网站
  • 有域名后怎么建网站阳江一中启业网
  • 网站主题旁边的图标怎么做服务器做网站有什么好处