2022-05-04 23:41:04 +03:00
|
|
|
import { MancalaGame } from 'mancala.js';
|
2021-07-04 00:45:00 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
|
import { FunctionComponent } from "react"
|
|
|
|
|
import { context } from '../context';
|
|
|
|
|
|
2021-07-04 01:23:10 +03:00
|
|
|
const InfoPanel: FunctionComponent<{
|
2022-05-04 23:41:04 +03:00
|
|
|
game: MancalaGame,
|
2021-07-04 01:23:10 +03:00
|
|
|
crashMessage: string,
|
|
|
|
|
userKey: string,
|
|
|
|
|
userKeyWhoLeave: string,
|
|
|
|
|
searchingOpponent: boolean
|
|
|
|
|
}> = ({
|
|
|
|
|
game, crashMessage, userKey, userKeyWhoLeave, searchingOpponent }) => {
|
|
|
|
|
if (searchingOpponent) {
|
|
|
|
|
return (
|
|
|
|
|
<h4>{
|
|
|
|
|
context.texts.SearchingOpponent + " " + context.texts.PleaseWait
|
|
|
|
|
}</h4>
|
|
|
|
|
)
|
2021-07-04 01:04:59 +03:00
|
|
|
}
|
|
|
|
|
|
2021-07-04 01:23:10 +03:00
|
|
|
if (crashMessage) {
|
2021-07-04 00:45:00 +03:00
|
|
|
return (
|
|
|
|
|
<h4>{
|
2021-07-04 01:23:10 +03:00
|
|
|
context.texts.GameCrashed + " " + crashMessage
|
2021-07-04 00:45:00 +03:00
|
|
|
}</h4>
|
|
|
|
|
)
|
2021-07-04 01:23:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (userKeyWhoLeave) {
|
|
|
|
|
let message = context.texts.OpponentLeavesTheGame
|
|
|
|
|
|
|
|
|
|
if (userKeyWhoLeave == userKey) {
|
|
|
|
|
message = context.texts.YouLeftTheGame
|
|
|
|
|
}
|
2021-07-04 00:45:00 +03:00
|
|
|
return (
|
2021-07-04 01:23:10 +03:00
|
|
|
<h4>
|
|
|
|
|
{message}
|
|
|
|
|
</h4>
|
2021-07-04 00:45:00 +03:00
|
|
|
)
|
|
|
|
|
}
|
2022-05-04 23:41:04 +03:00
|
|
|
|
2021-07-04 00:45:00 +03:00
|
|
|
|
2021-07-04 01:23:10 +03:00
|
|
|
if (game) {
|
|
|
|
|
if (game.state == "ended") {
|
2022-05-04 23:41:04 +03:00
|
|
|
const wonPlayer = game.getWonPlayerId();
|
|
|
|
|
let whoWon = game.getWonPlayerId() === userKey ? context.texts.YouWon : context.texts.YouLost
|
2021-07-04 01:51:39 +03:00
|
|
|
if(!wonPlayer){
|
|
|
|
|
whoWon = context.texts.GameDraw
|
|
|
|
|
}
|
2021-07-04 01:23:10 +03:00
|
|
|
return (
|
|
|
|
|
<h4>{
|
|
|
|
|
context.texts.GameEnded + " " + whoWon
|
|
|
|
|
}</h4>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
2022-05-04 23:41:04 +03:00
|
|
|
<h4>{game.checkIsPlayerTurn(userKey) ? context.texts.YourTurn : context.texts.OpponentTurn}</h4>
|
2021-07-04 01:23:10 +03:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <h4></h4>
|
|
|
|
|
}
|
2021-07-04 00:45:00 +03:00
|
|
|
|
|
|
|
|
export default InfoPanel
|