Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
yrfbybhdbfdj
- Loading branch information
Showing
1 changed file
with
79 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,99 @@ | ||
var app = new Vue({ | ||
el: '#vue-app', | ||
data: { | ||
turn: 'x', | ||
turn: 'X', | ||
board: [ | ||
[null, null, null], | ||
[null, null, null], | ||
[null, null, null] | ||
] | ||
}, | ||
methods: { | ||
changeIt: function(row,column){ | ||
|
||
this.board[row][column] = this.turn | ||
}, | ||
|
||
let winner = "Player" + this.turn + " you are a winner!"; | ||
methods: { | ||
changeIt: function(row, column){ | ||
|
||
this.board[row][column] = this.turn; | ||
|
||
if (this.board[0,0] == this.turn && this.board[0,1] == this.turn && this.board[0,2] == this.turn){ | ||
document.getElementById("1").style.backgroundcolor = "green"; | ||
document.getElementById("2").style.backgroundcolor = "green"; | ||
document.getElementById("3").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board[0,0] == this.turn && this.board[1,0] == this.turn && this.board[2,0] == this.turn){ | ||
document.getElementById("1").style.backgroundcolor = "green"; | ||
document.getElementById("4").style.backgroundcolor = "green"; | ||
document.getElementById("7").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
let winner = "Congratulations, Player " + this.turn + ", YOU WIN!" | ||
|
||
}else if (this.board[1,0] == this.turn && this.board[1,1] == this.turn && this.board[1,2] == this.turn) { | ||
document.getElementById("4").style.backgroundcolor = "green"; | ||
document.getElementById("5").style.backgroundcolor = "green"; | ||
document.getElementById("6").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
// add logic to check if someone one after each turn but before it says 'your turn _" | ||
if (this.board [0][0] == this.turn && this.board [0][1] && this.board[0][2] == this.turn){ | ||
document.getElementById("1").style.backgroundcolor = "blue"; | ||
document.getElementById("2").style.backgroundcolor = "blue"; | ||
document.getElementById("3").style.backgroundcolor = "blue"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board [0][0] == this.turn && this.board [1][0]== this.turn && this.board [2][0] == this.turn){ | ||
document.getElementById("1").style.backgroundcolor = "blue"; | ||
document.getElementById("4").style.backgroundcolor = "blue"; | ||
document.getElementById("7").style.backgroundcolor = "blue"; | ||
window.location.reload(); | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board[2,0] == this.turn && this.board[2,1] == this.turn && this.board[2,2] == this.turn) { | ||
document.getElementById("7").style.backgroundcolor = "green"; | ||
document.getElementById("8").style.backgroundcolor = "green"; | ||
document.getElementById("9").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
}else if (this.board [1][0] == this.turn && this.board [1][1] == this.turn && this.board [1][2] == this.turn){ | ||
document.getElementById("4").style.backgroundcolor = "blue"; | ||
document.getElementById("5").style.backgroundcolor = "blue"; | ||
document.getElementById("6").style.backgroundcolor = "blue"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board[0,1] == this.turn && this.board[1,1] == this.turn && this.board[2,1] == this.turn) { | ||
document.getElementById("2").style.backgroundcolor = "green"; | ||
document.getElementById("5").style.backgroundcolor = "green"; | ||
document.getElementById("8").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
}else if (this.board [2][0] == this.turn && this.board [2][1] == this.turn && this.board [2][2] == this.turn){ | ||
document.getElementById("7").style.backgroundcolor = "blue"; | ||
document.getElementById("8").style.backgroundcolor = "blue"; | ||
document.getElementById("9").style.backgroundcolor = "blue"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board[0,2] == this.turn && this.board[1,2] == this.turn && this.board[2,2] == this.turn) { | ||
document.getElementById("3").style.backgroundcolor = "green"; | ||
document.getElementById("6").style.backgroundcolor = "green"; | ||
document.getElementById("9").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
}else if (this.board [0][1] == this.turn && this.board [1][1] == this.turn && this.board [2][1] == this.turn){ | ||
document.getElementById("2").style.backgroundcolor = "blue"; | ||
document.getElementById("5").style.backgroundcolor = "blue"; | ||
document.getElementById("8").style.backgroundcolor = "blue"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board[0,0] == this.turn && this.board[1,1] == this.turn && this.board[2,2] == this.turn) { | ||
document.getElementById("1").style.backgroundcolor = "green"; | ||
document.getElementById("5").style.backgroundcolor = "green"; | ||
document.getElementById("9").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
}else if (this.board [0][2] == this.turn && this.board [1][2] == this.turn && this.board [2][2] == this.turn){ | ||
document.getElementById("3").style.backgroundcolor = "blue"; | ||
document.getElementById("6").style.backgroundcolor = "blue"; | ||
document.getElementById("9").style.backgroundcolor = "blue"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board [0][0] == this.turn && this.board [1][1] == this.turn && this.board [2][2] == this.turn){ | ||
document.getElementById("1").style.backgroundcolor = "blue"; | ||
document.getElementById("5").style.backgroundcolor = "blue"; | ||
document.getElementById("9").style.backgroundcolor = "blue"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
|
||
}else if (this.board [2][0] == this.turn && this.board [1][1] == this.turn && this.board [0][2] == this.turn){ | ||
document.getElementById("3").style.backgroundcolor = "blue"; | ||
document.getElementById("5").style.backgroundcolor = "blue"; | ||
document.getElementById("7").style.backgroundcolor = "blue"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
} | ||
|
||
this.turn = (this.turn == "X")? 'O' : 'X'; | ||
|
||
}else if (this.board [2,0] == this.turn && this.board [1,1] == this.turn && this.board [0,2] == this.turn){ | ||
document.getElementById("3").style.backgroundcolor = "green"; | ||
document.getElementById("5").style.backgroundcolor = "green"; | ||
document.getElementById("6").style.backgroundcolor = "green"; | ||
alert(winner); | ||
setTimeout(function(){ | ||
if(!alert('Play Again?')){window.location.reload();} | ||
}, 0500); | ||
} | ||
|
||
this.turn = (this.turn == 'x') ? 'o' : 'x'; | ||
} | ||
} | ||
|
||
}); |