diff --git a/src/App.tsx b/src/App.tsx
index fa7d5ef..9a957ce 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -3,16 +3,26 @@ import { ReactNode, useEffect, useState } from 'react';
import { init } from './fhevmjs';
import { Connect, Layout } from './modules/common-ui';
+import { pauseMusic, playMusic } from './utils/music';
import './App.css';
type AppProps = {
+ music?: boolean;
children: (account: string, provider: BrowserProvider) => ReactNode;
};
-const App = ({ children }: AppProps) => {
+const App = ({ music = false, children }: AppProps) => {
const [isInitialized, setIsInitialized] = useState(false);
+ useEffect(() => {
+ if (music) {
+ playMusic();
+ } else {
+ pauseMusic();
+ }
+ }, [music]);
+
useEffect(() => {
init()
.then(() => {
diff --git a/src/assets/music.mp3 b/src/assets/music.mp3
new file mode 100644
index 0000000..274d0a4
Binary files /dev/null and b/src/assets/music.mp3 differ
diff --git a/src/main.tsx b/src/main.tsx
index da9d0a2..25cc992 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -14,7 +14,7 @@ const router = createHashRouter([
path: '/',
element: (
- {(account, provider) => }
+ {(account, provider) => }
),
},
@@ -22,7 +22,7 @@ const router = createHashRouter([
path: 'rules',
element: (
- {(account, provider) => }
+ {(account, provider) => }
),
},
@@ -30,7 +30,7 @@ const router = createHashRouter([
path: 'join',
element: (
- {(account, provider) => }
+ {(account, provider) => }
),
},
diff --git a/src/modules/common-ui/components/Back/Back.tsx b/src/modules/common-ui/components/Back/Back.tsx
index 0c697fb..b34a586 100644
--- a/src/modules/common-ui/components/Back/Back.tsx
+++ b/src/modules/common-ui/components/Back/Back.tsx
@@ -1,9 +1,11 @@
+import { Link } from 'react-router-dom';
+
import './Back.css';
export const Back = () => {
return (
-
+
⬅ Back to the main menu
-
+
);
};
diff --git a/src/modules/game/assets/badguyswin.mp3 b/src/modules/game/assets/badguyswin.mp3
new file mode 100644
index 0000000..75cbf61
Binary files /dev/null and b/src/modules/game/assets/badguyswin.mp3 differ
diff --git a/src/modules/game/assets/card.mp3 b/src/modules/game/assets/card.mp3
new file mode 100644
index 0000000..2e19b81
Binary files /dev/null and b/src/modules/game/assets/card.mp3 differ
diff --git a/src/modules/game/assets/good_guys_win.mp3 b/src/modules/game/assets/goodguyswin.mp3
similarity index 100%
rename from src/modules/game/assets/good_guys_win.mp3
rename to src/modules/game/assets/goodguyswin.mp3
diff --git a/src/modules/game/components/Game/Game.tsx b/src/modules/game/components/Game/Game.tsx
index 50cb594..6a06a4b 100644
--- a/src/modules/game/components/Game/Game.tsx
+++ b/src/modules/game/components/Game/Game.tsx
@@ -5,8 +5,9 @@ import { useParams } from 'react-router-dom';
import { abi } from '../../../../abi/cipherbomb.json';
import { getEventContract, getReadContract, onNextBlock } from '../../../../utils/rpc';
import { Splash } from '../../../common-ui/components/Splash';
+import badGuysWin from '../../assets/badguyswin.mp3';
import begin from '../../assets/begin.mp3';
-import goodGuysWin from '../../assets/good_guys_win.mp3';
+import goodGuysWin from '../../assets/goodguyswin.mp3';
import { Table } from '../Table';
import { WaitingRoom } from '../WaitingRoom';
@@ -111,6 +112,7 @@ export const Game = ({ account, provider }: GameProps) => {
};
const onBadGuysWin = (reason: string) => {
+ void new Audio(badGuysWin).play();
setEndGame(reason === 'bomb' ? 'bomb' : 'bad');
onNextBlock(refreshInformations);
onNextBlock(refreshPlayers);
diff --git a/src/modules/game/components/Table/Table.tsx b/src/modules/game/components/Table/Table.tsx
index 617787d..025cf03 100644
--- a/src/modules/game/components/Table/Table.tsx
+++ b/src/modules/game/components/Table/Table.tsx
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useState } from 'react';
import { getInstance, getTokenSignature } from '../../../../fhevmjs';
import { getEventContract, getReadContract, onNextBlock } from '../../../../utils/rpc';
import { Button, Loader, Subtitle, Title } from '../../../common-ui';
+import card from '../../assets/card.mp3';
import { CardDisplay } from '../CardDisplay';
import { TablePlayers } from '../TablePlayers';
@@ -57,7 +58,7 @@ export const Table = ({ contract, account, players }: TableProps) => {
useEffect(() => {
const onCardPicked = (cp: number) => {
- console.log('picked', cp);
+ void new Audio(card).play();
setCardPicked(Number(cp));
setCardOpen(true);
onNextBlock(refresh);
@@ -81,6 +82,7 @@ export const Table = ({ contract, account, players }: TableProps) => {
const instance = getInstance(account);
const onRole = async () => {
+ void new Audio(card).play();
if (role == null) {
const contractAddress = await contract.getAddress();
const token = await getTokenSignature(contractAddress, account);
diff --git a/src/modules/home/components/Home/Home.tsx b/src/modules/home/components/Home/Home.tsx
index d57dd2f..fe56102 100644
--- a/src/modules/home/components/Home/Home.tsx
+++ b/src/modules/home/components/Home/Home.tsx
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import { BrowserProvider, ContractFactory } from 'ethers';
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import cipherbomb from '../../../../abi/cipherbomb.json';
@@ -16,6 +16,7 @@ type HomeProps = {
export const Home = ({ account, provider }: HomeProps) => {
const [createLoading, setCreateLoading] = useState(false);
const navigate = useNavigate();
+
const createARoom = async () => {
if (createLoading) return;
const contractFactory = new ContractFactory(cipherbomb.abi, cipherbomb.bytecode, await provider.getSigner());
diff --git a/src/utils/music.ts b/src/utils/music.ts
new file mode 100644
index 0000000..809e241
--- /dev/null
+++ b/src/utils/music.ts
@@ -0,0 +1,13 @@
+import music from '../assets/music.mp3';
+
+const musicAudio = new Audio(music);
+musicAudio.loop = true;
+musicAudio.volume = 0.5;
+
+export const playMusic = () => {
+ void musicAudio.play();
+};
+
+export const pauseMusic = () => {
+ void musicAudio.pause();
+};