Skip to content

Commit b16af88

Browse files
authored
Adding changes to Frontend visual + GuessRandomNumberGame (#18)
* adding nice visual to fhewordle * feat: add fhewordle mock to the frontend * change sample * adding a guess random number game to the hardhat examples * adding guess random number game
1 parent 154b351 commit b16af88

File tree

25 files changed

+43056
-13484
lines changed

25 files changed

+43056
-13484
lines changed

frontend-visual/app/dapps/[slug]/page.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import Header from '@/components/Header'
2-
import Link from 'next/link'
3-
import Image from 'next/image'
1+
"use client";
2+
3+
import Header from "@/components/Header";
4+
import Link from "next/link";
5+
import Image from "next/image";
46

57
export default function DAppPage({ params }: { params: { slug: string } }) {
6-
const dAppTitle = params.slug.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ')
8+
const dAppTitle = params.slug
9+
.split("-")
10+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
11+
.join(" ");
712

813
return (
914
<>
@@ -14,9 +19,12 @@ export default function DAppPage({ params }: { params: { slug: string } }) {
1419
</Link>
1520
<div className="w-full max-w-2xl mx-auto mt-8">
1621
<div className="bg-white shadow-[6px_6px_0_0_rgba(0,0,0,1)] p-8 relative overflow-hidden">
17-
<h1 className="text-4xl font-bold mb-4 text-gray-800 font-telegraf relative z-10">{dAppTitle}</h1>
22+
<h1 className="text-4xl font-bold mb-4 text-gray-800 font-telegraf relative z-10">
23+
{dAppTitle}
24+
</h1>
1825
<p className="text-gray-600 relative z-10">
19-
This is the page for the {dAppTitle} dApp. More details and functionality can be added here.
26+
This is the page for the {dAppTitle} dApp. More details and
27+
functionality can be added here.
2028
</p>
2129
</div>
2230
</div>
@@ -25,6 +33,5 @@ export default function DAppPage({ params }: { params: { slug: string } }) {
2533
<p>&copy; 2023 Zama dApps. All rights reserved.</p>
2634
</footer>
2735
</>
28-
)
36+
);
2937
}
30-
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use client";
2+
3+
import Header from "@/components/Header";
4+
import Link from "next/link";
5+
import Image from "next/image";
6+
import WordleGame from "@/components/fheWordle/WordleGame";
7+
8+
export default function DAppPage() {
9+
return (
10+
<>
11+
<Header />
12+
<main className="flex-grow container mx-auto px-4 py-16">
13+
<Link href="/" className="text-black hover:underline mb-4 inline-block">
14+
&larr; Back to dApps
15+
</Link>
16+
<div className="w-full max-w-2xl mx-auto mt-8">
17+
<div className="bg-white shadow-[6px_6px_0_0_rgba(0,0,0,1)] p-8 relative overflow-hidden">
18+
<h1 className="text-4xl font-bold mb-4 text-gray-800 font-telegraf relative z-10">
19+
FHEWordle
20+
</h1>
21+
<p className="text-gray-600 relative z-10">
22+
FHEWordle is a privacy-preserving version of the popular word game
23+
Wordle, powered by Fully Homomorphic Encryption (FHE). In this
24+
game, your guesses and the target word remain encrypted at all
25+
times, ensuring complete privacy while still allowing you to play
26+
the classic word-guessing game. Try to guess the 5-letter word in
27+
6 attempts or less!
28+
</p>
29+
<WordleGame />
30+
</div>
31+
</div>
32+
</main>
33+
<footer className="bg-yellow-400 py-6 text-center text-gray-800">
34+
<p>&copy; 2023 Zama dApps. All rights reserved.</p>
35+
</footer>
36+
</>
37+
);
38+
}

frontend-visual/app/page.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import Header from '@/components/Header'
2-
import DAppCard from '@/components/DAppCard'
1+
import Header from "@/components/Header";
2+
import DAppCard from "@/components/DAppCard";
33

44
const dApps = [
5-
{ title: 'EIP-712', slug: 'eip-712' },
6-
{ title: 'ERC-20', slug: 'erc-20' },
7-
{ title: 'Blind auction', slug: 'blind-auction' },
8-
]
5+
{ title: "EIP-712", slug: "eip-712" },
6+
{ title: "ERC-20", slug: "erc-20" },
7+
{ title: "Blind auction", slug: "blind-auction" },
8+
{ title: "FHEWordle", slug: "wordle" },
9+
];
910

1011
export default function Home() {
1112
return (
1213
<>
1314
<Header />
1415
<main className="flex-grow container mx-auto px-4 py-16">
1516
<h1 className="text-5xl font-bold mb-16 text-center text-gray-800 font-telegraf-bold">
16-
Explore <span className="font-telegraf-light">Decentralized Applications</span>
17+
Explore{" "}
18+
<span className="font-telegraf-light">
19+
Decentralized Applications
20+
</span>
1721
</h1>
1822
<div className="max-w-screen-lg mx-auto grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-16 justify-items-center">
1923
{dApps.map((dApp) => (
@@ -25,6 +29,5 @@ export default function Home() {
2529
<p>&copy; 2024 Zama dApps. All rights reserved.</p>
2630
</footer>
2731
</>
28-
)
32+
);
2933
}
30-
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { useState, useEffect } from "react";
2+
import { Button } from "@/components/ui/button";
3+
import { Input } from "@/components/ui/input";
4+
import { AlertCircle } from "lucide-react";
5+
import { VALID_WORDS } from "./validWordsList";
6+
7+
const WORD_LENGTH = 5;
8+
const MAX_GUESSES = 6;
9+
const WORDS = VALID_WORDS.map((word) => word.toUpperCase());
10+
11+
export default function WordleGame() {
12+
const [targetWord, setTargetWord] = useState("");
13+
const [currentGuess, setCurrentGuess] = useState("");
14+
const [guesses, setGuesses] = useState<string[]>([]);
15+
const [feedback, setFeedback] = useState<string[][]>([]);
16+
const [gameOver, setGameOver] = useState(false);
17+
const [message, setMessage] = useState("");
18+
19+
useEffect(() => {
20+
setTargetWord(WORDS[Math.floor(Math.random() * WORDS.length)]);
21+
}, []);
22+
23+
const handleGuess = () => {
24+
if (currentGuess.length !== WORD_LENGTH) {
25+
setMessage("Please enter a 5-letter word");
26+
return;
27+
}
28+
29+
if (!WORDS.includes(currentGuess)) {
30+
setMessage("Not a valid word");
31+
return;
32+
}
33+
34+
const newFeedback = currentGuess.split("").map((letter, index) => {
35+
if (letter === targetWord[index]) return "correct";
36+
if (targetWord.includes(letter)) return "present";
37+
return "absent";
38+
});
39+
40+
setGuesses([...guesses, currentGuess]);
41+
setFeedback([...feedback, newFeedback]);
42+
setCurrentGuess("");
43+
setMessage("");
44+
45+
if (currentGuess === targetWord) {
46+
setGameOver(true);
47+
setMessage("Congratulations! You guessed the word!");
48+
} else if (guesses.length + 1 === MAX_GUESSES) {
49+
setGameOver(true);
50+
setMessage(`Game over! The word was ${targetWord}`);
51+
}
52+
};
53+
54+
const renderGuess = (guess: string, feedbackRow: string[]) => {
55+
return guess.split("").map((letter, index) => (
56+
<div
57+
key={index}
58+
className={`w-12 h-12 border-2 flex items-center justify-center text-2xl font-bold
59+
${
60+
feedbackRow[index] === "correct"
61+
? "bg-green-500 border-green-600"
62+
: feedbackRow[index] === "present"
63+
? "bg-yellow-500 border-yellow-600"
64+
: "bg-gray-300 border-gray-400"
65+
}`}
66+
>
67+
{letter}
68+
</div>
69+
));
70+
};
71+
72+
return (
73+
<div className="flex flex-col items-center justify-center">
74+
<div className="space-y-2 mt-4 mb-4">
75+
{guesses.map((guess, i) => (
76+
<div key={i} className="flex space-x-2">
77+
{renderGuess(guess, feedback[i])}
78+
</div>
79+
))}
80+
</div>
81+
{!gameOver && (
82+
<div className="flex space-x-2 mb-4">
83+
<Input
84+
type="text"
85+
value={currentGuess}
86+
onChange={(e) => setCurrentGuess(e.target.value.toUpperCase())}
87+
maxLength={WORD_LENGTH}
88+
className="w-40 text-center text-2xl uppercase"
89+
disabled={gameOver}
90+
/>
91+
<Button onClick={handleGuess} disabled={gameOver}>
92+
Guess
93+
</Button>
94+
</div>
95+
)}
96+
{message && (
97+
<div className="flex items-center space-x-2 text-red-500">
98+
<AlertCircle className="h-5 w-5" />
99+
<span>{message}</span>
100+
</div>
101+
)}
102+
</div>
103+
);
104+
}

0 commit comments

Comments
 (0)