Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 74b556f7 authored by 62160286's avatar 62160286
Browse files

Add button New Game

parent 90c51661
No related branches found
No related tags found
No related merge requests found
<template> <template>
<div> <div>
<div>{{ turn }} {{ finish }} {{ winner }}</div> <div v-if="finish">
<span v-if="winner !== '-'">{{ winner }} Win!!! </span>
<span v-else>Draw!!!</span>
<button @click="newGame">New Game</button>
</div>
<div v-else>{{ turn }} Turn..</div>
<table> <table>
<tr v-for="(line, lineId) in table" :key="lineId"> <tr v-for="(line, lineId) in table" :key="lineId">
<td v-for="(item, itemId) in line" :key="itemId"> <td v-for="(item, itemId) in line" :key="itemId">
...@@ -20,6 +25,7 @@ import OXCell from './OXCell.vue' ...@@ -20,6 +25,7 @@ import OXCell from './OXCell.vue'
export default { export default {
data () { data () {
return { return {
count: 0,
finish: false, finish: false,
winner: '-', winner: '-',
turn: 'O', turn: 'O',
...@@ -31,16 +37,22 @@ export default { ...@@ -31,16 +37,22 @@ export default {
} }
}, },
methods: { methods: {
newGame () {},
cellClick (row, col) { cellClick (row, col) {
if (this.finish) return if (this.finish) return
console.log('Cell click ' + row + ' ' + col) console.log('Cell click ' + row + ' ' + col)
this.table[row][col] = this.turn this.table[row][col] = this.turn
this.count++
if (this.checkwin(row, col)) { if (this.checkwin(row, col)) {
console.log('Win') console.log('Win')
this.finish = true this.finish = true
this.winner = this.turn this.winner = this.turn
return return
} }
if (this.count === 9) {
this.finish = true
return
}
this.switchTurn() this.switchTurn()
}, },
switchTurn () { switchTurn () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment