Skip to content

Instantly share code, notes, and snippets.

@fallenthereaper
Last active April 25, 2024 22:33
Show Gist options
  • Select an option

  • Save fallenthereaper/dbd6361b4525fe2b24cecb9e6396b853 to your computer and use it in GitHub Desktop.

Select an option

Save fallenthereaper/dbd6361b4525fe2b24cecb9e6396b853 to your computer and use it in GitHub Desktop.

Revisions

  1. fallenthereaper revised this gist Apr 25, 2024. 6 changed files with 117 additions and 62 deletions.
    67 changes: 60 additions & 7 deletions errors.txt
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,6 @@
    Severity Code Description Project File Line Suppression State Details
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 31
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    @@ -35,23 +29,82 @@ Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\m
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2065 'game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Warning C4244 'initializing': conversion from 'float' to 'int', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 36
    Warning C4244 'initializing': conversion from 'float' to 'int', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 37
    Warning C4244 '=': conversion from 'float' to 'int', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 47
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 55
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 55
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 123
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 124
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 125
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 126
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 127
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 128
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 129
    Error C2660 'ShopGame::GameState::handleInput': function does not take 2 arguments C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 141
    Warning C4067 unexpected tokens following preprocessor directive - expected a newline C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\game_renderer.cpp 4
    Warning C4067 unexpected tokens following preprocessor directive - expected a newline C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\game_renderer.h 3
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 22
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 22
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2065 'Game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2144 syntax error: 'unknown-type' should be preceded by ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2144 syntax error: 'unknown-type' should be preceded by ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2065 'Game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2065 'game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2039 'GameState': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 31
    Error C2061 syntax error: identifier 'GameState' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 31
    Error C2039 'GameState': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error C2039 'GameState': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error C2039 'GameState': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error C2039 'GameState': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C2660 'ShopGame::Game::setGameState': function does not take 1 arguments C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 42
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 118
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 119
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 120
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 121
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 122
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 123
    Warning C4244 'argument': conversion from 'int' to 'float', possible loss of data C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game_state.cpp 124
    Warning C4067 unexpected tokens following preprocessor directive - expected a newline C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\tictac_game.h 3
    Warning C4067 unexpected tokens following preprocessor directive - expected a newline C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\main.cpp 18
    Warning C4067 unexpected tokens following preprocessor directive - expected a newline C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\main.cpp 19
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    49 changes: 22 additions & 27 deletions game.cpp
    Original file line number Diff line number Diff line change
    @@ -1,33 +1,29 @@
    #include "src/core/shop/game.h"


    namespace ShopGame {


    Game::Game() : running(true), gameName("Default"), canvas(new GameRenderer::TextCanvas(0, 0)), currentState(nullptr), prevState(nullptr) {
    ShopGame::Game::Game() : running(true), gameName("Default"), canvas(new GameRenderer::TextCanvas(0, 0)), currentState(nullptr), prevState(nullptr) {
    registerCommands();
    }

    Game::Game(int canvasWidth, int canvasHeight, std::string name) : canvas(new GameRenderer::TextCanvas(canvasWidth, canvasHeight)), running(true), gameName(name), currentState(nullptr), prevState(nullptr) {
    ShopGame::Game::Game(int canvasWidth, int canvasHeight, std::string name) : canvas(new GameRenderer::TextCanvas(canvasWidth, canvasHeight)), running(true), gameName(name), currentState(nullptr), prevState(nullptr) {

    registerCommands();
    }

    // Destructor
    Game::~Game() {
    ShopGame::Game::~Game() {
    registerCommands();
    }

    void Game::addCommand(const std::string& command, const std::function<void(Game*)> consumer) {
    void ShopGame::Game::addCommand(const std::string& command, const std::function<void(Game*)> consumer) {
    // commandMap[command] = (consumer);
    commandMap.emplace(command, consumer);
    }

    std::string Game::getName() {
    std::string ShopGame::Game::getName() {
    return gameName;
    }

    void displayItemList(GameRenderer::TextCanvas* canvas, const std::unordered_map<std::string, ItemRegistry::ItemFactory>& itemList, const std::string& displayTitle, const Vec2& topLeft, int maxWidth, int itemWidth, int itemHeight, int maxItemCount) {
    void ShopGame::displayItemList(GameRenderer::TextCanvas* canvas, const std::unordered_map<std::string, ItemRegistry::ItemFactory>& itemList, const std::string& displayTitle, const Vec2& topLeft, int maxWidth, int itemWidth, int itemHeight, int maxItemCount) {
    int itemCount = std::min(static_cast<int>(itemList.size()), maxItemCount);

    // Calculate the number of rows needed based on the item count
    @@ -65,7 +61,7 @@ namespace ShopGame {
    }
    }

    void Game::registerCommands() {
    void ShopGame::Game::registerCommands() {
    GameRenderer::TextCanvas* canvas = this->getCanvas();

    addCommand("shop", [canvas](Game* g) {
    @@ -135,22 +131,22 @@ namespace ShopGame {
    }

    // Method to process input and trigger associated consumers
    void Game::processInput(const std::string& input) {
    void ShopGame::Game::processInput(const std::string& input) {
    auto it = commandMap.find(input);
    if (it != commandMap.end()) {
    it->second(this);
    }
    else {
    if (currentState) {
    currentState->handleInput(this, input);
    currentState->handleInput(this, input);
    }
    else {
    std::cout << "Command not recognized. Try again." << std::endl;
    }
    }
    }

    void Game::update(GameRenderer::TextCanvas* canvas) {
    void ShopGame::Game::update(GameRenderer::TextCanvas* canvas) {
    canvas->drawSquare(Vec2(0, 0), 112, 28, '*', "", true);
    std::string input;
    std::cout << "Enter a command: ";
    @@ -160,64 +156,63 @@ namespace ShopGame {
    }


    void Game::clean() {
    void ShopGame::Game::clean() {
    }

    void Game::render() {
    void ShopGame::Game::render() {
    if (currentState) {

    currentState->render(canvas);
    canvas->render(); // Render the canvas after updating its content
    }
    }

    const bool Game::isRunning() {
    const bool ShopGame::Game::isRunning() {

    return this->running;
    }

    void Game::setRunning(bool val) {
    void ShopGame::Game::setRunning(bool val) {

    this->running = val;

    }

    GameRenderer::TextCanvas* Game::getCanvas() {
    GameRenderer::TextCanvas* ShopGame::Game::getCanvas() {

    return canvas;
    }

    void Game::setGameState(ShopGame::GameState* state) {
    void ShopGame::Game::setGameState(GameState* state) {
    prevState = currentState;

    if (currentState != nullptr) {
    delete currentState; // Clean up the previous state
    // delete currentState; // Clean up the previous state
    }

    std::cout << "Switching GameState..";
    currentState = state;
    }

    GameState* Game::getGameState() {
    ShopGame::GameState* ShopGame::Game::getGameState() {
    return currentState;
    }

    GameState* Game::getPreviousState() {
    ShopGame::GameState* ShopGame::Game::getPreviousState() {
    return prevState;
    }

    // Method to start the game
    void Game::start() {
    void ShopGame::Game::start() {
    std::cout << "[Game Started]" << std::endl;
    std::cout << "Type 'exit' to quit the game." << std::endl;
    }


    // Helper method for handling user input
    void Game::handleInput(const std::string& input) {
    void ShopGame::Game::handleInput(const std::string& input) {



    std::cout << "Command not recognized. Try again." << std::endl;
    }

    } // namespace ShopGame
    12 changes: 9 additions & 3 deletions game.h
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,15 @@
    #pragma once
    #ifndef GAME_H
    #define GAME_H

    #include <iostream>
    #include <unordered_map>
    #include <functional>
    #include "src/core/text_canvas.h"
    #include "src/core/shop/registry/item_registry.h"
    #include "src/core/shop/game_state.h"
    #include "game_state.h"
    #include "src/core/utils/utility.h"
    #include <vector>

    namespace ShopGame {

    @@ -21,7 +25,7 @@ namespace ShopGame {
    const bool isRunning();
    void setRunning(bool val);
    GameRenderer::TextCanvas* getCanvas();
    void addCommand(const std::string& command, const std::function<void(Game*)> function);
    void addCommand(const std::string& command, const std::function<void(ShopGame::Game*)> function);
    void processInput(const std::string& input);
    std::string getName();
    void setGameState(ShopGame::GameState* state);
    @@ -41,4 +45,6 @@ namespace ShopGame {
    friend void displayItemList(GameRenderer::TextCanvas* canvas, const std::unordered_map<std::string, ItemRegistry::ItemFactory>& itemList, const std::string& displayTitle, const Vec2& topLeft, int maxWidth, int itemWidth, int itemHeight, int maxItemCount);
    };

    } // namespace ShopGame
    } // namespace ShopGame

    #endif
    26 changes: 12 additions & 14 deletions game_state.cpp
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,12 @@

    #include "src/core/shop/game_state.h"

    namespace ShopGame {
    //GAME STATE
    GameState::GameState(Game* game) {
    ShopGame::GameState::GameState(Game* game) {
    init(game);
    }

    void GameState::handleInput(Game* game, const std::string& input) {
    void ShopGame::GameState::handleInput(ShopGame::Game* game, const std::string& input) {
    auto it = commandMap.find(input);
    if (it != commandMap.end()) {
    // Execute the consumer associated with the input command
    @@ -18,46 +17,46 @@ namespace ShopGame {
    }
    };

    void GameState::update(Game* game) {
    void ShopGame::GameState::update(Game* game) {

    };

    void GameState::init(Game* game) {
    void ShopGame::GameState::init(Game* game) {
    registerCommands();
    }

    void GameState::addCommand(const std::string& command, const std::function<void(Game*)> consumer) {
    void ShopGame::GameState::addCommand(const std::string& command, const std::function<void(Game*)> consumer) {
    // commandMap[command] = (consumer);
    commandMap.emplace(command, consumer);
    }

    Game* GameState::getGame() {
    ShopGame::Game* ShopGame::GameState::getGame() {
    return game;
    }


    void GameState::registerCommands() {
    void ShopGame::GameState::registerCommands() {
    addCommand("menu", [this](Game* g) {
    GameState* menu = new MenuState(g);

    g->setGameState(menu);
    g->setGameState(menu);
    });
    }


    void GameState::render(GameRenderer::TextCanvas* canvas) {
    void ShopGame::GameState::render(GameRenderer::TextCanvas* canvas) {

    }



    //MENU STATE

    void MenuState::update(ShopGame::Game* game) {
    void ShopGame::MenuState::update(Game* game) {
    // Update logic for the menu state
    }

    void MenuState::registerCommands() {
    void ShopGame::MenuState::registerCommands() {
    GameState::registerCommands();

    GameRenderer::TextCanvas* canvas = getGame()->getCanvas();
    @@ -127,8 +126,7 @@ namespace ShopGame {
    }


    void MenuState::render(GameRenderer::TextCanvas* canvas) {
    void ShopGame::MenuState::render(GameRenderer::TextCanvas* canvas) {
    // Render the menu state on the canvas
    }

    }
    21 changes: 12 additions & 9 deletions game_state.h
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,32 @@
    #pragma once



    #pragma once
    #ifndef GAME_STATE_H
    #define GAME_STATE_H

    #include <string>
    #include <unordered_map>
    #include <functional>
    #include "src/core/shop/game.h" // Include the necessary header
    #include "game.h" // Include the necessary header

    namespace ShopGame {

    class GameState {
    protected:
    ShopGame::Game* game;
    std::unordered_map<std::string, std::function<void(ShopGame::Game*)>> commandMap;


    public:
    GameState(ShopGame::Game* game);
    virtual ~GameState() = default;
    void handleInput(ShopGame::Game* game, const std::string& input);
    void handleInput(Game* game, const std::string& input);
    virtual void update(ShopGame::Game* game) = 0;
    virtual void registerCommands() = 0;
    void init(ShopGame::Game* game);
    void addCommand(const std::string& command, const std::function<void(ShopGame::Game*)> function);
    ShopGame::Game* getGame();
    virtual void render(GameRenderer::TextCanvas* canvas) = 0;

    private:
    ShopGame::Game* game;
    std::unordered_map<std::string, std::function<void(ShopGame::Game*)>> commandMap;
    };

    class MenuState : public GameState {
    @@ -36,4 +37,6 @@ namespace ShopGame {
    void render(GameRenderer::TextCanvas* canvas) override;
    };

    } // namespace ShopGame
    } // namespace ShopGam

    #endif
    4 changes: 2 additions & 2 deletions main.cpp
    Original file line number Diff line number Diff line change
    @@ -89,13 +89,13 @@ unsigned long long hexToDecimal(const std::string& hexString) {
    }


    using Game = ShopGame::Game;


    int main(int argc, const char * argv[]) {
    coreInit();


    game = new Game(MAX_CANVAS_WIDTH, MAX_CANVAS_HEIGHT, "Exolor");
    game = new ShopGame::Game(MAX_CANVAS_WIDTH, MAX_CANVAS_HEIGHT, "Exolor");


    game->start();
  2. fallenthereaper revised this gist Apr 25, 2024. 1 changed file with 82 additions and 0 deletions.
    82 changes: 82 additions & 0 deletions errors.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    Severity Code Description Project File Line Suppression State Details
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 31
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error (active) E0020 identifier "GameState" is undefined main.exe - x64 Release C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 22
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 22
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2065 'Game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2144 syntax error: 'unknown-type' should be preceded by ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2144 syntax error: 'unknown-type' should be preceded by ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2065 'Game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2065 'game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2660 'ShopGame::GameState::handleInput': function does not take 2 arguments C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\src\core\base\shop\game.cpp 141
    Error C2061 syntax error: identifier 'GameState' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 31
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 32
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 33
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 36
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game.h 37
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 17
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 19
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 20
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 22
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 22
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2065 'Game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2144 syntax error: 'unknown-type' should be preceded by ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2144 syntax error: 'unknown-type' should be preceded by ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 23
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 24
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2143 syntax error: missing ';' before '*' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2238 unexpected token(s) preceding ';' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 28
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2065 'Game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2059 syntax error: ')' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 29
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
    Error C2039 'Game': is not a member of 'ShopGame' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2061 syntax error: identifier 'Game' C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 36
    Error C2065 'game': undeclared identifier C:\Users\salva\source\repos\_cmake\main\out\build\x64-release\main C:\Users\salva\source\repos\_cmake\main\include\src\core\shop\game_state.h 34
  3. fallenthereaper revised this gist Apr 25, 2024. 4 changed files with 531 additions and 0 deletions.
    223 changes: 223 additions & 0 deletions game.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,223 @@
    #include "src/core/shop/game.h"


    namespace ShopGame {


    Game::Game() : running(true), gameName("Default"), canvas(new GameRenderer::TextCanvas(0, 0)), currentState(nullptr), prevState(nullptr) {
    registerCommands();
    }

    Game::Game(int canvasWidth, int canvasHeight, std::string name) : canvas(new GameRenderer::TextCanvas(canvasWidth, canvasHeight)), running(true), gameName(name), currentState(nullptr), prevState(nullptr) {

    registerCommands();
    }

    // Destructor
    Game::~Game() {
    registerCommands();
    }

    void Game::addCommand(const std::string& command, const std::function<void(Game*)> consumer) {
    // commandMap[command] = (consumer);
    commandMap.emplace(command, consumer);
    }

    std::string Game::getName() {
    return gameName;
    }

    void displayItemList(GameRenderer::TextCanvas* canvas, const std::unordered_map<std::string, ItemRegistry::ItemFactory>& itemList, const std::string& displayTitle, const Vec2& topLeft, int maxWidth, int itemWidth, int itemHeight, int maxItemCount) {
    int itemCount = std::min(static_cast<int>(itemList.size()), maxItemCount);

    // Calculate the number of rows needed based on the item count
    int numRows = (itemCount + (maxWidth - 1)) / maxWidth;
    int numCols = (itemCount + numRows - 1) / numRows;

    // Draw the title of the item list
    canvas->drawSquare(topLeft + Vec2{2, - 1}, itemWidth * numRows + 3 , itemHeight, '*', displayTitle, true);

    int row = topLeft.y + 2; // Start rendering items below the title
    int col = topLeft.x + 2;

    int itemIndex = 0;
    for (const auto& itemPair : itemList) {
    if (itemIndex >= maxItemCount) {
    break; // Stop rendering if maximum item count is reached
    }

    // Check if we need to move to the next row
    if (col + itemWidth > topLeft.x + numCols * itemWidth) {
    col = topLeft.x + 2; // Reset column position to start a new row
    row += itemHeight ; // Move to the next row
    }

    // Get the item name from the item pair
    std::string itemName = itemPair.first;

    // Render the item at the current position
    canvas->drawSquare(Vec2(col, row + 1), itemWidth, itemHeight, '*', itemName, true);

    // Move to the next column position
    col += itemWidth + 1;

    ++itemIndex;
    }
    }

    void Game::registerCommands() {
    GameRenderer::TextCanvas* canvas = this->getCanvas();

    addCommand("shop", [canvas](Game* g) {
    std::cout << "Opening shop..." << std::endl;

    const auto& itemMap = ItemRegistry::getInstance()->getItemMap();

    // Define the dimensions and layout of the item shop display
    Vec2 shopTopLeft(16 , 3);
    int maxWidth = 6; // Maximum items per row
    int itemWidth = 18;
    int itemHeight = 3;
    int maxItemCount = 30; // Maximum items to display


    displayItemList(canvas, itemMap, "Item Shop", shopTopLeft, maxWidth, itemWidth, itemHeight, maxItemCount);

    });


    addCommand("exit", [canvas](Game* g) {
    std::cout << "Closing game..." << std::endl;
    canvas->drawSquare(Vec2(46, 10), 20, 5, '*', "Game Closed", true);

    g->running = false; // Set running flag to false to exit the game loop
    });

    addCommand("clear", [canvas](Game* g) {
    std::cout << "Clearing canvas..." << std::endl;
    canvas->clear(); // Clear the canvas
    canvas->drawSquare(Vec2(46, 10), 20, 5, '*', "Cleared Canvas", true);
    });
    addCommand("help", [canvas](Game* g) {
    canvas->drawSquare(Vec2(46, 10), 20, 5, '*', "Help Menu", false);
    canvas->drawSquare(Vec2(48, 12), 16, 3, '*', "Commands:", false);
    canvas->drawSquare(Vec2(50, 14), 12, 3, '*', "shop - Open shop", false);
    canvas->drawSquare(Vec2(50, 16), 12, 3, '*', "exit - Exit game", false);
    canvas->drawSquare(Vec2(50, 18), 12, 3, '*', "clear - Clear canvas", false);
    canvas->drawSquare(Vec2(50, 20), 12, 3, '*', "info - Game info", false);
    canvas->drawSquare(Vec2(50, 22), 12, 3, '*', "help - Display help", false);
    });
    addCommand("info", [canvas](Game* g) {
    std::cout << "Displaying info..." << std::endl;
    canvas->drawSquare(Vec2(46, 3), 20, 5, '*', "Game Information", true);


    canvas->drawText(Vec2(46, 14), "Version: 1.0");
    canvas->drawText(Vec2(46, 16), "Developer: " + g->getName());

    // Display screen size
    int screenWidth = g->getCanvas()->getWidth();
    int screenHeight = g->getCanvas()->getHeight();
    canvas->drawText(Vec2(46, 18), "Screen Size:");
    canvas->drawText(Vec2(46, 20), "Width: " + std::to_string(screenWidth));
    canvas->drawText(Vec2(46, 22), "Height: " + std::to_string(screenHeight));

    // Display available commands
    int x = 6;
    canvas->drawSquare(Vec2(x - 2, 2), 28, 14, '*', "", true);
    canvas->drawText(Vec2(x, 3), "Available Commands:");
    canvas->drawText(Vec2(x, 5), "shop - Open shop");
    canvas->drawText(Vec2(x, 7), "exit - Exit game");
    canvas->drawText(Vec2(x, 9), "clear - Clear canvas");
    canvas->drawText(Vec2(x, 11), "info - Display game info");
    canvas->drawText(Vec2(x, 13), "help - Display help menu");
    });
    }

    // Method to process input and trigger associated consumers
    void Game::processInput(const std::string& input) {
    auto it = commandMap.find(input);
    if (it != commandMap.end()) {
    it->second(this);
    }
    else {
    if (currentState) {
    currentState->handleInput(this, input);
    }
    else {
    std::cout << "Command not recognized. Try again." << std::endl;
    }
    }
    }

    void Game::update(GameRenderer::TextCanvas* canvas) {
    canvas->drawSquare(Vec2(0, 0), 112, 28, '*', "", true);
    std::string input;
    std::cout << "Enter a command: ";
    std::cin >> input;

    processInput(input);
    }


    void Game::clean() {
    }

    void Game::render() {
    if (currentState) {
    currentState->render(canvas);
    canvas->render(); // Render the canvas after updating its content
    }
    }

    const bool Game::isRunning() {

    return this->running;
    }

    void Game::setRunning(bool val) {

    this->running = val;

    }

    GameRenderer::TextCanvas* Game::getCanvas() {

    return canvas;
    }

    void Game::setGameState(ShopGame::GameState* state) {
    prevState = currentState;

    if (currentState != nullptr) {
    delete currentState; // Clean up the previous state
    }

    std::cout << "Switching GameState..";
    currentState = state;
    }

    GameState* Game::getGameState() {
    return currentState;
    }

    GameState* Game::getPreviousState() {
    return prevState;
    }

    // Method to start the game
    void Game::start() {
    std::cout << "[Game Started]" << std::endl;
    std::cout << "Type 'exit' to quit the game." << std::endl;
    }


    // Helper method for handling user input
    void Game::handleInput(const std::string& input) {



    std::cout << "Command not recognized. Try again." << std::endl;
    }

    } // namespace ShopGame
    134 changes: 134 additions & 0 deletions game_state.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,134 @@

    #include "src/core/shop/game_state.h"

    namespace ShopGame {
    //GAME STATE
    GameState::GameState(Game* game) {
    init(game);
    }

    void GameState::handleInput(Game* game, const std::string& input) {
    auto it = commandMap.find(input);
    if (it != commandMap.end()) {
    // Execute the consumer associated with the input command
    it->second(game); // Pass 'this' pointer to the Game object
    }
    else {
    game->getCanvas()->drawSquare(Vec2(38, 10), 38, 5, '*', "Command not recognized. Try again.", true);
    }
    };

    void GameState::update(Game* game) {

    };

    void GameState::init(Game* game) {
    registerCommands();
    }

    void GameState::addCommand(const std::string& command, const std::function<void(Game*)> consumer) {
    // commandMap[command] = (consumer);
    commandMap.emplace(command, consumer);
    }

    Game* GameState::getGame() {
    return game;
    }


    void GameState::registerCommands() {
    addCommand("menu", [this](Game* g) {
    GameState* menu = new MenuState(g);

    g->setGameState(menu);
    });
    }


    void GameState::render(GameRenderer::TextCanvas* canvas) {

    }



    //MENU STATE

    void MenuState::update(ShopGame::Game* game) {
    // Update logic for the menu state
    }

    void MenuState::registerCommands() {
    GameState::registerCommands();

    GameRenderer::TextCanvas* canvas = getGame()->getCanvas();

    addCommand("shop", [canvas](Game* g) {
    std::cout << "Opening shop..." << std::endl;

    const auto& itemMap = ItemRegistry::getInstance()->getItemMap();

    // Define the dimensions and layout of the item shop display
    Vec2 shopTopLeft(16, 3);
    int maxWidth = 6; // Maximum items per row
    int itemWidth = 18;
    int itemHeight = 3;
    int maxItemCount = 30; // Maximum items to display

    displayItemList(canvas, itemMap, "Item Shop", shopTopLeft, maxWidth, itemWidth, itemHeight, maxItemCount);
    });

    addCommand("exit", [canvas](Game* g) {
    std::cout << "Closing game..." << std::endl;
    canvas->drawSquare(Vec2(46, 10), 20, 5, '*', "Game Closed", true);

    g->setRunning(false); // Set running flag to false to exit the game loop
    });

    addCommand("clear", [canvas](Game* g) {
    std::cout << "Clearing canvas..." << std::endl;
    canvas->clear(); // Clear the canvas
    canvas->drawSquare(Vec2(46, 10), 20, 5, '*', "Cleared Canvas", true);
    });

    addCommand("help", [canvas](Game* g) {
    canvas->drawSquare(Vec2(46, 10), 20, 5, '*', "Help Menu", false);
    canvas->drawSquare(Vec2(48, 12), 16, 3, '*', "Commands:", false);
    canvas->drawSquare(Vec2(50, 14), 12, 3, '*', "shop - Open shop", false);
    canvas->drawSquare(Vec2(50, 16), 12, 3, '*', "exit - Exit game", false);
    canvas->drawSquare(Vec2(50, 18), 12, 3, '*', "clear - Clear canvas", false);
    canvas->drawSquare(Vec2(50, 20), 12, 3, '*', "info - Game info", false);
    canvas->drawSquare(Vec2(50, 22), 12, 3, '*', "help - Display help", false);
    });

    addCommand("info", [canvas](Game* g) {
    std::cout << "Displaying info..." << std::endl;
    canvas->drawSquare(Vec2(46, 3), 20, 5, '*', "Game Information", true);

    canvas->drawText(Vec2(46, 14), "Version: 1.0");
    canvas->drawText(Vec2(46, 16), "Developer: " + g->getName());

    // Display screen size
    int screenWidth = g->getCanvas()->getWidth();
    int screenHeight = g->getCanvas()->getHeight();
    canvas->drawText(Vec2(46, 18), "Screen Size:");
    canvas->drawText(Vec2(46, 20), "Width: " + std::to_string(screenWidth));
    canvas->drawText(Vec2(46, 22), "Height: " + std::to_string(screenHeight));

    // Display available commands
    int x = 6;
    canvas->drawSquare(Vec2(x - 2, 2), 28, 14, '*', "", true);
    canvas->drawText(Vec2(x, 3), "Available Commands:");
    canvas->drawText(Vec2(x, 5), "shop - Open shop");
    canvas->drawText(Vec2(x, 7), "exit - Exit game");
    canvas->drawText(Vec2(x, 9), "clear - Clear canvas");
    canvas->drawText(Vec2(x, 11), "info - Display game info");
    canvas->drawText(Vec2(x, 13), "help - Display help menu");
    });
    }


    void MenuState::render(GameRenderer::TextCanvas* canvas) {
    // Render the menu state on the canvas
    }

    }
    39 changes: 39 additions & 0 deletions game_state.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #pragma once



    #pragma once

    #include <string>
    #include <unordered_map>
    #include <functional>
    #include "src/core/shop/game.h" // Include the necessary header

    namespace ShopGame {

    class GameState {
    protected:
    ShopGame::Game* game;
    std::unordered_map<std::string, std::function<void(ShopGame::Game*)>> commandMap;

    public:
    GameState(ShopGame::Game* game);
    virtual ~GameState() = default;
    void handleInput(ShopGame::Game* game, const std::string& input);
    virtual void update(ShopGame::Game* game) = 0;
    virtual void registerCommands() = 0;
    void init(ShopGame::Game* game);
    void addCommand(const std::string& command, const std::function<void(ShopGame::Game*)> function);
    ShopGame::Game* getGame();
    virtual void render(GameRenderer::TextCanvas* canvas) = 0;
    };

    class MenuState : public GameState {
    public:
    MenuState(ShopGame::Game* game) : GameState(game) {}
    void registerCommands() override;
    void update(ShopGame::Game* game) override;
    void render(GameRenderer::TextCanvas* canvas) override;
    };

    } // namespace ShopGame
    135 changes: 135 additions & 0 deletions main.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,135 @@
    // main.cpp : Defines the entry point for the application.
    //

    #define MAX_CANVAS_WIDTH 112
    #define MAX_CANVAS_HEIGHT 28


    #include "src/core/main.h"
    #include "src/core/utils/utility.h"
    #include "src/core/utils/containers.h"
    #include <vector>
    #include "src/core/bank/bank.h"
    #include "src/core/bank/bank_account.h"
    #include "src/core//tictac_game.h"
    #include <sstream>
    #include <iomanip>
    #include "src/core/shop/registry/item_registry.h"
    #include "src/core/shop/registry/items.h";
    #include "src/core/shop/game.h";
    #include "src/core/Game_renderer.h";
    using namespace std;
    using namespace Utility;
    using namespace Utility::Mth;

    //using Vec3 = Utility::Mth::Vec3;

    ///int argc, char * argv[]

    static const std::vector<std::string> BELOW_TWENTY = {
    "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
    "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
    "seventeen", "eighteen", "nineteen"
    };

    unsigned long long hexToDecimal(const std::string& hexString) {
    unsigned long long decimalValue;
    std::stringstream ss;
    ss << std::hex << hexString;
    ss >> decimalValue;
    return decimalValue;
    }

    // Function to convert a decimal integer to a hexadecimal string
    std::string decimalToHex(unsigned long long decimalValue) {
    std::stringstream ss;
    ss << std::hex << std::uppercase << decimalValue;
    return ss.str();
    }


    ShopGame::Game* game = nullptr;

    void coreInit() {

    ShopGame::registerItems();
    }

    // Function to compare two canvas data arrays
    bool compareData(const char** canvas1, const char** canvas2, int width, int height) {
    for (int y = 0; y < height; ++y) {
    for (int x = 0; x < width; ++x) {
    if (canvas1[y][x] != canvas2[y][x]) {
    return false; // Found a difference in the canvas content
    }
    }
    }
    return true; // Canvases are identical
    }

    // Function to copy canvas data
    const char** copyData(const char** canvas, int width, int height) {
    char** copiedCanvas = new char* [height];
    for (int y = 0; y < height; ++y) {
    copiedCanvas[y] = new char[width];
    for (int x = 0; x < width; ++x) {
    copiedCanvas[y][x] = canvas[y][x];
    }
    }
    return const_cast<const char**>(copiedCanvas);
    }

    void deleteData(const char** canvas, int height) {
    if (canvas != nullptr) {
    for (int y = 0; y < height; ++y) {
    delete[] canvas[y]; // Free each row of the canvas
    }
    delete[] canvas; // Free the array of rows
    }
    }


    using Game = ShopGame::Game;

    int main(int argc, const char * argv[]) {
    coreInit();


    game = new Game(MAX_CANVAS_WIDTH, MAX_CANVAS_HEIGHT, "Exolor");


    game->start();

    const char** prevCanvas = nullptr;

    GameRenderer::TextCanvas* canvas = game->getCanvas();

    while (game->isRunning()) {


    game->update(canvas);

    const char** currentCanvas = canvas->getData();

    // Check if the canvas content has changed
    if (prevCanvas == nullptr || !compareData(prevCanvas, currentCanvas, canvas->getWidth(), canvas->getHeight())) {
    // Render the game only if the canvas content has changed
    GameRenderer::render(game);

    // Update the previous canvas to match the current canvas
    if (prevCanvas != nullptr) {
    delete[] prevCanvas; // Free the previously allocated memory
    }
    prevCanvas = copyData(currentCanvas, canvas->getWidth(), canvas->getHeight());
    }

    // GameRenderer::render(game);
    }

    // Clean up allocated memory for the last recorded canvas
    if (prevCanvas != nullptr) {
    delete[] prevCanvas;
    }
    return 0;
    }

  4. fallenthereaper created this gist Apr 25, 2024.
    44 changes: 44 additions & 0 deletions game.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #pragma once

    #include <iostream>
    #include <unordered_map>
    #include <functional>
    #include "src/core/text_canvas.h"
    #include "src/core/shop/registry/item_registry.h"
    #include "src/core/shop/game_state.h"

    namespace ShopGame {

    class Game {
    public:
    Game();
    ~Game();
    Game(int canvasWidth, int canvasHeight, std::string gameName);
    void start();
    void update(GameRenderer::TextCanvas* canvas);
    void clean();
    void render();
    const bool isRunning();
    void setRunning(bool val);
    GameRenderer::TextCanvas* getCanvas();
    void addCommand(const std::string& command, const std::function<void(Game*)> function);
    void processInput(const std::string& input);
    std::string getName();
    void setGameState(ShopGame::GameState* state);
    ShopGame::GameState* getGameState();
    ShopGame::GameState* getPreviousState();

    private:
    ShopGame::GameState* prevState;
    ShopGame::GameState* currentState;
    bool running;
    std::string gameName;
    GameRenderer::TextCanvas* canvas;
    std::unordered_map<std::string, std::function<void(Game*)>> commandMap;
    void handleInput(const std::string& input);
    void registerCommands();

    friend void displayItemList(GameRenderer::TextCanvas* canvas, const std::unordered_map<std::string, ItemRegistry::ItemFactory>& itemList, const std::string& displayTitle, const Vec2& topLeft, int maxWidth, int itemWidth, int itemHeight, int maxItemCount);
    };

    } // namespace ShopGame