diff --git a/src/Home.tsx b/src/Home.tsx
index f4b1156..0cd55d9 100644
--- a/src/Home.tsx
+++ b/src/Home.tsx
@@ -214,7 +214,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
)}
= ({ initial = 0 }) => {
{userKey === game.player2Id ? (
diff --git a/src/components/Button.tsx b/src/components/Button.tsx
index bfe897b..6a2c361 100644
--- a/src/components/Button.tsx
+++ b/src/components/Button.tsx
@@ -1,22 +1,26 @@
-import * as React from 'react';
-import { FunctionComponent } from "react"
+import * as React from "react";
+import { FunctionComponent } from "react";
-const Button: FunctionComponent<{ text: String,onClick: () => void, color: string }> = ({ text, color, onClick }) => {
+const Button: FunctionComponent<{
+ text: String;
+ onClick: () => void;
+ color: string;
+}> = ({ text, color, onClick }) => {
+ return (
+
+ );
+};
- return (
-
- )
-}
-
-export default Button
\ No newline at end of file
+export default Button;
diff --git a/src/components/InfoPanel.tsx b/src/components/InfoPanel.tsx
index 6825317..a4f6e0d 100644
--- a/src/components/InfoPanel.tsx
+++ b/src/components/InfoPanel.tsx
@@ -1,66 +1,107 @@
-import { MancalaGame } from 'mancala.js';
-import * as React from 'react';
-import { FunctionComponent } from "react"
-import { context } from '../context';
+import { MancalaGame } from "mancala.js";
+import * as React from "react";
+import { FunctionComponent } from "react";
+import { Context } from "../context";
+
+function getInfoPanelTextByGameState(params: {
+ context: Context;
+ game: MancalaGame;
+ crashMessage: string;
+ userKey: string;
+ userKeyWhoLeave: string;
+ searchingOpponent: boolean;
+}): string {
+ const {
+ context,
+ game,
+ crashMessage,
+ userKey,
+ userKeyWhoLeave,
+ searchingOpponent,
+ } = params;
+ if (searchingOpponent) {
+ return context.texts.SearchingOpponent + " " + context.texts.PleaseWait;
+ } else if (crashMessage) {
+ return context.texts.GameCrashed + " " + crashMessage;
+ } else if (userKeyWhoLeave) {
+ let message = context.texts.OpponentLeavesTheGame;
+ if (userKeyWhoLeave == userKey) {
+ message = context.texts.YouLeftTheGame;
+ }
+ return message;
+ } else if (game?.state == "ended") {
+ const wonPlayer = game.getWonPlayerId();
+ let whoWon =
+ game.getWonPlayerId() === userKey
+ ? context.texts.YouWon
+ : context.texts.YouLost;
+ if (!wonPlayer) {
+ whoWon = context.texts.GameDraw;
+ }
+ return context.texts.GameEnded + " " + whoWon;
+ } else {
+ return game?.checkIsPlayerTurn(userKey)
+ ? context.texts.YourTurn
+ : context.texts.OpponentTurn;
+ }
+ return undefined;
+}
+
+const InfoPanelContainer: FunctionComponent<{
+ context: Context;
+ color: string;
+}> = (props) => {
+ return (
+
+ {props.children}
+
+ );
+};
const InfoPanel: FunctionComponent<{
- game: MancalaGame,
- crashMessage: string,
- userKey: string,
- userKeyWhoLeave: string,
- searchingOpponent: boolean
+ context: Context;
+ game: MancalaGame;
+ crashMessage: string;
+ userKey: string;
+ userKeyWhoLeave: string;
+ searchingOpponent: boolean;
}> = ({
- game, crashMessage, userKey, userKeyWhoLeave, searchingOpponent }) => {
- if (searchingOpponent) {
- return (
- {
- context.texts.SearchingOpponent + " " + context.texts.PleaseWait
- }
- )
- }
+ context,
+ game,
+ crashMessage,
+ userKey,
+ userKeyWhoLeave,
+ searchingOpponent,
+}) => {
+ const isUserTurn = game?.checkIsPlayerTurn(userKey);
+ return (
+
+
+ {getInfoPanelTextByGameState({
+ context,
+ game,
+ crashMessage,
+ userKey,
+ userKeyWhoLeave,
+ searchingOpponent,
+ })}
+
+
+ );
+};
- if (crashMessage) {
- return (
- {
- context.texts.GameCrashed + " " + crashMessage
- }
- )
- }
-
- if (userKeyWhoLeave) {
- let message = context.texts.OpponentLeavesTheGame
-
- if (userKeyWhoLeave == userKey) {
- message = context.texts.YouLeftTheGame
- }
- return (
-
- {message}
-
- )
- }
-
-
- if (game) {
- if (game.state == "ended") {
- const wonPlayer = game.getWonPlayerId();
- let whoWon = game.getWonPlayerId() === userKey ? context.texts.YouWon : context.texts.YouLost
- if(!wonPlayer){
- whoWon = context.texts.GameDraw
- }
- return (
- {
- context.texts.GameEnded + " " + whoWon
- }
- )
- } else {
- return (
- {game.checkIsPlayerTurn(userKey) ? context.texts.YourTurn : context.texts.OpponentTurn}
- )
- }
- }
-
- return
- }
-
-export default InfoPanel
\ No newline at end of file
+export default InfoPanel;
diff --git a/src/theme/DefaultTheme.ts b/src/theme/DefaultTheme.ts
index e6fe2ae..e778a06 100644
--- a/src/theme/DefaultTheme.ts
+++ b/src/theme/DefaultTheme.ts
@@ -3,9 +3,8 @@ import { Theme } from "./Theme";
const defaultTheme: Theme = {
background: "#EEEEEE",
boardColor: "#4D606E",
- boardColorWhenPlayerTurn: "#84b8a6",
+ playerTurnColor: "#84b8a6",
storeColor: "#3FBAC2",
- storeColorWhenPlayerTurn: "#6cab94",
holeColor: "#D3D4D8",
pitSelectedColor: "#8837fa",
ballColor: "#393E46",
diff --git a/src/theme/Theme.ts b/src/theme/Theme.ts
index 8027648..c950a43 100644
--- a/src/theme/Theme.ts
+++ b/src/theme/Theme.ts
@@ -1,9 +1,8 @@
export type Theme = {
background: string;
boardColor: string;
- boardColorWhenPlayerTurn: string;
+ playerTurnColor: string;
storeColor: string;
- storeColorWhenPlayerTurn: string;
holeColor: string;
pitSelectedColor: string;
ballColor: string;