Skip to content

Commit 7ccb215

Browse files
authored
Merge pull request #95 from Treevyy/GO-Vic-Connections
Go vic connections
2 parents 2fb2eaa + be22147 commit 7ccb215

File tree

11 files changed

+52
-92
lines changed

11 files changed

+52
-92
lines changed

client/src/components/BackgroundMusic.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,31 @@ const BackgroundMusic: React.FC<Props> = ({ src, volume = 0.03 }) => {
99
const audioRef = useRef<HTMLAudioElement | null>(null);
1010

1111
useEffect(() => {
12+
// Create audio instance if it doesn't exist
1213
if (!audioRef.current) {
1314
audioRef.current = new Audio(src);
1415
audioRef.current.loop = true;
1516
audioRef.current.volume = volume;
1617
}
1718

1819
const audio = audioRef.current;
20+
21+
// Play the audio
1922
audio.play().catch((err) => {
2023
console.warn('⚠️ Autoplay blocked:', err);
2124
});
2225

26+
// Stop the audio when component unmounts (e.g., on Play Again)
2327
return () => {
24-
// Do not pause or destroy the audio here to preserve continuity
28+
if (audio) {
29+
audio.pause();
30+
audio.currentTime = 0;
31+
audioRef.current = null;
32+
}
2533
};
2634
}, [src, volume]);
2735

2836
return null;
2937
};
3038

31-
export default BackgroundMusic;
39+
export default BackgroundMusic;

client/src/components/DanismEvent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useEffect } from "react";
22
import SoundPlayer from "@/components/SoundPlayer";
3-
import { preloadSounds } from "../Utils/preloadSounds";
4-
import { getRandomDanismAndSound } from "../Utils/handleAnswer";
3+
import { preloadSounds } from "../utils/preloadSounds";
4+
import { getRandomDanismAndSound } from "../utils/handleAnswer";
55

66

