-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
draft submission for TicTacToe #21
base: sat/master
Are you sure you want to change the base?
Changes from all commits
d61b8c6
17c926a
2e4bbae
b70af40
d373a19
b2decb7
9f6840d
930abf9
e1fd889
183e14b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
html { | ||
|
||
font-size: 16px; | ||
color: white; | ||
} | ||
|
||
body { | ||
background-color: black; | ||
} | ||
|
||
.slot { | ||
background-color: gray; | ||
width: 75px; | ||
height: 75px; | ||
margin: 5px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,83 @@ | ||
function TicTacToe() { | ||
$(document).on('ready', function() { | ||
var game = new TicTacToe(); | ||
|
||
} | ||
// click handler - keep it separate | ||
// we could have saved the button clicking function to a variable and then passed that variable to click | ||
$(":button").click( function(){ | ||
if (game.turns % 2 === 0) { | ||
$(this).css('background-color', 'red'); | ||
} else { | ||
$(this).css('background-color', 'green'); | ||
} | ||
// this gives me the class that the person has clicked on and is storing the value so I can use it elsewhere | ||
var position = $(this).attr("class").split(" ")[1]; | ||
game.play(position, game.marker()); | ||
}); | ||
}); | ||
|
||
TicTacToe.prototype = { | ||
|
||
} | ||
// creates a class that initializes constructor for tictactoe class | ||
// create a function for each of these functions? | ||
function TicTacToe() { | ||
this.board = []; | ||
this.player = "player1"; | ||
this.turns = 0; | ||
} | ||
|
||
TicTacToe.prototype.play = function(position, marker) { | ||
this.turn(); | ||
this.board[position] = marker; | ||
this.won(); | ||
}; | ||
|
||
TicTacToe.prototype.turn = function(){ | ||
this.turns++; | ||
if (this.turns % 2 === 0) { | ||
this.player = "player1"; | ||
} else { | ||
this.player = "player2"; | ||
} | ||
}; | ||
|
||
TicTacToe.prototype.marker = function(player){ | ||
if (this.player === "player1") { | ||
return 'x'; | ||
} else { | ||
return 'o'; | ||
} | ||
}; | ||
|
||
TicTacToe.prototype.getPlayerName = function(){ | ||
if (this.turn % 2 === 0 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like you should be able to use the |
||
return "player 1"; | ||
} else { | ||
return "player 2"; | ||
} | ||
}; | ||
|
||
// create function for winMessage | ||
|
||
TicTacToe.prototype.won = function(){ | ||
// could also pair this down by creating a row 1 variable | ||
if (this.board.slice(0,2) === ['x','x','x'] || this.board.slice(0,2) === ['o','o','o']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you test out the |
||
console.log("You win!"); | ||
var div = $('<div class = "won_message"></div>'); | ||
var winMessage = $('<p></p>'); | ||
winMessage.text(this.getPlayerName() + "won!"); | ||
div.append(winMessage); | ||
$('body').append('div'); | ||
debugger; | ||
// return true; | ||
} else if (this.board.slice(3,5) === ['x','x','x'] || this.board.slice(3,5) === ['o','o','o']) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment re: the slice params, here and on line 73 |
||
console.log("You win!"); | ||
return true; | ||
} else if (this.board.slice(6,8) === ['x','x','x'] || this.board.slice(6,8) === ['o','o','o']) { | ||
console.log("You win!"); | ||
return true; | ||
} | ||
}; | ||
// if someone has taken 8 or 9 turns with no win, its a draw. | ||
|
||
|
||
// var won = function(board){ | ||
// // loop through and see if someone has won horizontally, vertically, diagonally | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch your indentation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you would want to switch the players at the end of a turn instead of at the beginning of the turn, right? Will this then end up with player 2 as the first player?