From bc9e7c144b0276d23147967fc01c13892b7b177b Mon Sep 17 00:00:00 2001 From: 62160286 <62160286@go.buu.ac.th> Date: Wed, 22 Dec 2021 23:17:19 +0700 Subject: [PATCH] Add method checkWin --- src/components/OXTable.vue | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/components/OXTable.vue b/src/components/OXTable.vue index 194fd1d..e2ec8ca 100644 --- a/src/components/OXTable.vue +++ b/src/components/OXTable.vue @@ -22,6 +22,8 @@ import OXCell from './OXCell.vue' export default { data () { return { + finish: false, + winner: '-', turn: 'O', table: [ ['-', '-', '-'], @@ -34,6 +36,12 @@ export default { cellClick (row, col) { console.log('Cell click ' + row + ' ' + col) this.table[row][col] = this.turn + if (this.checkwin(row, col)) { + console.log('Win') + this.finish = true + this.winner = this.turn + return + } this.switchTurn() }, switchTurn () { @@ -49,6 +57,28 @@ export default { } else { this.turn = 'X' } + }, + checkwin (row, col) { + if ( + this.checkRow(row) || + this.checkCol(col) || + this.checkX1() || + this.checkX2() + ) { + return this.turn + } + }, + checkRow (row) { + return false + }, + checkCol (col) { + return false + }, + checkX1 () { + return false + }, + checkX2 () { + return false } }, components: { -- GitLab