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>
<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>
<tr v-for="(line, lineId) in table" :key="lineId">
<td v-for="(item, itemId) in line" :key="itemId">
......@@ -20,6 +25,7 @@ import OXCell from './OXCell.vue'
export default {
data () {
return {
count: 0,
finish: false,
winner: '-',
turn: 'O',
......@@ -31,16 +37,22 @@ export default {
}
},
methods: {
newGame () {},
cellClick (row, col) {
if (this.finish) return
console.log('Cell click ' + row + ' ' + col)
this.table[row][col] = this.turn
this.count++
if (this.checkwin(row, col)) {
console.log('Win')
this.finish = true
this.winner = this.turn
return
}
if (this.count === 9) {
this.finish = true
return
}
this.switchTurn()
},
switchTurn () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment