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.
Game class
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment