added who won text

This commit is contained in:
jhalitaksoy 2021-07-04 01:51:39 +03:00
parent 39d4e138a9
commit c8e354c159
4 changed files with 19 additions and 12 deletions

View File

@ -171,7 +171,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
minWidth: "10vw",
minHeight: "1vw",
background: "#2F2504",
color : "white",
color: "white",
}}>
{connectionStateText()}
</div>}
@ -187,7 +187,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
<h1 style={{ margin: "10px 0px" }}>{context.texts.Mancala}</h1>
<div>
{renderNewGameButton()}
{game && !userKeyWhoLeave && !crashMessage && < Button color="#005f73" text={context.texts.Leave} onClick={leaveGame} />}
{game && !userKeyWhoLeave && !crashMessage && game?.state == "playing" && < Button color="#005f73" text={context.texts.Leave} onClick={leaveGame} />}
</div>
</div>

View File

@ -42,7 +42,11 @@ const InfoPanel: FunctionComponent<{
if (game) {
if (game.state == "ended") {
const whoWon = game.getWonPlayer() == userKey ? context.texts.YouWon : context.texts.YouLost
const wonPlayer = game.getWonPlayer()
let whoWon = game.getWonPlayer() == userKey ? context.texts.YouWon : context.texts.YouLost
if(!wonPlayer){
whoWon = context.texts.GameDraw
}
return (
<h4>{
context.texts.GameEnded + " " + whoWon

View File

@ -19,7 +19,8 @@ export type Texts = {
OpponentLeavesTheGame: string,
YouLeftTheGame: string,
SearchingOpponent: string,
PleaseWait : string
PleaseWait : string,
GameDraw : string
}
export const EnUs: Texts = {
@ -42,7 +43,8 @@ export const EnUs: Texts = {
OpponentLeavesTheGame: "Opponent Leaves The Game",
YouLeftTheGame: "You Left The Game",
SearchingOpponent: "Searching Opponent",
PleaseWait : "Please Wait"
PleaseWait : "Please Wait",
GameDraw : "Draw"
}
export const TrTr: Texts = {
@ -65,5 +67,6 @@ export const TrTr: Texts = {
OpponentLeavesTheGame: "Rakip Oyundan Ayrıldı",
YouLeftTheGame: "Sen Oyundan Ayrıldın",
SearchingOpponent: "Rakip Aranıyor",
PleaseWait: "Lütfen Bekleyin"
PleaseWait: "Lütfen Bekleyin",
GameDraw : "Berabere"
}

View File

@ -128,10 +128,10 @@ export class Game {
//todo throw expection
public getPlayerKeyByName(key: "player1" | "player2"): string {
if (this.player1 == key) {
return "player1"
if (key == "player1") {
return this.player1
} else {
return "player2"
return this.player2
}
}
@ -142,11 +142,11 @@ export class Game {
public getWonPlayer() : string | undefined {
const player1BallCount = this.board.player1Store.ballCount
const player2BallCount = this.board.player2Store.ballCount
if(player1BallCount < player2BallCount){
return this.getPlayerKeyByName("player1")
}else if(player1BallCount > player2BallCount) {
return this.getPlayerKeyByName("player2")
}else if(player1BallCount > player2BallCount) {
return this.getPlayerKeyByName("player1")
}else{
return undefined
}