-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
53 lines (43 loc) · 1012 Bytes
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { useState } from 'react'
import './App.css'
// components & screens
import Intro from './screens/intro/Intro'
import Game from './screens/game/Game'
import End from './screens/end/End'
// constants
const STAGE = Object.freeze({
START: 'start',
INTRO: 'intro',
PLAYING: 'playing',
END: 'end',
})
const name = 'Kay'
function App() {
const [stage, setStage] = useState(STAGE.INTRO)
let content
if (stage === STAGE.START) {
content = (
<>
<h1>Welcome to our game!</h1>
<button onClick={_ => setStage(STAGE.INTRO)}>Enter</button>
</>
)
}
if (stage === STAGE.INTRO) {
content = <Intro
name={name}
onStart={_ => setStage(STAGE.PLAYING)}
onEnd={_ => setStage(STAGE.END)}
/>
}
if (stage === STAGE.PLAYING) {
content = <Game name={name} onEnd={_ => setStage(STAGE.END)} />
}
if (stage === STAGE.END) {
content = <End />
}
return (
<div className='app'>{content}</div>
)
}
export default App