| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #pragma once
- #include "utilities.h"
- #include <stdbool.h>
- #include <assert.h>
- enum game_state
- {
- preloading = 0,
- mainMenu,
- inGame,
- gameOver,
- gameVictory
- };
- enum shape_names
- {
- left = 0,
- top,
- right,
- bottom
- };
- struct SimonSays
- {
- enum game_state gameState;
- int highScore;
- int currentScore;
- int numberOfMillisecondsBeforeShapeDisappears;
- enum shape_names simonMoves[1000];
- int playerMoveIndex;
- };
- struct SimonSays currentGame;
- void resetGame()
- {
- currentGame = (struct SimonSays){
- .gameState = preloading,
- .currentScore = 0,
- .playerMoveIndex = 0,
- .numberOfMillisecondsBeforeShapeDisappears = 500,
- .simonMoves[0] = getRandomIntInRange(0, 3)};
- }
- void preLoadGame()
- {
- // TODO: load game stuff
- currentGame.highScore = 0; // TODO: fetch this from storage
- setCurrentGameState(mainMenu);
- }
- void startGame()
- {
- assert(currentGame.gameState == mainMenu);
- setCurrentGameState(inGame);
- }
- void setCurrentGameState(enum game_state gameState)
- {
- currentGame.gameState = gameState;
- }
- enum game_state getCurrentGameState()
- {
- return currentGame.gameState;
- }
- void addNewSimonMove(int addAtIndex)
- {
- currentGame.simonMoves[addAtIndex] = getRandomIntInRange(0, 3);
- }
- void startNewRound()
- {
- addNewSimonMove(currentGame.currentScore);
- currentGame.playerMoveIndex = 0;
- }
- void onPlayerAnsweredCorrect()
- {
- currentGame.playerMoveIndex++;
- }
- void onPlayerAnsweredWrong()
- {
- setCurrentGameState(gameOver);
- }
- bool isRoundComplete()
- {
- return currentGame.playerMoveIndex == currentGame.currentScore;
- }
- enum shape_names getCurrentSimonMove()
- {
- return currentGame.simonMoves[currentGame.playerMoveIndex];
- }
- void onPlayerSelectedShapeCallback(enum shape_names shape)
- {
- if (shape == getCurrentSimonMove())
- {
- onPlayerAnsweredCorrect();
- }
- else
- {
- onPlayerAnsweredWrong();
- }
- }
|