色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

vue實(shí)現(xiàn)井字棋游戲

瀏覽:85日期:2022-11-17 16:32:45

本文實(shí)例為大家分享了vue實(shí)現(xiàn)井字棋游戲的具體代碼,供大家參考,具體內(nèi)容如下

之前看react的教程時(shí)看到的小游戲,試著用vue做一個(gè)。右邊的winner提示勝者,還沒(méi)有勝者時(shí)提示下一個(gè)棋子的種類(lèi)。restart按鈕點(diǎn)擊可重新開(kāi)始。go to step可跳轉(zhuǎn)到第n步。

vue實(shí)現(xiàn)井字棋游戲

html:

<div id='app'> <ul class='white normal'> <li v-for='i, idx in datas' @click=set(idx)>{{i}}</li> </ul> <div id='console'> <div class='white'>{{hint}}</div> <input type='button' value='restart' @click='init()'/> <ul class='normal'> <li v-for='i, idx in history'> <input type='button' :value='’go to step’ + (idx + 1)' @click=jump(idx) /> </li> </ul> </div></div>

css:

<style type='text/css'> body { background: #5af; } .white { background: #fff; border-radius: 11px; outline: none; border: none; } .normal { list-style: none; padding: 0px; margin: 0px; } #app { display: flex; justify-content: space-between; width: 450px; height: 306px; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; } #board { display: flex; width: 306px; height: 306px; flex-wrap: wrap; overflow: hidden; } #hint { width: 100px; height: 22px; text-align: center; margin: 10px; } #restart { width: 70px; height: 22px; margin: 10px; } #history, .history { margin: 5px; } .square { height: 100px; width: 100px; border: #ebebeb solid 1px; flex: 0 0 auto; font-size: 50px; font-weight: 900; line-height: 100px; text-align: center; }</style>

js:

new Vue({ el: ’#app’, data: { datas: Array(9).fill(’’), history: [], next: true, winner: ’’, cases: [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6], ] }, methods: { //放置棋子 set(idx) { if (!this.datas[idx] && !this.winner) { this.$set(this.datas, idx, this.next_player); this.history.push({ status: [...this.datas], player: this.next }); if (this.is_win(this.next_player)) { this.winner = this.next_player; } this.next = !this.next; } }, //跳轉(zhuǎn)到第n步 jump(idx) { this.datas = this.history[idx].status; this.history.splice(idx + 1, this.history.length - idx - 1); this.next = !this.history[idx].player; this.winner = this.is_win(’O’) ? ’O’ : this.is_win(’X’) ? ’X’ : ’’; }, //判斷是否勝出 is_win(player) { return this.cases.some(arr => arr.every(el => this.datas[el] === player)); }, //初始化 init() { this.datas = Array(9).fill(’’); this.history = []; this.next = true; this.winner = ’’; } }, computed: { next_player() { return this.next ? ’O’ : ’X’; }, hint() { return this.winner ? ’winner: ’ + this.winner : ’next: ’ + this.next_player; } }})

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 亚洲影院在线播放 | 久久久精品久久视频只有精品 | 国产在视频线精品视频二代 | 成人不卡视频 | 国产精品yjizz视频网一二区 | 国产女人在线观看 | 久久福利青草免费精品 | 波多野结衣中文一区二区免费 | 中文字幕一区二区三区精品 | 国产欧美成人一区二区三区 | 国产成人精品永久免费视频 | 一级特黄性色生活片一区二区 | 九九九九在线视频播放 | 人人草97 | 特级av毛片免费观看 | 免费人成在线观看播放国产 | 长腿美女被啪的欲仙欲死视频 | 久久国产精品自线拍免费 | a级男女性高爱潮高清试 | 成人在线视频一区 | 久久久久久亚洲精品不卡 | 宅男69免费永久网站 | 亚洲精品久久一区影院 | 成年美女黄网站小视频 | 国产自精品在线 | 精品成人在线 | 免费视频观看在线www日本 | 亚洲午夜国产精品 | 抱着cao才爽免费观看 | 看一级毛片 | 久久精品中文字幕首页 | 99久久精品免费看国产一区二区三区 | 五月激激激综合网色播免费 | 久久视频国产 | 亚洲日本欧美综合在线一 | avtt亚洲一区中文字幕 | 国产精品成人观看视频国产 | 天天澡天天碰天天狠伊人五月 | 亚洲精品在线看 | 日韩一区二区三区在线视频 | 高清欧美日本视频免费观看 |