Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
yrfbybhdbfdj
  • Loading branch information
met18001 committed Mar 2, 2020
1 parent e4c3c47 commit dce6c4f
Showing 1 changed file with 79 additions and 75 deletions.
154 changes: 79 additions & 75 deletions week-6/js/tic-tac-toe.js
@@ -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';
}
}

});

0 comments on commit dce6c4f

Please sign in to comment.