2021-04-10 00:12:31 +02:00
|
|
|
/**
|
|
|
|
* React Subcomponent for displaying a location's UI, when that location is a gym
|
|
|
|
*
|
|
|
|
* This subcomponent renders all of the buttons for training at the gym
|
|
|
|
*/
|
|
|
|
import * as React from "react";
|
2021-04-29 02:07:26 +02:00
|
|
|
import { Blackjack } from "../../Casino/Blackjack";
|
|
|
|
import { CoinFlip } from "../../Casino/CoinFlip";
|
|
|
|
import { Roulette } from "../../Casino/Roulette";
|
|
|
|
import { SlotMachine } from "../../Casino/SlotMachine";
|
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { StdButton } from "../../ui/React/StdButton";
|
2021-04-10 00:12:31 +02:00
|
|
|
|
2021-04-29 02:07:26 +02:00
|
|
|
enum GameType {
|
2021-09-05 01:09:30 +02:00
|
|
|
None = "none",
|
|
|
|
Coin = "coin",
|
|
|
|
Slots = "slots",
|
|
|
|
Roulette = "roulette",
|
|
|
|
Blackjack = "blackjack",
|
2021-04-29 02:07:26 +02:00
|
|
|
}
|
2021-04-10 00:12:31 +02:00
|
|
|
|
|
|
|
type IProps = {
|
2021-09-05 01:09:30 +02:00
|
|
|
p: IPlayer;
|
|
|
|
};
|
2021-04-10 00:12:31 +02:00
|
|
|
|
|
|
|
type IState = {
|
2021-09-05 01:09:30 +02:00
|
|
|
game: GameType;
|
|
|
|
};
|
2021-04-10 00:12:31 +02:00
|
|
|
|
|
|
|
export class CasinoLocation extends React.Component<IProps, IState> {
|
2021-09-05 01:09:30 +02:00
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
2021-04-10 00:12:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
this.state = {
|
|
|
|
game: GameType.None,
|
|
|
|
};
|
2021-04-10 00:12:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
this.updateGame = this.updateGame.bind(this);
|
|
|
|
}
|
2021-04-10 00:12:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
updateGame(game: GameType): void {
|
|
|
|
this.setState({
|
|
|
|
game,
|
|
|
|
});
|
|
|
|
}
|
2021-04-10 00:12:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
renderGames(): React.ReactNode {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<StdButton
|
|
|
|
onClick={() => this.updateGame(GameType.Coin)}
|
|
|
|
text={"Play coin flip"}
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<StdButton
|
|
|
|
onClick={() => this.updateGame(GameType.Slots)}
|
|
|
|
text={"Play slots"}
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<StdButton
|
|
|
|
onClick={() => this.updateGame(GameType.Roulette)}
|
|
|
|
text={"Play roulette"}
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<StdButton
|
|
|
|
onClick={() => this.updateGame(GameType.Blackjack)}
|
|
|
|
text={"Play blackjack"}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2021-04-10 00:12:31 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
renderGame(): React.ReactNode {
|
|
|
|
let elem = null;
|
|
|
|
switch (this.state.game) {
|
|
|
|
case GameType.Coin:
|
|
|
|
elem = <CoinFlip p={this.props.p} />;
|
|
|
|
break;
|
|
|
|
case GameType.Slots:
|
|
|
|
elem = <SlotMachine p={this.props.p} />;
|
|
|
|
break;
|
|
|
|
case GameType.Roulette:
|
|
|
|
elem = <Roulette p={this.props.p} />;
|
|
|
|
break;
|
|
|
|
case GameType.Blackjack:
|
|
|
|
elem = <Blackjack p={this.props.p} />;
|
|
|
|
break;
|
|
|
|
case GameType.None:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error(`MissingCaseException: ${this.state.game}`);
|
2021-04-10 00:12:31 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<StdButton
|
|
|
|
onClick={() => this.updateGame(GameType.None)}
|
|
|
|
text={"Stop playing"}
|
|
|
|
/>
|
|
|
|
{elem}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): React.ReactNode {
|
|
|
|
if (this.state.game === GameType.None) {
|
|
|
|
return this.renderGames();
|
|
|
|
} else {
|
|
|
|
return this.renderGame();
|
2021-04-10 00:12:31 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
}
|