diff --git a/src/Home.tsx b/src/Home.tsx
index 41ac6d7..8ffa7ae 100644
--- a/src/Home.tsx
+++ b/src/Home.tsx
@@ -171,7 +171,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
minWidth: "10vw",
minHeight: "1vw",
background: "#2F2504",
- color : "white",
+ color: "white",
}}>
{connectionStateText()}
}
@@ -187,7 +187,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
{context.texts.Mancala}
{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} />}
diff --git a/src/components/InfoPanel.tsx b/src/components/InfoPanel.tsx
index b54a3d3..4c55572 100644
--- a/src/components/InfoPanel.tsx
+++ b/src/components/InfoPanel.tsx
@@ -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 (
{
context.texts.GameEnded + " " + whoWon
diff --git a/src/const/texts.ts b/src/const/texts.ts
index 6e8aae0..f2221ef 100644
--- a/src/const/texts.ts
+++ b/src/const/texts.ts
@@ -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"
}
\ No newline at end of file
diff --git a/src/mancala.ts b/src/mancala.ts
index 7eea963..a32516f 100644
--- a/src/mancala.ts
+++ b/src/mancala.ts
@@ -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
}