-
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 - Viktoria O. #7
base: main
Are you sure you want to change the base?
Changes from all commits
440ee5b
d11a804
d46b47c
ebf8faa
20c4bff
f361db7
feb2990
de92c03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Home } from "./components/Home/Home"; | ||
import { Loading } from "./components/Loading/Loading"; | ||
import { useLabyrinthStore } from "./store/useLabyrinthStore"; | ||
|
||
export const App = () => { | ||
return ( | ||
<div> | ||
Labyrinth Project | ||
</div> | ||
); | ||
const { loading } = useLabyrinthStore(); | ||
|
||
return <>{loading ? <Loading /> : <Home />}</>; | ||
}; |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
margin: 16px; | ||
} | ||
|
||
@media (min-width: 668px) { | ||
.container { | ||
margin: 20px 36px 20px 36px; | ||
} | ||
} | ||
|
||
@media (min-width: 1024px) { | ||
.container { | ||
margin: 0 36px 0 36px; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useLabyrinthStore } from "../../store/useLabyrinthStore"; | ||
import { UsernameInput } from "../UsernameInput/UsernameInput"; | ||
import { Scene } from "../Scene/Scene"; | ||
import { SceneCard } from "../SceneCard/SceneCard"; | ||
import "./Home.css"; | ||
|
||
export const Home = () => { | ||
const { apiData, username } = useLabyrinthStore(); | ||
|
||
return ( | ||
<div className="container"> | ||
{!username ? <UsernameInput /> : <Scene />} | ||
{apiData && <SceneCard />} | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.loader { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
} | ||
|
||
@media (min-width: 668px) { | ||
.loader { | ||
height: 60vh; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Lottie from "lottie-react"; | ||
import animationData from "../../animation.json"; | ||
import "./Loading.css" | ||
|
||
export const Loading = () => { | ||
return ( | ||
<div className="loader"> | ||
<Lottie animationData={animationData} /> | ||
</div> | ||
); | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.location-image { | ||
width: 100%; | ||
height: 300px; | ||
object-fit: cover; | ||
border: solid white 2px; | ||
} | ||
|
||
@media (min-width: 668px) { | ||
.scene-div { | ||
margin-top: 16px; | ||
} | ||
.location-image { | ||
height: 500px; | ||
} | ||
} | ||
|
||
|
||
@media (min-width: 1024px) { | ||
.scene-div { | ||
max-width: 700px; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useLabyrinthStore } from "../../store/useLabyrinthStore"; | ||
import locationImage from "../locationImage.json"; | ||
import "./Scene.css"; | ||
|
||
export const Scene = () => { | ||
const { locationDescription, coordinates } = useLabyrinthStore(); | ||
const image = locationImage.find((img) => img.imgCoordinates === coordinates); | ||
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. Nice solution! |
||
|
||
return ( | ||
<div className="scene-div"> | ||
<img | ||
className="location-image" | ||
src={image.imageUrl} | ||
alt={image.altText} | ||
/> | ||
<p>{locationDescription}</p> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.actions-container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.actions-div { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
text-align: center; | ||
border-top: solid 1px white; | ||
} | ||
|
||
.move-btn { | ||
font-size: 1.2rem; | ||
letter-spacing: 3px; | ||
min-width: 120px; | ||
max-width: 300px; | ||
font-size: 1rem; | ||
margin: 1rem; | ||
background: #881400; | ||
} | ||
|
||
.move-btn:hover { | ||
background: #a81000; | ||
} | ||
|
||
.look-btn { | ||
background: #0000bc; | ||
min-width: 80px; | ||
font-size: 1rem; | ||
max-width: 300px; | ||
letter-spacing: 3px; | ||
margin: 1rem; | ||
} | ||
|
||
.look-btn:hover { | ||
background: #0000fc; | ||
} | ||
|
||
.hidden { | ||
display: none; | ||
} | ||
|
||
@media (min-width: 1024px) { | ||
.actions-container { | ||
flex-direction: column; | ||
justify-content: space-between; | ||
max-width: 700px; | ||
} | ||
.actions-div { | ||
flex-direction: row; | ||
border-top: none; | ||
text-align: left; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useLabyrinthStore } from "../../store/useLabyrinthStore"; | ||
import "./SceneCard.css"; | ||
|
||
export const SceneCard = () => { | ||
const { apiData, username, nextMove, actions, isHidden, toggleHidden } = | ||
useLabyrinthStore(); | ||
|
||
return ( | ||
<> | ||
{actions.length > 0 && ( | ||
<div className="actions-container"> | ||
<button className="look-btn" onClick={toggleHidden}> | ||
Look around | ||
</button> | ||
{actions.map((action, index) => ( | ||
<div key={index} className="actions-div"> | ||
<p className={isHidden ? "hidden" : ""}>{action.description}</p> | ||
<button | ||
className="move-btn" | ||
onClick={() => nextMove(username, action.direction)} | ||
> | ||
{`GO ${action.direction}`} | ||
</button> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.username-form { | ||
display: flex; | ||
flex-direction: column; | ||
text-shadow: 1px 1px 2px gray; | ||
align-items: center; | ||
text-align: center; | ||
} | ||
|
||
.username-form input { | ||
width: 100%; | ||
min-width: 220px; | ||
max-width: 400px; | ||
font-family: "DotGothic16", sans-serif; | ||
letter-spacing: 1px; | ||
margin: 1rem 0 1rem 0; | ||
} | ||
|
||
.start-btn { | ||
background: #005800; | ||
margin: 1rem; | ||
font-size: 1.2rem; | ||
letter-spacing: 3px; | ||
min-width: 18 0px; | ||
max-width: 300px; | ||
} | ||
|
||
.start-btn:hover { | ||
background: #006800; | ||
} | ||
|
||
@media (min-width: 668px) { | ||
.username-form { | ||
padding: 100px; | ||
} | ||
} | ||
|
||
@media (min-width: 1024px) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useState } from "react"; | ||
import { useLabyrinthStore } from "../../store/useLabyrinthStore"; | ||
import "./UsernameInput.css"; | ||
|
||
export const UsernameInput = () => { | ||
const { startGame } = useLabyrinthStore(); | ||
const [playerName, setPlayerName] = useState(""); | ||
|
||
const handleSubmit = async (event) => { | ||
event.preventDefault(); | ||
await startGame(playerName); | ||
}; | ||
return ( | ||
<form className="username-form" onSubmit={handleSubmit}> | ||
<h1>Welcome, traveller.</h1> | ||
<p>To begin the adventure, please enter your name:</p> | ||
<label> | ||
<input | ||
type="text" | ||
value={playerName} | ||
placeholder="Enter your name" | ||
onChange={(event) => setPlayerName(event.target.value)} | ||
/> | ||
Comment on lines
+18
to
+23
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. Maybe you'd want to account for missing input here |
||
</label> | ||
<button className="start-btn" type="submit"> | ||
start game | ||
</button> | ||
</form> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[ | ||
{ | ||
"altText": "archway leading into a cave", | ||
"imgCoordinates": "0,0", | ||
"imageUrl": "/cave-opening.jpg" | ||
}, | ||
{ | ||
"altText": "cave with lightrays penetrating the ceiling", | ||
"imgCoordinates": "1,0", | ||
"imageUrl": "/lightrays.jpg" | ||
}, | ||
{ | ||
"altText": "colourful cave wall", | ||
"imgCoordinates": "1,1", | ||
"imageUrl": "/colourful-cave.jpg" | ||
}, | ||
{ | ||
"altText": "machine room", | ||
"imgCoordinates": "0,1", | ||
"imageUrl": "/machine-room.jpg" | ||
}, | ||
{ | ||
"altText": "machine interface", | ||
"imgCoordinates": "0,2", | ||
"imageUrl": "/machine-exit.jpg" | ||
}, | ||
{ | ||
"altText": "library", | ||
"imgCoordinates": "0,3", | ||
"imageUrl": "/books.jpg" | ||
}, | ||
{ | ||
"altText": "view of mountainside in sunlight", | ||
"imgCoordinates": "1,3", | ||
"imageUrl": "/light-exit.jpg" | ||
} | ||
] |
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.
Nice loader ⭐