Skip to content
This repository was archived by the owner on Jan 3, 2025. It is now read-only.
Merged

2048 #96

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c85eadb
Defined Grid and Tiles for 2048 Game
Christian2147 Oct 10, 2024
eb07542
Functional 2048 Game
Christian2147 Oct 11, 2024
51d11df
Fixed Styling
Christian2147 Oct 11, 2024
045b116
Added GUI Functionality
Christian2147 Oct 12, 2024
f6f2e79
Fixed Styling
Christian2147 Oct 12, 2024
aaaa4fe
Created Leaderboard databse
Christian2147 Oct 22, 2024
4dc773f
Forgor to save file
Christian2147 Oct 22, 2024
f21c9e9
Finished Leaderboard Frontend
Christian2147 Oct 26, 2024
493637c
Finished 2048 Game
Christian2147 Oct 29, 2024
0df8868
2048 Done
Christian2147 Nov 5, 2024
737d5ca
Merge branch 'main' into 2048
Christian2147 Nov 5, 2024
bc1e17c
Prettified Code!
Christian2147 Nov 5, 2024
81ec45c
re add package lock
Christian2147 Nov 5, 2024
f9da8f1
Merge branch '2048' of https://github.com/hack-rpi/HackRPI-Website-20…
Christian2147 Nov 5, 2024
e093150
removed print statements
Christian2147 Nov 5, 2024
053ef0c
Merge branch 'main' of https://github.com/hack-rpi/HackRPI-Website-20…
CooperW824 Nov 8, 2024
da0e521
security patch
CooperW824 Nov 8, 2024
1f395f6
Prettified Code!
CooperW824 Nov 8, 2024
db7cce1
Merge branch 'main' of https://github.com/hack-rpi/HackRPI-Website-20…
CooperW824 Nov 8, 2024
d877451
Merge branch '2048' of https://github.com/hack-rpi/HackRPI-Website-20…
CooperW824 Nov 8, 2024
a5353cd
better score checking
CooperW824 Nov 8, 2024
aa449fe
everything works now
CooperW824 Nov 8, 2024
46c6e6a
Prettified Code!
CooperW824 Nov 8, 2024
8179af9
put a time block on the 2048 game
CooperW824 Nov 10, 2024
8739d4e
Merge branch '2048' of https://github.com/hack-rpi/HackRPI-Website-20…
CooperW824 Nov 10, 2024
80428ce
Prettified Code!
CooperW824 Nov 9, 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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
},
plugins: ["@typescript-eslint", "react"],
rules: {
indent: ["error", "tab"],
indent: ["warn", "tab"],
quotes: ["error", "double", { allowTemplateLiterals: true }],
semi: ["error", "always"],
},
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.pnp.js
.yarn/install-state.gz


# testing
/coverage

Expand Down
16 changes: 16 additions & 0 deletions amplify/data/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ const schema = a.schema({
allow.guest().to(["read"]),
];
}),

Leaderboard: a
.model({
id: a.id().required(),
username: a.string().required(),
score: a.integer().required().default(0),
year: a.integer().required().default(2024),
})
.secondaryIndexes((index) => [index("year").sortKeys(["score"]).queryField("listByScore")])
.authorization((allow) => {
return [
allow.group("directors").to(["create", "delete", "read"]),
allow.authenticated("identityPool").to(["read", "create"]),
allow.guest().to(["read", "create"]),
];
}),
});

export type Schema = ClientSchema<typeof schema>;
Expand Down
108 changes: 108 additions & 0 deletions app/2048/leaderboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"use client";

import { useState } from "react";
import { useEffect } from "react";
import NavBar from "@/components/nav-bar/nav-bar";
import Footer from "@/components/footer/footer";
import "@/app/globals.css";
import HackRPIButton from "@/components/themed-components/hackrpi-button";
import { get_leaderboard, LeaderboardEntry } from "@/app/actions";
import * as Auth from "@aws-amplify/auth";
import { Amplify } from "aws-amplify";
import amplify_outputs from "@/amplify_outputs.json";
import { generateClient } from "aws-amplify/api";
import { Schema } from "@/amplify/data/resource";

Amplify.configure(amplify_outputs);
const client = generateClient<Schema>({ authMode: "userPool" });

export default function Page() {
const [leaderboardEntries, setLeaderboardEntries] = useState<LeaderboardEntry[]>([]);
const [isDirector, setIsDirector] = useState(false);

const fetchLeaderboard = async () => {
const entries = await get_leaderboard();
setLeaderboardEntries(entries);
};

async function is_director() {
let groups = undefined;
try {
const session = await Auth.fetchAuthSession();
groups = session.tokens?.accessToken.payload["cognito:groups"];
} catch (e) {
console.error(e);
groups = undefined;
}

return groups !== undefined;
}

useEffect(() => {
const setDirectorStatus = async () => {
setIsDirector(await is_director());
};

setDirectorStatus();
fetchLeaderboard();
}, []);

return (
<div className="flex flex-col items-center justify-start w-full h-screen">
<NavBar showOnScroll={false}></NavBar>

<div className="flex-grow flex-shrink basis-auto">
<h1 className="mt-28 text-center text-4xl">2048 Leaderboard</h1>
<table className="min-w-[80vw] mt-10 justify-inbetween table-auto w-full table table-zebra">
<thead>
<tr>
<th className="w-1/4 px-4 py-2 text-center">Position</th>
<th className="w-1/3 px-4 py-2 text-center">Username</th>
<th className="w-1/3 px-4 py-2 text-center">Score</th>
{isDirector ? <th className="w-1/3 px-4 py-2">Delete</th> : null}
</tr>
</thead>

<tbody className="text-center">
{leaderboardEntries.map((entry, index) => (
<tr key={entry.id}>
<td className="px-y py-2">{index + 1}</td>
<td className="px-4 py-2">{entry.username}</td>
<td className="px-4 py-2">{entry.score}</td>
{isDirector ? (
<td className="px-4 py-2 flex items-center justify-center">
<HackRPIButton
onClick={async () => {
await deleteLeaderboardEntry(entry.id);
await fetchLeaderboard();
}}
>
Delete Item
</HackRPIButton>
</td>
) : null}
</tr>
))}
</tbody>
</table>
</div>
<div className="flex-grow mt-24"></div>

<div className="absolute-bottom-0 w-full">
<Footer />
</div>
</div>
);
}

async function deleteLeaderboardEntry(id: string) {
if (!confirm("Are you sure???")) {
return;
}

const response = await client.models.Leaderboard.delete({ id });

if (response.errors) {
alert("Error deleting leaderboard entry");
}
}
Loading