Skip to content

Instantly share code, notes, and snippets.

@River2056
Created February 20, 2021 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save River2056/baf570d30931e02d2794c80cad6569a7 to your computer and use it in GitHub Desktop.
Save River2056/baf570d30931e02d2794c80cad6569a7 to your computer and use it in GitHub Desktop.
import React from "react";
import { Helmet } from "react-helmet";
import { uuid } from "uuidv4";
import "./styles.css";
import "bootstrap/dist/css/bootstrap.min.css";
import TitleBar from "./components/titleBar";
import GameArea from "./components/gameArea";
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
id: uuid(),
isGameStart: false
};
}
gameReset = () => {
this.setState(() => ({ id: uuid() }));
};
backToMenu = () => {
this.setState(() => ({ isGameStart: false }));
};
startGame = () => {
this.setState(() => ({ isGameStart: true }));
};
render() {
return (
<div>
<TitleBar />
<div className="container" style={appStyle()}>
<Helmet>
<style>
{`body {
background-color: #1e1e1e;
color: #fff;
}`}
</style>
</Helmet>
{this.state.isGameStart ? (
<GameArea
key={this.state.id}
gameReset={this.gameReset}
giveUp={this.backToMenu}
/>
) : (
<div style={divStyle()}>
<div
style={{
display: "flex",
flexDirection: "column",
flexGrow: "1",
justifyContent: "center",
alignItems: "center"
}}
>
<img
src="./images/blackjack.jpg"
style={imgStyle()}
alt="BlackJack Game"
onClick={this.startGame}
/>
<h1>Tap to start</h1>
</div>
</div>
)}
</div>
</div>
);
}
}
const appStyle = () => {
return {
backgroundColor: "#1E1E1E"
};
};
const divStyle = () => {
return {
height: "100vh",
display: "flex",
flexGrow: "1",
flexDirection: "column",
alignItems: "center",
justifyContent: "center"
};
};
const imgStyle = () => {
return {
width: "100%"
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment