-
Notifications
You must be signed in to change notification settings - Fork 20
Tic-Tac-G.O.B. #3
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
base: jmn/master
Are you sure you want to change the base?
Changes from all commits
4f88bf0
e51a760
dcf8dbb
0d5e254
f300958
df02e92
2ae5482
2acf1f7
4dc6df9
be7363a
3f339fb
0b0ef33
21d4aab
6ed355b
ab84c5a
d827a19
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,71 @@ | ||
| @font-face { | ||
| font-family: antiqueOlive; | ||
| src: url("AntiqueOlive.ttf"); | ||
| } | ||
|
|
||
| html { | ||
|
|
||
|
|
||
| } | ||
|
|
||
| body { | ||
| background-color: #F98F1B; | ||
| text-align: center; | ||
| } | ||
|
|
||
| h1 { | ||
| font-family: 'antiqueOlive', cursive; | ||
| letter-spacing: -3px; | ||
| text-align: center; | ||
| color: black; | ||
| font-size: 48px; | ||
| margin-bottom: 10px; | ||
| } | ||
|
|
||
| button { | ||
| margin-bottom: 10px; | ||
| font-size: 18px; | ||
| } | ||
|
|
||
| .arrested-development { | ||
| font-family: 'antiqueOlive', cursive; | ||
| } | ||
|
|
||
| h2 { | ||
| font-family: 'antiqueOlive', cursive; | ||
| text-align: center; | ||
| color: black; | ||
| font-size: 36px; | ||
| letter-spacing: -3px; | ||
| } | ||
|
|
||
| div.row { | ||
| text-align: center; | ||
| } | ||
|
|
||
| div.square { | ||
| border: 5px solid black; | ||
| background-color: white; | ||
| height: 150px; | ||
| width: 150px; | ||
| margin: 5px; | ||
| display: inline-block; | ||
| position: relative; | ||
| } | ||
|
|
||
| img { | ||
| position: absolute; | ||
| left: 0px; | ||
| top: 50%; | ||
| transform: translateY(-50%); | ||
| width: 100%; | ||
| height: auto; | ||
| } | ||
|
|
||
| .banana { | ||
| opacity: 0.3; | ||
| left: 25px; | ||
| margin-left: auto; | ||
| margin-right: auto; | ||
| height: 75%; | ||
| width: auto; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,178 @@ | ||
| function TicTacToe() { | ||
| var possiblePlayersOne = [ | ||
| { | ||
| name: "Ann", | ||
| pictureURL: "images/ann.png" | ||
| }, | ||
| { | ||
| name: "Lucille", | ||
| pictureURL: "images/lucille.png" | ||
| }, | ||
| { | ||
| name: "G.O.B.", | ||
| pictureURL: "images/gob.jpg" | ||
| }, | ||
| { | ||
| name: "Buster", | ||
| pictureURL: "images/buster.jpg" | ||
| }, | ||
| { | ||
| name: "Tobias", | ||
| pictureURL: "images/tobias.jpg" | ||
| }, | ||
| ]; | ||
|
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. 🙌🏾Thank you for the whitespace. |
||
|
|
||
| } | ||
| var possiblePlayersTwo = [ | ||
| { | ||
| name: "George Michael", | ||
| pictureURL: "images/georgemichael.png" | ||
| }, | ||
| { | ||
| name: "George Sr.", | ||
| pictureURL: "images/georgesr.jpg" | ||
| }, | ||
| { | ||
| name: "Lindsay", | ||
| pictureURL: "images/lindsay.jpg" | ||
| }, | ||
| { | ||
| name: "Michael", | ||
| pictureURL: "images/michael.jpg" | ||
| }, | ||
| { | ||
| name: "Maeby", | ||
| pictureURL: "images/maeby.png" | ||
| }, | ||
| ]; | ||
|
|
||
| TicTacToe.prototype = { | ||
|
|
||
| function TicTacToe() { | ||
| this.board = [[0,0,0], [0,0,0], [0,0,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. Seriously, I'm so happy right now. 💕 |
||
| this.playerOne = possiblePlayersOne[Math.floor(Math.random() * possiblePlayersOne.length)]; // random from group 1 | ||
| this.playerTwo = possiblePlayersTwo[Math.floor(Math.random() * possiblePlayersTwo.length)]; // random from group 2 | ||
| this.currentPlayer = this.playerOne; | ||
| this.turns = 0; | ||
| this.over = false; | ||
| } | ||
|
|
||
| TicTacToe.prototype.updateBoard = function(square) { | ||
| switch ($(square).attr('id')) { | ||
| case "top-left": | ||
| this.board[0][0] = this.currentPlayer; | ||
| break; | ||
| case "top-mid": | ||
| this.board[0][1] = this.currentPlayer; | ||
| break; | ||
| case "top-right": | ||
| this.board[0][2] = this.currentPlayer; | ||
| break; | ||
| case "mid-left": | ||
| this.board[1][0] = this.currentPlayer; | ||
| break; | ||
| case "mid-mid": | ||
| this.board[1][1] = this.currentPlayer; | ||
| break; | ||
| case "mid-right": | ||
| this.board[1][2] = this.currentPlayer; | ||
| break; | ||
| case "bottom-left": | ||
| this.board[2][0] = this.currentPlayer; | ||
| break; | ||
| case "bottom-mid": | ||
| this.board[2][1] = this.currentPlayer; | ||
| break; | ||
| case "bottom-right": | ||
| this.board[2][2] = this.currentPlayer; | ||
| break; | ||
| } | ||
| }; | ||
|
|
||
| TicTacToe.prototype.play = function() { | ||
| if (this.gameOver() === false) { | ||
| this.switchPlayer(); | ||
| } else if (this.gameOver() === true) { | ||
| this.over = true; | ||
| $("body").append("<h2>It's a draw... I guess you could say you're tie-curious...</h2>"); | ||
| } else if (this.gameOver().name === "Ann") { | ||
| this.over = true; | ||
| $("body").append("<h2>Her?</h2>"); | ||
| } else { | ||
| this.over = true; | ||
| $("body").append("<h2>fAmily LOVe " + this.gameOver().name + "!</h2>"); | ||
| } | ||
| }; | ||
|
|
||
| TicTacToe.prototype.gameOver = function() { | ||
| var b = this.board; | ||
| var one = this.playerOne; | ||
| var two = this.playerTwo; | ||
|
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. I'm a fan of explicit variable names ¯_(ツ)_/¯ I find it a lot easier when you're debugging old code—but that's my opinion. |
||
|
|
||
| // variables for the board | ||
|
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. explanatory comments?!? 😭😭😭 beauty. |
||
| var topLeft = b[0][0], topMid = b[0][1], topRight = b[0][2]; // top | ||
| var midLeft = b[1][0], midMid = b[1][1], midRight = b[1][2]; // middle | ||
| var bottomLeft = b[2][0], bottomMid = b[2][1], bottomRight = b[2][2]; // bottom | ||
|
|
||
|
|
||
| // player one wins vertically | ||
| if (topLeft === one && midLeft === one && bottomLeft === one) { | ||
| return one; | ||
| } else if (topMid === one && midMid === one && bottomMid === one) { | ||
| return one; | ||
| } else if (topRight === one && midRight === one && bottomRight === one) { | ||
| return one; | ||
| } | ||
|
|
||
| // player two wins vertically | ||
| if (topLeft === two && midLeft === two && bottomLeft === two) { | ||
|
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. This code looks identical to the conditional above it. Could you turn this into a method to DRY it up? |
||
| return two; | ||
| } else if (topMid === two && midMid === two && bottomMid === two) { | ||
| return two; | ||
| } else if (topRight === two && midRight === two && bottomRight === two) { | ||
| return two; | ||
| } | ||
|
|
||
| // player one wins horizontally | ||
| if (topLeft === one && topMid === one && topRight === one) { | ||
| return one; | ||
| } else if (midLeft === one && midMid === one && midRight === one) { | ||
| return one; | ||
| } else if (bottomLeft === one && bottomMid === one && bottomRight === one) { | ||
| return one; | ||
| } | ||
|
|
||
| // player two wins horizontally | ||
| if (topLeft === two && topMid === two && topRight === two) { | ||
| return two; | ||
| } else if (midLeft === two && midMid === two && midRight === two) { | ||
| return two; | ||
| } else if (bottomLeft === two && bottomMid === two && bottomRight === two) { | ||
| return two; | ||
| } | ||
|
|
||
| // player one wins diagonally | ||
| if (topLeft === one && midMid === one && bottomRight === one) { | ||
| return one; | ||
| } else if (topRight === one && midMid === one && bottomLeft === one) { | ||
| return one; | ||
| } | ||
|
|
||
| // player two wins diagonally | ||
| if (topLeft === two && midMid === two && bottomRight === two) { | ||
| return two; | ||
| } else if (topRight === two && midMid === two && bottomLeft === two) { | ||
| return two; | ||
| } | ||
|
|
||
| // there's a draw if no one has won after 9 turns | ||
|
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. YES! To this comment & elegant code combo! |
||
| if (this.turns > 8) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| TicTacToe.prototype.switchPlayer = function () { | ||
| if (this.currentPlayer === this.playerOne) { | ||
| this.currentPlayer = this.playerTwo; | ||
| } else { | ||
| this.currentPlayer = this.playerOne; | ||
| } | ||
| }; | ||
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.
So happy with your class & id names.☺️