forked from AdaGold/react-tic-tac-toe
-
Notifications
You must be signed in to change notification settings - Fork 37
FIRE - Alice D. and Tram #14
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
Open
trambui09
wants to merge
12
commits into
Ada-C14:master
Choose a base branch
from
codeandmorecode:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7987307
generateSquareComponents function updated and rendering all 9 squares…
codeandmorecode 8622def
added the callback function to the componenets and passed the tests
trambui09 75ce296
got the x and o's to show up on board
trambui09 0bbbdfc
completed wave 2 with the board rendering the x and o's correctly
trambui09 a5a8fa0
unskipped the wave 2 tests and fixed the X to lowercase x
trambui09 178ddf0
commit before merge
codeandmorecode 9f967f1
winner correctly determined and displayed in header
codeandmorecode 3dec7b7
prevent the board from updating after the winner is determined
trambui09 952466a
passed all wave 3 tests
trambui09 4b82e34
completed the resetGame method and accounted for ties
trambui09 06a8eb4
removed superflous comments
trambui09 0460c20
adjusted line spacing
trambui09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -22,4 +22,4 @@ npm-debug.log* | |
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .eslintcache | ||
|
|
||
| package-lock.json | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -29,40 +29,65 @@ const App = () => { | |
|
|
||
| // This starts state off as a 2D array of JS objects with | ||
| // empty value and unique ids. | ||
| const [squares, setSquares] = useState(generateSquares()); | ||
| const [squareList, setSquares] = useState(generateSquares()); | ||
| const [playCount, setPlayCount] = useState(0) | ||
| const [winner, setWinner] = useState('') | ||
|
|
||
| // Wave 2 | ||
| // You will need to create a method to change the square | ||
| // When it is clicked on. | ||
| // Then pass it into the squares as a callback | ||
| const callback = (updatedSquare) => { | ||
| const squares = [...squareList] | ||
|
|
||
| for (let j = 0; j < 3; j++) { | ||
| for (let i = 0; i < 3; i++) { | ||
| let currentSquare = squares[j][i] | ||
| if (currentSquare.id === updatedSquare.id) { | ||
| if (currentSquare.value !== '') { break; } | ||
| if (winner !== '') {break;} | ||
| playCount % 2 === 0 ? currentSquare.value = 'x' : currentSquare.value = 'o' | ||
|
|
||
| setPlayCount(playCount + 1) | ||
| checkForWinner() | ||
| } | ||
| } | ||
| } | ||
| setSquares(squares) | ||
| } | ||
|
|
||
| const checkForWinner = () => { | ||
|
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. 👍 |
||
| // Complete in Wave 3 | ||
| // You will need to: | ||
| // 1. Go accross each row to see if | ||
| // 3 squares in the same row match | ||
| // i.e. same value | ||
| // 2. Go down each column to see if | ||
| // 3 squares in each column match | ||
| // 3. Go across each diagonal to see if | ||
| // all three squares have the same value. | ||
|
|
||
| const winningConditions = [ | ||
| [squareList[0][0].value, squareList[0][1].value, squareList[0][2].value], | ||
| [squareList[1][0].value, squareList[1][1].value, squareList[1][2].value], | ||
| [squareList[2][0].value, squareList[2][1].value, squareList[2][2].value], | ||
| [squareList[0][0].value, squareList[1][0].value, squareList[2][0].value], | ||
| [squareList[0][1].value, squareList[1][1].value, squareList[2][1].value], | ||
| [squareList[0][2].value, squareList[1][2].value, squareList[2][2].value], | ||
| [squareList[0][0].value, squareList[1][1].value, squareList[2][2].value], | ||
| [squareList[0][2].value, squareList[1][1].value, squareList[2][0].value] | ||
| ] | ||
|
|
||
| for (let i = 0; i < winningConditions.length; i++) { | ||
| const [first, second, third] = winningConditions[i] | ||
| if (first === second && first === third && first !== ''){ | ||
| setWinner(winningConditions[i][0]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const resetGame = () => { | ||
| // Complete in Wave 4 | ||
| setSquares(generateSquares()) | ||
| setWinner('') | ||
| setPlayCount(0) | ||
| } | ||
|
|
||
| return ( | ||
| <div className="App"> | ||
| <header className="App-header"> | ||
| <h1>React Tic Tac Toe</h1> | ||
| <h2>The winner is ... -- Fill in for wave 3 </h2> | ||
| <button>Reset Game</button> | ||
| <h2>{(playCount === 9 && winner === '') ? 'It\'s a TIE!' : `Winner is ${winner}`} </h2> | ||
| <button onClick={resetGame}>Reset Game</button> | ||
| </header> | ||
| <main> | ||
| <Board squares={squares} /> | ||
| <Board squares={squareList} onClickCallback={callback} /> | ||
| </main> | ||
| </div> | ||
| ); | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍 , but I might use a more descriptive name to illustrate what this function does.