-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grzegorz Tańczyk
committed
Jul 10, 2024
1 parent
0bbe390
commit 39ab87f
Showing
7 changed files
with
76 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useState } from 'react'; | ||
import { GameState, GameStateComponent } from './types'; | ||
import { GameStatePlaying } from './state-playing'; | ||
|
||
const PlayComponent: GameStateComponent = ({ setGameState }) => { | ||
const [stateName, setStateName] = useState(''); | ||
|
||
const handlePlay = () => { | ||
setGameState(GameStatePlaying, { stateName, gameId: String(Date.now()) }); | ||
}; | ||
|
||
return ( | ||
<> | ||
<input | ||
type="text" | ||
placeholder="Name your state" | ||
value={stateName} | ||
onChange={(event) => setStateName(event.currentTarget.value)} | ||
/> | ||
|
||
<button onClick={handlePlay} disabled={!stateName}> | ||
Play | ||
</button> | ||
</> | ||
); | ||
}; | ||
|
||
export const GameStatePlay: GameState = { | ||
Component: PlayComponent, | ||
path: '/play', | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { GameState, GameStateComponent } from './types'; | ||
|
||
const PlayedComponent: GameStateComponent = ({}) => { | ||
return <>Game over, results</>; | ||
}; | ||
|
||
export const GameStatePlayed: GameState = { | ||
Component: PlayedComponent, | ||
path: '/playing', | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useLocation } from 'react-router'; | ||
import { GameState, GameStateComponent } from './types'; | ||
|
||
const PlayingComponent: GameStateComponent = ({}) => { | ||
const { | ||
state: { stateName, gameId }, | ||
} = useLocation(); | ||
|
||
return ( | ||
<> | ||
Playing: {stateName} {gameId} | ||
Render world | ||
</> | ||
); | ||
}; | ||
|
||
export const GameStatePlaying: GameState = { | ||
Component: PlayingComponent, | ||
path: '/playing', | ||
}; |
This file contains 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 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