77
const DanismEvent = () => {

client/src/components/screens/GameMap.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ const GameMap: React.FC = () => {
122122
navigate(`/question/${questionId}`);
123123
};
124124

125+
console.log("selectedAvatar:", selectedAvatar);
125126
return (
126127
<div className="game-map">
127128
<BackgroundMusic src="/black.sabbath.mp3" volume={0.03} />

client/src/components/screens/GameOver.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ import "../../styles/codezilla.css";
33

44

55
const GameOverPage = ({
6-
// backgroundUrl = 'client/background/codezilla_bkgd.png',
7-
avatarUrl = 'client/avatars/avatar4.png',
8-
codezillaUrl = 'client/minions/codezilla2.png',
6+
avatarUrl = '/avatars/michael.png',
7+
codezillaUrl = '/minions/codezilla2.png',
98
}) => {
109
const navigate = useNavigate();
1110

1211
const handlePlayAgain = () => {
13-
// navigate to your game-start route
14-
navigate('/game');
12+
// back to the question map
13+
navigate('/map');
1514
};
1615

1716
const handleMainMenu = () => {
18-
// navigate back to your main menu/home route
17+
// back to your overall main menu/home
1918
navigate('/');
2019
};
2120

@@ -68,4 +67,4 @@ const GameOverPage = ({
6867
);
6968
};
7069

71-
export default GameOverPage;
70+
export default GameOverPage;

client/src/components/screens/Login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "../../styles/codezilla.css";
44
import { useNavigate } from "react-router-dom";
55
import { useMutation } from "@apollo/client";
66
import { LOGIN } from "../../graphql/mutations";
7-
import { useBodyClass } from "../../Utils/useBodyClass";
7+
import { useBodyClass } from "../../utils/useBodyClass";
88

99
export const Login: React.FC = () => {
1010
const navigate = useNavigate();

client/src/components/screens/Questions.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import AnswerResultModal from '../AnswerResultModal';
44
import ReactMarkdown from 'react-markdown';
55
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
66
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
7-
87
import { preloadSounds } from '../../utils/preloadSounds';
9-
108
import BackgroundMusic from '../BackgroundMusic';
119

12-
13-
1410
interface Question {
1511
snippet?: string;
1612
question: string;
@@ -19,7 +15,6 @@ interface Question {
1915
}
2016

2117
const Questions: React.FC = () => {
22-
const [updateStats] = useMutation(UPDATE_STATS);
2318
const { id } = useParams<{ id: string }>();
2419
const navigate = useNavigate();
2520

@@ -30,8 +25,6 @@ const Questions: React.FC = () => {
3025
const [audioUrl, setAudioUrl] = useState('');
3126
const [isReady, setIsReady] = useState(false);
3227

33-
const [score, setScore] = useState(0);
34-
3528
useEffect(() => {
3629
preloadSounds([
3730
'/audio/Dan_correct/Dan-correct-1.wav',
@@ -80,7 +73,7 @@ const Questions: React.FC = () => {
8073
if (data.isFallback && data.question.correctIndex !== undefined) {
8174
const fallback = data.question;
8275
const labeledChoices = fallback.choices.map((choice: string, index: number) => {
83-
const label = String.fromCharCode(65 + index); // "A", "B", "C", ...
76+
const label = String.fromCharCode(65 + index);
8477
return `${label}) ${choice}`;
8578
});
8679
const correctLetter = String.fromCharCode(65 + fallback.correctIndex);
@@ -136,16 +129,26 @@ const Questions: React.FC = () => {
136129
const correctChoice = question.choices[correctIndex]?.slice(3).trim();
137130
const isCorrect = selectedAnswer === correctChoice;
138131

139-
140132
setUserWasCorrect(isCorrect);
141133
setAudioUrl(getRandomAudio(isCorrect));
142134
setShowResult(true);
135+
136+
const questionNumber = Number(id?.replace('q', ''));
137+
138+
setTimeout(() => {
139+
if (questionNumber === 5) {
140+
if (isCorrect) {
141+
navigate('/victory');
142+
} else {
143+
navigate('/gameover');
144+
}
145+
}
146+
}, 6000);
143147
};
144148

145149
const handleBack = () => navigate('/map');
146150

147151
return (
148-
149152
<div
150153
className="min-h-screen bg-cover bg-center bg-no-repeat"
151154
style={{ backgroundImage: 'url("/background/codezilla_bkgd.png")' }}
@@ -189,7 +192,6 @@ const Questions: React.FC = () => {
189192
</pre>
190193
);
191194
},
192-
193195
}}
194196
>
195197
{question.question}
@@ -198,7 +200,7 @@ const Questions: React.FC = () => {
198200

199201
<div className="text-left flex flex-col items-start gap-2 text-white">
200202
{question.choices.map((choice, index) => {
201-
const value = choice.slice(3).trim(); // remove "A) " etc.
203+
const value = choice.slice(3).trim();
202204
return (
203205
<label key={index} className="flex items-center gap-2 cursor-pointer">
204206
<input
@@ -248,4 +250,4 @@ const Questions: React.FC = () => {
248250
);
249251
};
250252

251-
export default Questions;
253+
export default Questions;

client/src/components/screens/Signup.tsx

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ const avatarList = [
2323
"/avatars/shawna.png",
2424
];
2525

26-
// Utility hook to set a class on the body element
27-
const useBodyClass = (className: string) => {
28-
React.useEffect(() => {
29-
document.body.classList.add(className);
30-
return () => {
31-
document.body.classList.remove(className);
32-
};
33-
}, [className]);
34-
};
35-
3626
const SignUp: React.FC = () => {
3727
useBodyClass('signup-background');
3828
const navigate = useNavigate();
@@ -128,44 +118,12 @@ const SignUp: React.FC = () => {
128118
))}
129119
</div>
130120
</div>
131-
132-
<button className="signup-button" type="submit">Enter the Game</button>
133-
<p>Select Your Avatar</p>
134-
<div className="avatar-grid">
135-
<div className="avatar-row">
136-
{avatarList.slice(0, 3).map((avatar, index) => (
137-
<img
138-
key={index}
139-
src={avatar}
140-
alt={`Avatar ${index}`}
141-
className={`avatar-option ${
142-
selectedAvatar === avatar ? "selected" : ""
143-
}`}
144-
onClick={() => setSelectedAvatar(avatar)}
145-
/>
146-
))}
147-
</div>
148-
<div className="avatar-row">
149-
{avatarList.slice(3).map((avatar, index) => (
150-
<img
151-
key={index + 3}
152-
src={avatar}
153-
alt={`Avatar ${index + 3}`}
154-
className={`avatar-option ${
155-
selectedAvatar === avatar ? "selected" : ""
156-
}`}
157-
onClick={() => setSelectedAvatar(avatar)}
158-
/>
159-
))}
160-
</div>
161-
</div>
162-
163-
<button className="signup-button" type="submit">
164-
Enter the Game
165-
</button>
121+
<button type="submit" className="login-button">Sign Up</button>
166122
</form>
167123
</div>
168124
);
169125
};
170126

171-
export default SignUp;
127+
128+
129+
export default SignUp;

client/src/components/screens/Victory.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
// src/pages/VictoryPage.tsx
12
import { useNavigate } from 'react-router-dom';
23
import "../../styles/codezilla.css";
34

45
export default function VictoryPage({
5-
// backgroundUrl = 'client/background/codezilla_bkgd.png',
6-
avatarUrl = 'client/avatars/avatar4.png',
7-
confettiUrl = 'client/background/confetti_image.jpg',
6+
avatarUrl = '/avatars/michael.png',
7+
confettiUrl = '/background/confetti_image.jpg',
88
}) {
99
const navigate = useNavigate();
1010

1111
const handlePlayAgain = () => {
12-
navigate('/game');
12+
navigate('/map'); // ← back to your question map
1313
};
1414

1515
const handleMainMenu = () => {
16-
navigate('/');
16+
navigate('/'); // ← back to your main menu/home
1717
};
1818

1919
return (

client/src/components/ui/dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as React from "react";
44
import * as DialogPrimitive from "@radix-ui/react-dialog";
5-
import { cn } from "@/Utils/utils";
5+
import { cn } from "@/utils/utils";
66

77
// Root dialog elements
88
const Dialog = DialogPrimitive.Root;

client/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client';
33
import App from './App';
44
import './index.css';
55
import { ApolloProvider } from '@apollo/client';
6-
import client from './Utils/apolloClient'; // or wherever your client file is
6+
import client from './utils/apolloClient'; // or wherever your client file is
77

88
ReactDOM.createRoot(document.getElementById('root')!).render(
99
<React.StrictMode>

0 commit comments

Comments
 (0)