Преглед изворни кода

Remove platform agnostic Simon Says

SimplyMinimal пре 3 година
родитељ
комит
ad097ca94c
3 измењених фајлова са 0 додато и 185 уклоњено
  1. 0 67
      simonsays_cli.c
  2. 0 111
      simonsays_controller.h
  3. 0 7
      utilities.h

+ 0 - 67
simonsays_cli.c

@@ -1,67 +0,0 @@
-#include <stdio.h>
-#include <assert.h>
-#include "simonsays_controller.h"
-#include "utilities.h"
-
-int main()
-{
-    resetGame();
-
-    printf("Loading game...\n");
-    // TODO: LOADING SCREEN HERE
-    preLoadGame();
-
-    printf("Welcome to Simon Says!\nPress enter to start the game");
-    // TODO: MAIN MENU HERE
-    getchar();
-
-    startGame();
-
-    while (getCurrentGameState() == inGame)
-    {
-
-        printf("New Round!\n");
-        currentGame.currentScore++;
-        startNewRound();
-
-        enum shape_names currentSimonMove = getCurrentSimonMove();
-        printf("Simon Says.. Score(%d)\n", currentGame.currentScore - 1);
-        for (int index = 0; index < currentGame.currentScore; index++)
-        {
-            // TODO: TIMED SEQUENCE HERE
-            printf("%d\n", currentGame.simonMoves[index]);
-        }
-
-        printf("Your turn:\n");
-
-        while (!isRoundComplete())
-        {
-            char userInput = getchar();
-            if (userInput == '\n')
-                continue; // getchar registers enter as an input..
-            int playerAction = atoi(&userInput);
-
-            onPlayerSelectedShapeCallback(playerAction);
-
-            // TODO: INTERACT WITH USER INPUTS HERE
-
-            if (getCurrentGameState() != inGame)
-            {
-                break;
-            }
-        }
-    }
-
-    if (getCurrentGameState() == gameOver)
-    {
-        // TODO: GAMEOVER SCREEN HERE
-        printf("Game over!");
-    }
-    if (getCurrentGameState() == gameVictory)
-    {
-        // TODO: VICTORY SCREEN HERE
-        printf("You've beat Simon!");
-    }
-
-    return 0;
-}

+ 0 - 111
simonsays_controller.h

@@ -1,111 +0,0 @@
-#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();
-    }
-}

+ 0 - 7
utilities.h

@@ -1,7 +0,0 @@
-#pragma once
-#include <stdlib.h>
-
-int getRandomIntInRange(int lower, int upper) {
-        return (rand() %
-        (upper - lower + 1)) + lower;
-}