Skip to content

Commit

Permalink
player 1 and two state
Browse files Browse the repository at this point in the history
  • Loading branch information
StevieBrooks committed Nov 6, 2023
1 parent b31afdc commit 9a3550f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export default function App() {
</>)
}

/*IDEAS
- add dropdown to change theme
- form so players can punch in their own names for scoreboard
- reset one game or entire match
- extra points for actiing quickly
*/

/*
Set Up Your React Project:
Start by creating a new React project using a tool like Create React App or your preferred setup.
Expand Down
3 changes: 2 additions & 1 deletion src/components/DashBoard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export default function DashBoard() {
</div>

)
}
}

3 changes: 1 addition & 2 deletions src/components/GameBoard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function GameBoard() {

<div className="game-board w-96 h-96 bg-slate-600 m-auto flex flex-wrap justify-center items-center">
{boardState.map((cell, index) => (
<GameCell key={index} />
<GameCell key={index} index={index} />
))}
</div>

Expand All @@ -28,4 +28,3 @@ export default function GameBoard() {
)
}

// need to figure out how to arrange cells
27 changes: 25 additions & 2 deletions src/components/GameCell.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
export default function GameCell() {
import { useContext } from "react"
import { GameState } from "../ContextFile"
import { FaO, FaX } from "react-icons/fa6"

export default function GameCell( { index } ) {

const [player, setPlayer, boardState, setBoardState, result, setResult] = useContext(GameState)

const clickHandler = (e) => {
const cellToAlter = e.target.classList[0]
const updatedBoardState = [...boardState]
updatedBoardState[cellToAlter] = player
setBoardState(updatedBoardState)

setPlayer(player === 1 ? 2 : 1)
console.log(player)
}

return (
<div className="game-cell w-28 h-28 m-2 bg-slate-400"></div>
<div className={`${index} game-cell w-28 h-28 m-2 bg-slate-400`} onClick={clickHandler}>
{
boardState[index] === 1 ? <FaO style={{display: "block"}} /> : boardState[index] === 2 ? <FaX style={{display: "block"}} /> : null

}

</div>
)
}

2 comments on commit 9a3550f

@vercel
Copy link

@vercel vercel bot commented on 9a3550f Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 9a3550f Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.