Merge pull request #8 from jhalitaksoy/feature/info-panel
Feature/info panel
This commit is contained in:
commit
3d50ee8697
@ -214,7 +214,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
|
|||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
padding: "0px 50px",
|
padding: "0px 4vw",
|
||||||
background: "rgb(228, 228, 228)",
|
background: "rgb(228, 228, 228)",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
@ -239,6 +239,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
|
context={context}
|
||||||
game={game}
|
game={game}
|
||||||
crashMessage={crashMessage}
|
crashMessage={crashMessage}
|
||||||
userKey={userKey}
|
userKey={userKey}
|
||||||
|
|||||||
@ -150,16 +150,14 @@ const BoardView: FunctionComponent<{
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
margin: "10px",
|
margin: "1vw",
|
||||||
padding: "20px",
|
padding: "2vw",
|
||||||
display: "grid",
|
display: "grid",
|
||||||
gridTemplateColumns: "repeat(8, 11vw)",
|
gridTemplateColumns: "repeat(8, 11vw)",
|
||||||
gridTemplateRows: "repeat(2, 11vw)",
|
gridTemplateRows: "repeat(2, 11vw)",
|
||||||
borderRadius: "3vw",
|
borderRadius: "3vw",
|
||||||
transition: "background-color 0.5s",
|
transition: "background-color 0.5s",
|
||||||
background: isUserTurn
|
background: theme.boardColor,
|
||||||
? theme.boardColor
|
|
||||||
: theme.boardColorWhenPlayerTurn,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{userKey === game.player2Id ? (
|
{userKey === game.player2Id ? (
|
||||||
|
|||||||
@ -1,22 +1,26 @@
|
|||||||
import * as React from 'react';
|
import * as React from "react";
|
||||||
import { FunctionComponent } 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 (
|
||||||
<button
|
<button
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
style={{
|
style={{
|
||||||
background: color,
|
background: color,
|
||||||
color : "white",
|
color: "white",
|
||||||
margin: "5px",
|
margin: "5px",
|
||||||
padding: "10px",
|
padding: "10px",
|
||||||
border : "none",
|
border: "none",
|
||||||
borderRadius: "3vw",
|
borderRadius: "4vw",
|
||||||
}} >
|
}}
|
||||||
|
>
|
||||||
{text}
|
{text}
|
||||||
</button>
|
</button>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default Button
|
export default Button;
|
||||||
|
|||||||
@ -1,66 +1,107 @@
|
|||||||
import { MancalaGame } from 'mancala.js';
|
import { MancalaGame } from "mancala.js";
|
||||||
import * as React from 'react';
|
import * as React from "react";
|
||||||
import { FunctionComponent } from "react"
|
import { FunctionComponent } from "react";
|
||||||
import { context } from '../context';
|
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 (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
background: props.color,
|
||||||
|
padding: "1vw 2vw",
|
||||||
|
marginTop: "1vw",
|
||||||
|
borderRadius: "10vw",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const InfoPanel: FunctionComponent<{
|
const InfoPanel: FunctionComponent<{
|
||||||
game: MancalaGame,
|
context: Context;
|
||||||
crashMessage: string,
|
game: MancalaGame;
|
||||||
userKey: string,
|
crashMessage: string;
|
||||||
userKeyWhoLeave: string,
|
userKey: string;
|
||||||
searchingOpponent: boolean
|
userKeyWhoLeave: string;
|
||||||
|
searchingOpponent: boolean;
|
||||||
}> = ({
|
}> = ({
|
||||||
game, crashMessage, userKey, userKeyWhoLeave, searchingOpponent }) => {
|
context,
|
||||||
if (searchingOpponent) {
|
game,
|
||||||
|
crashMessage,
|
||||||
|
userKey,
|
||||||
|
userKeyWhoLeave,
|
||||||
|
searchingOpponent,
|
||||||
|
}) => {
|
||||||
|
const isUserTurn = game?.checkIsPlayerTurn(userKey);
|
||||||
return (
|
return (
|
||||||
<h4>{
|
<InfoPanelContainer
|
||||||
context.texts.SearchingOpponent + " " + context.texts.PleaseWait
|
context={context}
|
||||||
}</h4>
|
color={
|
||||||
)
|
isUserTurn
|
||||||
|
? context.themeManager.theme.playerTurnColor
|
||||||
|
: context.themeManager.theme.holeColor
|
||||||
}
|
}
|
||||||
|
>
|
||||||
if (crashMessage) {
|
<h4 style={{ margin: "0" }}>
|
||||||
return (
|
{getInfoPanelTextByGameState({
|
||||||
<h4>{
|
context,
|
||||||
context.texts.GameCrashed + " " + crashMessage
|
game,
|
||||||
}</h4>
|
crashMessage,
|
||||||
)
|
userKey,
|
||||||
}
|
userKeyWhoLeave,
|
||||||
|
searchingOpponent,
|
||||||
if (userKeyWhoLeave) {
|
})}
|
||||||
let message = context.texts.OpponentLeavesTheGame
|
|
||||||
|
|
||||||
if (userKeyWhoLeave == userKey) {
|
|
||||||
message = context.texts.YouLeftTheGame
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<h4>
|
|
||||||
{message}
|
|
||||||
</h4>
|
</h4>
|
||||||
)
|
</InfoPanelContainer>
|
||||||
}
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InfoPanel;
|
||||||
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 (
|
|
||||||
<h4>{
|
|
||||||
context.texts.GameEnded + " " + whoWon
|
|
||||||
}</h4>
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<h4>{game.checkIsPlayerTurn(userKey) ? context.texts.YourTurn : context.texts.OpponentTurn}</h4>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return <h4></h4>
|
|
||||||
}
|
|
||||||
|
|
||||||
export default InfoPanel
|
|
||||||
|
|||||||
@ -3,9 +3,8 @@ import { Theme } from "./Theme";
|
|||||||
const defaultTheme: Theme = {
|
const defaultTheme: Theme = {
|
||||||
background: "#EEEEEE",
|
background: "#EEEEEE",
|
||||||
boardColor: "#4D606E",
|
boardColor: "#4D606E",
|
||||||
boardColorWhenPlayerTurn: "#84b8a6",
|
playerTurnColor: "#84b8a6",
|
||||||
storeColor: "#3FBAC2",
|
storeColor: "#3FBAC2",
|
||||||
storeColorWhenPlayerTurn: "#6cab94",
|
|
||||||
holeColor: "#D3D4D8",
|
holeColor: "#D3D4D8",
|
||||||
pitSelectedColor: "#8837fa",
|
pitSelectedColor: "#8837fa",
|
||||||
ballColor: "#393E46",
|
ballColor: "#393E46",
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
export type Theme = {
|
export type Theme = {
|
||||||
background: string;
|
background: string;
|
||||||
boardColor: string;
|
boardColor: string;
|
||||||
boardColorWhenPlayerTurn: string;
|
playerTurnColor: string;
|
||||||
storeColor: string;
|
storeColor: string;
|
||||||
storeColorWhenPlayerTurn: string;
|
|
||||||
holeColor: string;
|
holeColor: string;
|
||||||
pitSelectedColor: string;
|
pitSelectedColor: string;
|
||||||
ballColor: string;
|
ballColor: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user