mancala/src/components/InfoPanel.tsx

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-07-04 00:45:00 +03:00
import * as React from 'react';
import { FunctionComponent } from "react"
import { context } from '../context';
import { Game } from '../mancala';
2021-07-04 01:23:10 +03:00
const InfoPanel: FunctionComponent<{
game: Game,
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: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
)
}
2021-07-04 01:23:10 +03:00
if (game) {
if (game.state == "ended") {
const whoWon = game.getWonPlayer() == userKey ? context.texts.YouWon : context.texts.YouLost
return (
<h4>{
context.texts.GameEnded + " " + whoWon
}</h4>
)
} else {
return (
<h4>{game.checkGameTurn(userKey) ? context.texts.YourTurn : context.texts.OpponentTurn}</h4>
)
}
}
return <h4></h4>
}
2021-07-04 00:45:00 +03:00
export default InfoPanel