import React from 'react'; import { createGame, gameInfo, joinGame, getGuesses, sendGuess } from "./services/ggsh.service"; import GamePanel from "./components/game-panel.component"; import ApiInfo from "./components/api-info.component"; import PlayerScores from "./components/player-scores.component"; import RoundSummary from './components/round-summary.component'; import './App.css'; import PreGame from './components/pre-game.component'; const LOADING = "LOADING"; const PRE_GAME = "PREGAME"; const IN_ROUND = "INROUND"; const POST_ROUND = "POSTROUND"; const POST_GAME = "POSTGAME"; class Game extends React.Component { constructor(props) { super(props); this.state = { gameState: PRE_GAME, playerName: "testing", // TODO mechanism for setting this loading: false, gameId: null, // TODO mechanism for joining game currentRound: null, targetPoint: null, selectedPoint: null, lastScore: null, totalScore: null, players: null, } } async handleGameCreate() { this.setState({ gameState: LOADING }); const { playerName } = this.state; const gameId = await createGame(playerName, 300); this.setState({ gameId }); await this.updateRoundState(); } async updateRoundState() { this.setState({ gameState: LOADING }) const { gameId, playerName } = this.state; const { currentRound } = await getGuesses(gameId, playerName); const { coords, players } = await gameInfo(gameId); if (currentRound) { const targetPoint = coords[currentRound]; this.setState({ gameState: IN_ROUND, currentRound, targetPoint, selectedPoint: null, players, }); } else { this.setState({ gameState: POST_GAME, players }); } } async handleSubmitGuess() { const { gameId, playerName, currentRound, selectedPoint } = this.state; this.setState({ gameState: LOADING }); const { score, totalScore } = await sendGuess(gameId, playerName, currentRound, selectedPoint); this.setState({ gameState: POST_ROUND, lastScore: score, totalScore }); } render() { const { gameState } = this.state; switch (gameState) { case LOADING: return

Loading...

case PRE_GAME: return this.handleGameCreate()} /> case IN_ROUND: const { targetPoint, selectedPoint } = this.state; return this.setState({selectedPoint: latLng})} onSubmitGuess={() => this.handleSubmitGuess()} streetViewPoint={targetPoint} selectedPoint={selectedPoint} /> case POST_ROUND: const { currentRound, lastScore, totalScore } = this.state; return this.updateRoundState()} buttonText={currentRound === "5" ? "View Summary" : "Next Round"} /> case POST_GAME: const { players } = this.state; return this.setState({ gameState: PRE_GAME })} /> default: return

Application state is inconsistent, please refresh and rejoin your previous game.

} } } const App = () => { return (

TerrAssumptions!



); } export default App;