Skip to content

Commit

Permalink
Fix error when clicking on populate cell and changing player (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur322 authored and taniarascia committed Sep 4, 2019
1 parent eb8f8f8 commit 37e191b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
32 changes: 16 additions & 16 deletions dist/tictactoe.js
Expand Up @@ -90,22 +90,22 @@ var TicTacToe = (function () {
if (canContinue && !_this.waiting) {
_this.board[row][col] = _this.currentPlayer;
_this.display.updateBoard(row, col, _this.currentPlayer);
}
var win = _this.isGameWon(row, col);
var stalemate = _this.board
.map(function (row) { return row.filter(function (col) { return col === ''; }); })
.filter(function (row) { return row.length > 0; });
if (!_this.waiting) {
if (win) {
_this.increaseScore();
_this.display.updateScore(_this.score, _this.currentPlayer);
_this.gameOver(_this.currentPlayer);
}
else if (stalemate.length < 1) {
_this.gameOver();
}
else {
_this.switchPlayer();
var win = _this.isGameWon(row, col);
var stalemate = _this.board
.map(function (row) { return row.filter(function (col) { return col === ''; }); })
.filter(function (row) { return row.length > 0; });
if (!_this.waiting) {
if (win) {
_this.increaseScore();
_this.display.updateScore(_this.score, _this.currentPlayer);
_this.gameOver(_this.currentPlayer);
}
else if (stalemate.length < 1) {
_this.gameOver();
}
else {
_this.switchPlayer();
}
}
}
};
Expand Down
30 changes: 15 additions & 15 deletions src/tictactoe.ts
Expand Up @@ -226,22 +226,22 @@ class TicTacToe {
if (canContinue && !this.waiting) {
this.board[row][col] = this.currentPlayer
this.display.updateBoard(row, col, this.currentPlayer)
}

const win = this.isGameWon(row, col)
const stalemate = this.board
.map(row => row.filter(col => col === ''))
.filter(row => row.length > 0)

if (!this.waiting) {
if (win) {
this.increaseScore()
this.display.updateScore(this.score, this.currentPlayer)
this.gameOver(this.currentPlayer)
} else if (stalemate.length < 1) {
this.gameOver()
} else {
this.switchPlayer()
const win = this.isGameWon(row, col)
const stalemate = this.board
.map(row => row.filter(col => col === ''))
.filter(row => row.length > 0)

if (!this.waiting) {
if (win) {
this.increaseScore()
this.display.updateScore(this.score, this.currentPlayer)
this.gameOver(this.currentPlayer)
} else if (stalemate.length < 1) {
this.gameOver()
} else {
this.switchPlayer()
}
}
}
}
Expand Down

0 comments on commit 37e191b

Please sign in to comment.