Skip to content
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

Alma and Wen - Labyrinth project #3

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7a20f30
Install zustand package
wwenzz Apr 15, 2024
3a43436
Create useStore for the startgame
wwenzz Apr 16, 2024
8721c7b
Make the start API call work
wwenzz Apr 16, 2024
ca9c973
Create action page component that displays the data for the current p…
wwenzz Apr 16, 2024
c7d924c
Create makeMove state in store
wwenzz Apr 16, 2024
6eff1a0
Implement restart state and button
wwenzz Apr 16, 2024
813a73f
Disable submit when no input
wwenzz Apr 16, 2024
a9931b2
Add the date details to the name so as to make it unique
wwenzz Apr 16, 2024
b83111a
Merge pull request #1 from wwenzz/movement-logic
wwenzz Apr 16, 2024
e5939c8
Style the first page and add media query for font size changes
wwenzz Apr 16, 2024
60c5c48
Implement useRef to change bg image for action pages
wwenzz Apr 16, 2024
be06687
Merge pull request #2 from wwenzz/style-start-page
wwenzz Apr 16, 2024
8654f36
Add some background images and make restart button work to change bac…
wwenzz Apr 17, 2024
be8d675
Merge pull request #3 from wwenzz/changeBg-logic
wwenzz Apr 17, 2024
6170ec8
Added backgrounds
almaherris Apr 18, 2024
99d939f
Add loading animation and styled action page
almaherris Apr 19, 2024
160bc49
Media query for actionpage
almaherris Apr 19, 2024
3a978ff
Worked together with loading of images
almaherris Apr 19, 2024
5471e8d
Update readme and add og tags
almaherris Apr 19, 2024
90879c4
Add og image to public folder so as to get the URL
wwenzz Apr 19, 2024
abe5287
Replace the og image url
wwenzz Apr 19, 2024
228264f
Responsiveness for form
almaherris Apr 19, 2024
88c43a0
Move backgrounds to public folder for deployment
wwenzz Apr 19, 2024
c05dc41
use absolute path to display background
wwenzz Apr 19, 2024
19259df
changed place of images
almaherris Apr 19, 2024
0a0e02c
Change place again
almaherris Apr 19, 2024
a92cdc3
changed path
almaherris Apr 19, 2024
9d250d0
remove console logs
almaherris Apr 19, 2024
cb4ad7b
Add favicon and update the website title
wwenzz Apr 19, 2024
0d8c4b4
Remove the duplicated loading from action page
wwenzz Apr 19, 2024
8d79870
Style the start button when disable
wwenzz Apr 19, 2024
e8638ce
Preload background images
wwenzz Apr 19, 2024
00ca49a
Preload start background image
wwenzz Apr 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
<h1 align="center">
<a href="">
<img src="./src/assets/banner.svg" alt="Project Banner 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
```
In this pair project, we built a text based adventure using Zustand for state management and an API from Technigo to post data.

### 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?
We approached the problem by laying out the components and stores we needed. We then ensured that the API calls worked as intended. We identified the states that should be defined globally with Zustand and used them in the components. As a next step, we made sure to implement a user-friendly design that would allow the user to quickly understand what to do.

### View it live
If we had more time we would look into more of the stretch goals.

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.

## Instructions
### View it live

<a href="instructions.md">
See instructions of this project
</a>
https://alma-wen-labyrinth.netlify.app/
21 changes: 19 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/src/assets/favicon.svg" />
<meta property="og:title" content="A Labyrinth Game" />
<meta
property="og:description"
content="A labyrinth game created by Alma and Wen"
/>
<meta
property="og:image"
content="https://i.postimg.cc/Fszys7Vp/preview.png"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Project Labyrinth Zustand</title>
<title>Mysterious Labyrinth</title>
<link rel="preload" href="start.jpeg" as="image" />
<link rel="preload" href="0,0.jpeg" as="image" />
<link rel="preload" href="0,1.jpeg" as="image" />
<link rel="preload" href="0,2.jpeg" as="image" />
<link rel="preload" href="0,3.jpeg" as="image" />
<link rel="preload" href="1,0.jpeg" as="image" />
<link rel="preload" href="1,1.jpeg" as="image" />
<link rel="preload" href="1,3.jpeg" as="image" />
</head>
<body>
<div id="root"></div>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"preview": "vite preview"
},
"dependencies": {
"lottie-web": "^5.12.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zustand": "^4.4.1"
"zustand": "^4.5.2"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
Binary file added public/0,0.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/0,1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/0,2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/0,3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/1,0.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/1,1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/1,3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/start.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions pull_request_template.md

This file was deleted.

7 changes: 4 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FirstPage } from "./components/FirstPage";

export const App = () => {
return (
<div>
Labyrinth Project
</div>
<>
<FirstPage />
</>
Comment on lines +5 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for fragments when you're only returning one element

);
};
1 change: 1 addition & 0 deletions src/assets/animations/loading-compass.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/assets/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/fonts/Gravedigger.ttf

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this font!

Binary file not shown.
Binary file added src/assets/fonts/Sdfortimburtondemo-ALoW2.ttf
Binary file not shown.
45 changes: 45 additions & 0 deletions src/components/ActionPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useEffect } from "react";
import { useLabyrinthStore } from "../stores/useLabyrinthStore";
import "../style/ActionPage.css";

export const ActionPage = ({ changeBgImg }) => {
const { coordinates, description, actions, makeMove, restart } =
useLabyrinthStore();

// useEffect that runs on mount of the component and changes the bg img
useEffect(() => {
changeBgImg(coordinates);
}, [changeBgImg, coordinates]);

return (
<div className="action-container">
<p>{description}</p>
<div className="button-container">
{actions.map((action, index) => (
<button
className="action-button"
value={action.direction}
key={index}
onClick={e => {
const direction = e.target.value;
makeMove(direction);
}}
>
{action.direction}
</button>
))}
</div>
<button
className="restart-button"
type="button"
onClick={() => {
restart();
// change background back to start page
changeBgImg("start");
}}
>
Restart
</button>
</div>
);
};
66 changes: 66 additions & 0 deletions src/components/FirstPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useRef, useState } from "react"
import { useLabyrinthStore } from "../stores/useLabyrinthStore"
import { ActionPage } from "./ActionPage"
import { LoadingAnimation } from "./LoadingAnimation"
import "../style/FirstPage.css"

export const FirstPage = () => {
// create ref for main container div
const bgImgRef = useRef()

const { loggedIn, startGame, loading } = useLabyrinthStore()
const [userInput, setUserInput] = useState("")
const handleSubmit = (e) => {
e.preventDefault()
setUserInput("")
startGame(userInput)
}

// function that changes the background img
const changeBgImg = (coordinates) => {
// replace the url for each coordinate
bgImgRef.current.style.backgroundImage = `url('${coordinates}.jpeg')`
}

if (loading) {
return <LoadingAnimation />
}

return (
<div
ref={bgImgRef}
className="main-container"
style={{ backgroundColor: "gray" }}>
{loggedIn ? (
<ActionPage changeBgImg={changeBgImg} />
) : (
<div className="start-container">
<h1 className="heading">Labyrinth</h1>
<h2 className="subheading">
Dare to tread the labyrinth&apos;s enigmatic paths, where secrets
lurk in every shadow.
</h2>
<p className="description">
Are you ready to uncover the secrets of the labyrinth? Embark on the
journey and find out.
</p>
<form className="form" onSubmit={handleSubmit}>
<label htmlFor="userName">Adventurer name:</label>
<input
id="userName"
type="text"
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
/>
<button
className="submit-btn"
disabled={userInput ? false : true}
type="submit">
Start
</button>
</form>
</div>
)}
</div>
)
}
28 changes: 28 additions & 0 deletions src/components/LoadingAnimation.jsx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice loading animation you found!

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect, useRef } from "react"
import lottie from "lottie-web"
import loadingCompass from "../assets/animations/loading-compass.json"
import "../style/LoadingAnimation.css"

export const LoadingAnimation = () => {
const container = useRef(null)

useEffect(() => {
const anim = lottie.loadAnimation({
container: container.current,
renderer: "svg",
loop: true,
autoplay: true,
animationData: loadingCompass,
})

return () => {
anim.destroy()
}
}, [])

return (
<div className="loading-container" style={{ backgroundColor: "gray" }}>
<div className="loading-animation" ref={container}></div>
</div>
)
}
113 changes: 15 additions & 98 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
/* font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
background-color: #242424; */

font-synthesis: none;
text-rendering: optimizeLegibility;
Expand All @@ -14,106 +14,23 @@
-webkit-text-size-adjust: 100%;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

html,
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
height: 100%;
}

/* APP Component CSS */
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "SD For Tim Burton";
}

.read-the-docs {
color: #888;
@font-face {
font-family: "Gravedigger";
src: url("./assets/fonts/Gravedigger.ttf") format("truetype");
}

/* Bio Comp */
.bioComp {
border: 1px solid red;
margin-bottom: 1em;
@font-face {
font-family: "SD For Tim Burton";
src: url("./assets/fonts//Sdfortimburtondemo-ALoW2.ttf") format("truetype");
}
Loading