|
1 |
| -import React, { useState, useEffect } from 'react' |
2 |
| -import './Game.css' |
| 1 | +import React, { useEffect } from 'react' |
| 2 | +import { useDispatch } from 'react-redux' |
3 | 3 | import Paper from '@material-ui/core/Paper'
|
| 4 | +import './Game.css' |
| 5 | +import { loop } from 'modules/game' |
4 | 6 | import { Navbar } from 'components/layout/Navbar'
|
5 | 7 | import { Gitcoin } from 'components/Gitcoin'
|
6 | 8 | import { Score } from 'components/Score'
|
7 | 9 | import { Store } from 'components/Store/Store'
|
8 | 10 | import { Skills } from 'components/Skills'
|
9 |
| -import items from '../../items' |
10 | 11 |
|
11 | 12 | export const Game = () => {
|
12 |
| - const [lines, setLines] = useState(0) |
13 |
| - const [linesPerMillisecond, setLinesPerMillisecond] = useState(0) |
14 |
| - const [ownedItems, setOwnedItems] = useState({}) |
| 13 | + const dispatch = useDispatch() |
15 | 14 |
|
16 | 15 | useEffect(() => {
|
17 | 16 | const interval = setInterval(() => {
|
18 |
| - setLines(lines + linesPerMillisecond) |
| 17 | + dispatch(loop()) |
19 | 18 | }, 100)
|
20 | 19 |
|
21 | 20 | return () => clearInterval(interval)
|
22 | 21 | })
|
23 | 22 |
|
24 |
| - useEffect(() => { |
25 |
| - let count = 0 |
26 |
| - |
27 |
| - Object.keys(ownedItems).forEach(name => { |
28 |
| - const item = items.find(element => element.name === name) |
29 |
| - count += item.multiplier * ownedItems[name] |
30 |
| - }) |
31 |
| - |
32 |
| - setLinesPerMillisecond(count) |
33 |
| - }, [ownedItems]) |
34 |
| - |
35 |
| - const handleClick = () => { |
36 |
| - setLines(lines + 1) |
37 |
| - } |
38 |
| - |
39 |
| - const handleBuy = item => { |
40 |
| - setLines(lines - item.price) |
41 |
| - setOwnedItems({ |
42 |
| - ...ownedItems, |
43 |
| - [item.name]: (ownedItems[item.name] || 0) + 1 |
44 |
| - }) |
45 |
| - } |
46 |
| - |
47 | 23 | return (
|
48 | 24 | <>
|
49 | 25 | <Navbar />
|
50 | 26 | <main className="game">
|
51 | 27 | <Paper elevation={3} className="left">
|
52 |
| - <Score |
53 |
| - lines={lines} |
54 |
| - linesPerSecond={parseInt(linesPerMillisecond * 10)} |
55 |
| - /> |
56 |
| - <Gitcoin onClick={handleClick} /> |
| 28 | + <Score /> |
| 29 | + <Gitcoin /> |
57 | 30 | </Paper>
|
58 | 31 |
|
59 | 32 | <Paper elevation={3} className="center">
|
60 |
| - <Skills skills={ownedItems} /> |
| 33 | + <Skills /> |
61 | 34 | </Paper>
|
62 | 35 |
|
63 | 36 | <Paper elevation={3} className="right">
|
64 |
| - <Store |
65 |
| - lines={lines} |
66 |
| - onBuy={handleBuy} |
67 |
| - /> |
| 37 | + <Store /> |
68 | 38 | </Paper>
|
69 | 39 | </main>
|
70 | 40 | </>
|
|
0 commit comments