added who won text
This commit is contained in:
parent
39d4e138a9
commit
c8e354c159
@ -187,7 +187,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
|
|||||||
<h1 style={{ margin: "10px 0px" }}>{context.texts.Mancala}</h1>
|
<h1 style={{ margin: "10px 0px" }}>{context.texts.Mancala}</h1>
|
||||||
<div>
|
<div>
|
||||||
{renderNewGameButton()}
|
{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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -42,7 +42,11 @@ const InfoPanel: FunctionComponent<{
|
|||||||
|
|
||||||
if (game) {
|
if (game) {
|
||||||
if (game.state == "ended") {
|
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 (
|
return (
|
||||||
<h4>{
|
<h4>{
|
||||||
context.texts.GameEnded + " " + whoWon
|
context.texts.GameEnded + " " + whoWon
|
||||||
|
|||||||
@ -19,7 +19,8 @@ export type Texts = {
|
|||||||
OpponentLeavesTheGame: string,
|
OpponentLeavesTheGame: string,
|
||||||
YouLeftTheGame: string,
|
YouLeftTheGame: string,
|
||||||
SearchingOpponent: string,
|
SearchingOpponent: string,
|
||||||
PleaseWait : string
|
PleaseWait : string,
|
||||||
|
GameDraw : string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EnUs: Texts = {
|
export const EnUs: Texts = {
|
||||||
@ -42,7 +43,8 @@ export const EnUs: Texts = {
|
|||||||
OpponentLeavesTheGame: "Opponent Leaves The Game",
|
OpponentLeavesTheGame: "Opponent Leaves The Game",
|
||||||
YouLeftTheGame: "You Left The Game",
|
YouLeftTheGame: "You Left The Game",
|
||||||
SearchingOpponent: "Searching Opponent",
|
SearchingOpponent: "Searching Opponent",
|
||||||
PleaseWait : "Please Wait"
|
PleaseWait : "Please Wait",
|
||||||
|
GameDraw : "Draw"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TrTr: Texts = {
|
export const TrTr: Texts = {
|
||||||
@ -65,5 +67,6 @@ export const TrTr: Texts = {
|
|||||||
OpponentLeavesTheGame: "Rakip Oyundan Ayrıldı",
|
OpponentLeavesTheGame: "Rakip Oyundan Ayrıldı",
|
||||||
YouLeftTheGame: "Sen Oyundan Ayrıldın",
|
YouLeftTheGame: "Sen Oyundan Ayrıldın",
|
||||||
SearchingOpponent: "Rakip Aranıyor",
|
SearchingOpponent: "Rakip Aranıyor",
|
||||||
PleaseWait: "Lütfen Bekleyin"
|
PleaseWait: "Lütfen Bekleyin",
|
||||||
|
GameDraw : "Berabere"
|
||||||
}
|
}
|
||||||
@ -128,10 +128,10 @@ export class Game {
|
|||||||
|
|
||||||
//todo throw expection
|
//todo throw expection
|
||||||
public getPlayerKeyByName(key: "player1" | "player2"): string {
|
public getPlayerKeyByName(key: "player1" | "player2"): string {
|
||||||
if (this.player1 == key) {
|
if (key == "player1") {
|
||||||
return "player1"
|
return this.player1
|
||||||
} else {
|
} else {
|
||||||
return "player2"
|
return this.player2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,9 +144,9 @@ export class Game {
|
|||||||
const player2BallCount = this.board.player2Store.ballCount
|
const player2BallCount = this.board.player2Store.ballCount
|
||||||
|
|
||||||
if(player1BallCount < player2BallCount){
|
if(player1BallCount < player2BallCount){
|
||||||
return this.getPlayerKeyByName("player1")
|
|
||||||
}else if(player1BallCount > player2BallCount) {
|
|
||||||
return this.getPlayerKeyByName("player2")
|
return this.getPlayerKeyByName("player2")
|
||||||
|
}else if(player1BallCount > player2BallCount) {
|
||||||
|
return this.getPlayerKeyByName("player1")
|
||||||
}else{
|
}else{
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user