-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project-Labyrinth #12
base: main
Are you sure you want to change the base?
Changes from all commits
bb2fe22
01187b9
5c6e0f3
9b9d135
d5d4ef3
9f7519c
5ad4d8a
4d8e75d
97ad0ad
b956d99
1516f6c
a5f392b
f9232e4
e923a1a
a45480e
e612a41
3d497f6
3c9a998
e428f18
05b7366
ceef977
091e95b
8b0e135
40407a2
f9578ac
de35b04
ece7549
577ceca
74a68fa
dd6f3fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,24 @@ | ||
<h1 align="center"> | ||
<a href=""> | ||
<img src="./src/assets/banner.svg" alt="Project Banner Image"> | ||
<img src="public/cover-image-github.png" alt="Project preview image"> | ||
</a> | ||
</h1> | ||
|
||
# Labyrinth - Zustand Project | ||
|
||
Replace this readme with your own information about your project. | ||
|
||
Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
|
||
## Getting Started with the Project | ||
|
||
### Dependency Installation & Startup Development Server | ||
|
||
Once cloned, navigate to the project's root directory and this project uses npm (Node Package Manager) to manage its dependencies. | ||
|
||
The command below is a combination of installing dependencies, opening up the project on VS Code and it will run a development server on your terminal. | ||
|
||
```bash | ||
npm i && code . && npm run dev | ||
``` | ||
This project is a labyrinth game app and is using the zustand library. Fetching from an API to show players where they can navigate. | ||
|
||
### The Problem | ||
|
||
Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next? | ||
First we tried to layout what we needed and what we wanted to achieve. Next step was to take a look at the API results in Postman. We struggle to fetch 'POST' from two different URLs and connecting them. | ||
Thanks to help from a fellow bootcamp student, the game finally worked. It took longer than we expected and wanted to. | ||
|
||
### View it live | ||
|
||
Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about. | ||
Here our maze game. | ||
|
||
## Instructions | ||
|
||
<a href="instructions.md"> | ||
See instructions of this project | ||
<a href="https://fun-maze.netlify.app/"> | ||
Labyrinth Maze | ||
</a> |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
import { Username } from "./components/Username" | ||
import { useStore } from "./store/useStore" | ||
import { StartGame } from "./components/StartGame" | ||
// import { BrowserRouter, Routes} from "react-router-dom"; | ||
// import { routes } from "./routes/routes"; | ||
|
||
export const App = () => { | ||
const { username } = useStore() | ||
|
||
return ( | ||
<div> | ||
Labyrinth Project | ||
</div> | ||
); | ||
}; | ||
<> | ||
{/* <BrowserRouter> */} | ||
<div> | ||
{!username && <Username />} | ||
{username && <StartGame />} | ||
</div> | ||
|
||
{/* <Routes>{routes}</Routes> | ||
</BrowserRouter> */} | ||
</> | ||
) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"v":"5.1.18","fr":30,"ip":0,"op":120,"w":1080,"h":1080,"nm":"Loader 2","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Outline Sides 4","parent":2,"sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[102.47,68.411,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[21.675,21.675,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-108.75,-72.625],[-179.313,-141.563],[-297,-19.5],[-158.188,117.188],[-85.25,44]],"o":[[-108.75,-72.625],[-179.313,-141.563],[-297,-19.5],[-158.188,117.188],[-85.25,44]],"v":[[-108.75,-72.625],[-179.313,-141.563],[-297,-19.5],[-158.188,117.188],[-85.25,44]],"c":false},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false,"_render":true},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[109.5,-72.75],[177.438,-141.563],[315.75,-3],[198.25,113.5],[130,45]],"o":[[109.5,-72.75],[177.438,-141.563],[315.75,-3],[198.25,113.5],[130,45]],"v":[[109.5,-72.75],[177.438,-141.563],[315.75,-3],[198.25,113.5],[130,45]],"c":false},"ix":2},"nm":"Path 2","mn":"ADBE Vector Shape - Group","hd":false,"_render":true},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform","_render":true}],"nm":"Shape 1","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false,"_render":true},{"ty":"tm","s":{"a":0,"k":42,"ix":1},"e":{"a":0,"k":0,"ix":2},"o":{"a":1,"k":[{"i":{"x":[0.447],"y":[0.812]},"o":{"x":[0.546],"y":[0.209]},"n":["0p447_0p812_0p546_0p209"],"t":0,"s":[-76],"e":[644]},{"t":119}],"ix":3},"m":2,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false,"_render":true},{"ty":"gs","o":{"a":0,"k":100,"ix":9},"w":{"a":0,"k":29,"ix":10},"g":{"p":3,"k":{"a":0,"k":[0,0.42,0.42,0.42,0.206,0.7255,0.7255,0.7255,0.77,0.27,0.27,0.27],"ix":8}},"s":{"a":0,"k":[-73,0],"ix":4},"e":{"a":0,"k":[151,0],"ix":5},"t":1,"lc":1,"lj":1,"ml":4,"nm":"Gradient Stroke 2","mn":"ADBE Vector Graphic - G-Stroke","hd":false,"_render":true}],"ip":0,"op":120,"st":-27,"bm":0,"completed":true},{"ddd":0,"ind":2,"ty":4,"nm":"Fill Center","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[520.938,518.938,0],"ix":2},"a":{"a":0,"k":[103.5,66,0],"ix":1},"s":{"a":0,"k":[461.353,461.353,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[-19.15,14.9],[-2.15,31.9],[31.85,-2.1],[27.55,-6.4],[-2.15,23.4],[-14.85,10.6],[6.45,-10.7],[2.15,-15],[-19.15,6.4],[-23.45,10.7]],"o":[[-19.15,14.9],[-2.15,31.9],[31.85,-2.1],[27.55,-6.4],[-2.15,23.4],[-14.85,10.6],[6.45,-10.7],[2.15,-15],[-19.15,6.4],[-23.45,10.7]],"v":[[-19.15,14.9],[-2.15,31.9],[31.85,-2.1],[27.55,-6.4],[-2.15,23.4],[-14.85,10.6],[6.45,-10.7],[2.15,-15],[-19.15,6.4],[-23.45,10.7]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false,"_render":true},{"ind":1,"ty":"sh","ix":2,"ks":{"a":0,"k":{"i":[[19.15,-14.9],[6.35,-27.6],[2.05,-31.9],[-2.15,-27.6],[-31.85,2.1],[-27.55,6.3],[2.15,-23.4],[14.85,-10.6],[-6.35,10.6],[-2.05,14.9],[19.251,-6.4],[23.55,-10.6]],"o":[[19.15,-14.9],[6.35,-27.6],[2.05,-31.9],[-2.15,-27.6],[-31.85,2.1],[-27.55,6.3],[2.15,-23.4],[14.85,-10.6],[-6.35,10.6],[-2.05,14.9],[19.251,-6.4],[23.55,-10.6]],"v":[[19.15,-14.9],[6.35,-27.6],[2.05,-31.9],[-2.15,-27.6],[-31.85,2.1],[-27.55,6.3],[2.15,-23.4],[14.85,-10.6],[-6.35,10.6],[-2.05,14.9],[19.251,-6.4],[23.55,-10.6]],"c":true},"ix":2},"nm":"Path 2","mn":"ADBE Vector Shape - Group","hd":false,"_render":true},{"ty":"tr","p":{"a":0,"k":[104.954,65.304],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform","_render":true}],"nm":"Group 3","np":2,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false,"_render":true},{"ty":"gf","o":{"a":0,"k":100,"ix":10},"r":1,"g":{"p":3,"k":{"a":0,"k":[0.088,0.42,0.42,0.42,0.374,0.7255,0.7255,0.7255,0.95,0.27,0.27,0.27],"ix":9}},"s":{"a":0,"k":[62,13],"ix":5},"e":{"a":0,"k":[100,0],"ix":6},"t":1,"nm":"Gradient Fill 1","mn":"ADBE Vector Graphic - G-Fill","hd":false,"_render":true}],"ip":0,"op":120,"st":0,"bm":0,"completed":true}],"markers":[],"__complete":true} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Lottie from "lottie-react" | ||
import { useStore } from "../store/useStore" | ||
import "../styles/StartGame.css" | ||
import Loading from "../assets/loading.json" | ||
|
||
export const StartGame = () => { | ||
const { gameInfo, setActionData, fetchActionData, loading, actionData } = | ||
useStore() | ||
|
||
const handleClick = async (actionDirection) => { | ||
await setActionData(actionDirection) | ||
await fetchActionData() | ||
} | ||
|
||
if (loading) { | ||
return ( | ||
<Lottie | ||
animationData={Loading} | ||
loop={true} | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<div className='start-game-container'> | ||
<p>{actionData ? actionData.description : gameInfo?.description}</p> | ||
{/* If there is actionData, show the description */} | ||
<div className='direction-container'> | ||
{/* If there is no actionData, show gameinfo */} | ||
{!actionData && | ||
gameInfo?.actions?.map((action, index) => ( | ||
<div key={index}> | ||
<p>{action.description}</p> | ||
<button onClick={() => handleClick(action.direction)}> | ||
Go {action.direction} | ||
</button> | ||
</div> | ||
))} | ||
</div> | ||
{/* Descriptions are now displayed consistently here */} | ||
{actionData?.actions?.map((action, index) => ( | ||
<div key={index}> | ||
<p>{action.description}</p> | ||
<button onClick={() => handleClick(action.direction)}> | ||
Go {action.direction} | ||
</button> | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Lottie from "lottie-react" | ||
import { useStore } from "../store/useStore" | ||
import { useState } from "react" | ||
import "../styles/Username.css" | ||
import Loading from "../assets/loading.json" | ||
|
||
export const Username = () => { | ||
const [usernameInput, setUsernameInput] = useState("") //this is local value, not the global one. the hook is for updating username | ||
const { setUsername, fetchStartData, loading, error } = useStore() //import variable from globle state | ||
|
||
//fetch data by using the fetch funcion from global state | ||
const handleSubmit = async () => { | ||
setUsername(usernameInput) | ||
await fetchStartData(usernameInput) | ||
} | ||
|
||
if (loading) { | ||
return ( | ||
<Lottie | ||
animationData={Loading} | ||
loop={true} | ||
/> | ||
) | ||
} | ||
Comment on lines
+17
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Liking this! Very labyrinthy 😏 |
||
|
||
if (error) { | ||
return <div>Error: {error}</div> | ||
} | ||
|
||
return ( | ||
<div className='start-background'> | ||
<div className='main-container'> | ||
<h1>THE MAZE</h1> | ||
<p>Can you find a way out of the maze?</p> | ||
<p>Enter the labyrinth at your own risk.</p> | ||
<br /> | ||
</div> | ||
<form onSubmit={handleSubmit}> | ||
<label> Enter your username: </label> | ||
<input | ||
type='text' | ||
value={usernameInput} | ||
onChange={(e) => setUsernameInput(e.target.value)} | ||
/> | ||
Comment on lines
+40
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably don't want to allow empty inputs |
||
<button type='submit'>Submit</button> | ||
</form> | ||
</div> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused code and the fragment and just wrap everything in a div for cleaner code