Skip to content

Commit 03ae9d3

Browse files
feat: design Gitclicker game and new architecture design
1 parent 6ffd67c commit 03ae9d3

27 files changed

+302
-208
lines changed

src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { BrowserRouter, Routes, Route } from 'react-router'
2-
import { Game } from '@/components/Game'
3-
import Home from '@/components/pages/Home'
2+
import Home from '@/pages/Home'
43
import { Navbar } from '@/components/layout/Navbar'
4+
import GitClicker from '@/pages/GitClicker'
55

66
export default function App() {
77
return (
88
<BrowserRouter>
99
<Routes>
1010
<Route path="/" element={<Navbar />}>
1111
<Route index element={<Home />} />
12-
<Route path="gitclicker" element={<Game />} />
12+
<Route path="gitclicker" element={<GitClicker />} />
1313
</Route>
1414
</Routes>
1515
</BrowserRouter>

src/components/Game.css

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/components/Game.tsx

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/components/Home.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/components/Office.tsx

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/components/Store.css

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/components/Store.tsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/components/game/Game.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { useEffect, useState } from 'react'
2+
import '@/styles/game/index.css'
3+
import type { Item, OwnedItems } from '@/types'
4+
import { Grid2 as Grid, Card, CardContent, CardHeader } from '@mui/material'
5+
import { items } from '@/constants/items'
6+
import { Score, Gitcoin } from '@/components/game/core'
7+
import { Skills } from '@/components/game/skills'
8+
import { Store } from '@/components/game/store'
9+
10+
export function Game() {
11+
const [lines, setLines] = useState(0)
12+
const [linesPerMillisecond, setLinesPerMillisecond] = useState(0)
13+
14+
const [ownedItems, setOwnedItems] = useState<OwnedItems>({})
15+
16+
useEffect(() => {
17+
const interval = setInterval(() => {
18+
setLines(prev => prev + linesPerMillisecond)
19+
}, 100)
20+
return () => clearInterval(interval)
21+
}, [linesPerMillisecond])
22+
23+
useEffect(() => {
24+
let count = 0
25+
26+
Object.keys(ownedItems).forEach((name) => {
27+
const item = items.find(element => element.name === name)
28+
29+
if (item != null) {
30+
count += item.linesPerMillisecond * ownedItems[name]
31+
}
32+
})
33+
34+
setLinesPerMillisecond(count)
35+
}, [ownedItems])
36+
37+
const handleClick = () => {
38+
setLines(lines + 1)
39+
}
40+
41+
const handleBuy = (item: Item) => {
42+
setLines(lines - item.price)
43+
setOwnedItems({
44+
...ownedItems,
45+
[item.name]: (ownedItems[item.name] || 0) + 1,
46+
})
47+
}
48+
49+
return (
50+
<>
51+
<Grid size={3}>
52+
<Card component="section" className="card">
53+
<CardContent className="content">
54+
<Score
55+
lines={Math.ceil(lines)}
56+
linesPerSecond={Math.ceil(linesPerMillisecond * 10)}
57+
/>
58+
<Gitcoin onClick={handleClick} />
59+
</CardContent>
60+
</Card>
61+
</Grid>
62+
<Grid size="grow">
63+
<Card component="section" className="card">
64+
<CardHeader title="Skills" />
65+
<CardContent sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
66+
<Skills skills={ownedItems} />
67+
</CardContent>
68+
</Card>
69+
</Grid>
70+
<Grid size="grow">
71+
<Card component="section" className="card">
72+
<CardHeader title="Store" />
73+
<CardContent>
74+
<Store lines={lines} onBuy={handleBuy} />
75+
</CardContent>
76+
</Card>
77+
</Grid>
78+
</>
79+
)
80+
}

src/components/Gitcoin.tsx renamed to src/components/game/core/Gitcoin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import './Gitcoin.css'
1+
import '@/styles/game/core/gitcoin.css'
22
import githubIcon from '@/assets/github.svg'
33

44
type Props = {
File renamed without changes.

0 commit comments

Comments
 (0)