亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

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

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

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

vue實現(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; } }})

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

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 日韩最新视频一区二区三 | 日韩网站在线 | 亚洲色图偷拍 | 欧洲女人性开放视频在线观看 | 日韩欧美综合在线 | 成人av手机在线观看 | 国产精品自拍在线观看 | 91亚洲一区二区在线观看不卡 | 日韩欧美亚洲国产高清在线 | 久久最新精品 | 久久麻豆亚洲精品 | 麻豆传媒最新网址 | 久久精品全国免费观看国产 | 久久一区二区三区免费 | 中国xxxxx高清免费看视频 | 青青草国产97免久久费观看 | 免费观看拍拍视频在线观看 | 国产11一12周岁女毛片 | 麻豆视频免费在线观看 | 久久99毛片免费观看不卡 | 国产伦码精品一区二区三区 | 日韩精品久久久免费观看夜色 | 鲁大师视频在线www观看 | 玖玖国产精品视频 | 免费看午夜高清性色生活片 | 欧美精品一区二区三区四区 | 小草免费在线视频 | 欧美超高清xoxoxoxo | 在线免费观看网址 | 国产成人啪午夜精品网站男同 | 一级的黄色片 | 久久777国产线看是看精品 | 国产精品乱码免费一区二区 | 欧美成人xxxxxxxx在线 | 热er99久久6国产精品免费 | 日韩欧美在线综合 | 日本在观线免费观看 | 高清视频 一区二区三区四区 | 三毛片 | 在线播放黄 | 免费特黄|