国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

vue實現井字棋游戲

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

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

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

vue實現井字棋游戲

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; } }, //跳轉到第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; } }})

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 亚洲bt欧美bt国产bt | 欧美亚洲在线 | 亚洲国产一区在线精选 | 91久久精品青青草原伊人 | 亚洲精品久久99久久 | 怡红院老首页主页入口 | 男女乱淫真视频免费观看 | 久久性生大片免费观看性 | 国产日韩欧美精品 | 亚洲精品一区二区三区四区 | a级毛片免费完整视频 | 久久www免费人成精品 | 国产成人久久综合二区 | 在线日本看片免费人成视久网 | 九九九国产视频 | 99视频在线精品免费观看18 | 黄色网址网站 | 欧美激情亚洲一区中文字幕 | 欧美激情欧美狂野欧美精品免费 | 办公室紧身裙丝袜av在线 | 色青青草原桃花久久综合 | 免费一区二区三区视频狠狠 | 亚洲精品大片 | 欧美理论片在线观看一区二区 | 一级aaa级毛片午夜在线播放 | 午夜精品视频在线观看美女 | 国产精品爱久久久久久久三级 | 久久99国产精品久久99无号码 | 最近中文字幕在线 | 中文 | 日韩一级免费视频 | 国产v片在线播放免费观 | 日韩国产欧美在线观看 | 免费人成在线观看播放国产 | 精品一区二区在线观看 | 国产激情一区二区三区四区 | 欧美成人免费全部观看天天性色 | 国产三区视频在线观看 | 韩国精品一区视频在线播放 | 久久国产视频一区 | 亚洲在线视频免费 | 在线 | 一区二区三区 |