classDiagram
IGame : +virtual void compute(queue<Event> &eventQueue)
IGame : +virtual Data &getData()
Core :
Global :
IGraphical : virtual void display(Data &data)
IGraphical : virtual void catchEvent(queue<Event> &eventQueue)
IGame <|-- AGame
AGame <|-- Snake
AGame <|-- Minesweeper
AGame <|-- Menu
Core <|-- Core_hpp
Core <|-- DLLoader
Core <|-- LibLister
Global <|-- Data
Global <|-- Event
Global <|-- ScoreManager
IGraphical <|-- AGraphical
AGraphical <|-- SFML
AGraphical <|-- SDL2
AGraphical <|-- NCurses
class ScoreManager {
+long get(const string &gameName) const
+void set(const string &gameName, long score)
+bool isNumber(const string &str) const
+size_t getStringStreamLength(stringstream &&ss) const
+bool isScoreboardSane() const
}
class Event {
+enum class Type
+Type getType() const
+pair<int, int> getMousePosition() const
+bool isKeyboardEvent() const
+bool isMouseEvent() const
+Type _type
+int _mouseX
+int _mouseY
}
class Data {
+vector<std::vector<int>> &getGameMap()
+map<int, pair<string, char>> &getMapReferences()
+pair<string, char> getReference(int label) const
+vector< Text> &getTexts()
+void setGameMapCell(size_t x, size_t y, int value)
}
class NCurses {
+void display(Data &data) final
+void catchEvent(queue<Event> &eventQueue) final
+static const unordered_map<int, Type> eventMap
+void manageMouseEvents(queue<Event> &eventQueue)
+void drawLine(int length) const
+void drawMap(Data &data)
+void displayChar(int label, map<int, pair<string, char>> mapRefs) const
+void displayTexts(vector< Text> &texts)
+pair<int, int> getTilePosFromMouseClick(const int mouseX, const int mouseY)
+WINDOW *_window
+pair<size_t, size_t> _startPos
+pair<size_t, size_t> _mapPos
+size_t _textsN
}
class SDL2 {
+void display(Data &data) final
+void catchEvent(queue<Event> &eventQueue) final
+static const unordered_map<SDL_Keycode, Type> _eventMap
+void setChunk(const string &filepath, const SDL_Rect &pos)
+void setExtras(const Text &extras)
+pair<int, int> getTilePosFromMouseClick(const int mouseX, const int mouseY)
+shared_ptr <SDL_Surface> _surface
+shared_ptr <SDL_Window> _window
+shared_ptr<SDL_Renderer> _renderer
+SDL_Event _event
+bool _isRunning
}
class SFML {
+static const unordered_map<Key, Type> _eventMap
+void display(Data &data) final
+void catchEvent(queue<Event> &eventQueue) final
+void setChunk(const string &filepath, const Vector2f &chunkPos)
+void setExtras(const Text &extras)
+pair<int, int> getTilePosFromMouseClick(const int mouseX, const int mouseY)
+RenderWindow _window
}
class AGraphical {
+size_t _matrixWidth
+size_t _matrixHeight
}
class LibLister {
+void display() const
+vector<string> &getGameLibs()
+vector<string> &getGraphicalLibs()
+string getLibDirectory() const
+bool isGameLib(const string &path) const
+bool isGraphicalLib(const string &path) const
+int getIndexGame(const string &path) const
+int getIndexGraphical(const string &path) const
+const string _libDirectory
+vector<string> _gameLibs
+vector<string> _graphicalLibs
}
class DLLoader {
+T *getInstance(const std::string &instanceName) const
+void *_lib
}
class Core_hpp {
+enum Libtype
+unique_ptr<IGame> &getGame()
+unique_ptr<IGraphical> &getGraphical()
+queue<Event> &getEventQueue()
+void run()
+bool handleEvents()
+void handleLibSwitch()
+void libSwitch(Libtype type, size_t toLoad)
+size_t libGetNext(Libtype type)
+void menuHandler()
+arcade::LibLister _libLister
+size_t _menuLib
+unique_ptr<DLLoader> _graphLoader
+unique_ptr<DLLoader> _gameLoader
+unique_ptr<IGraphical> _graphical
+unique_ptr<IGame> _game
+queue<Event> _eventQueue
+size_t _loadedGame
+size_t _loadedGraphical
}
class AGame{
+enum HighScoreState
+HighScoreState _highScore
+Data _data
+virtual void compute(queue<Event> &eventQueue)
+Data getData() final
+bool setHighScore(const std::string &gameName, long score)
}
class Snake {
+enum GameState
+enum Direction
+enum Chunk
+SnakeTile
+Food
+void compute(queue<Event> &eventQueue)
+void reset()
+void init_mapReferences(Data &data)
+void addReference(int label, string path, char symbol, Data &data)
+void move()
+void handleTexts()
+bool colision(pair<int, int> pos)
+void directionSwitch(pair<int, int> &pos, Direction direct)
+void handleEvents(queue<arcade::Event> &eventQueue)
+void eventMoveSwitch(Event &event)
+void setMapTile(pair<int, int> pos, Chunk label)
+void drawSnake()
+void drawSnakeHead(int i)
+void drawSnakeTail(int i)
+void drawSnakeBody(int i)
+void eat()
+int getMapTile(pair<int, int> pos)
+pair<int, int> elongateSnakeX(Direction direct, pair<int, int> pos)
+pair<int, int> elongateSnakeY(Direction direct, pair<int, int> pos)
+GameState _gameState
+time_point _startTime
+time_point _timeRef
+time_point _currentTime
+int _snakeLen
+Direction _direction
+deque<SnakeTile> _snakeTiles
+Food _food
}
class Minesweeper {
+Tile
+enum GameStatus
+void compute(queue<Event> &eventQueue) final
+void setGame()
+Tile &getTile(size_t x, size_t y)
+void mapDisplay()
+void initData()
+void initMap()
+void refreshMapData(size_t x, size_t y)
+void mine(pair<int, int> mousePos)
+void flag(pair<int, int> mousePos)
+bool areCoordsInRange(size_t x, size_t y)
+void iterAround(size_t x, size_t y, void (*callback)(size_t, size_t))
+void firstMoveManager(size_t x, size_t y)
+bool isGameWon()
+void revealMines()
+void inputManager(Event &evt)
+void setTexts()
+void incrTile(size_t x, size_t y)
+void revealTile(size_t x, size_t y)
+void revealTileIfZero(size_t x, size_t y)
+const size_t _matrixWidth
+const size_t _matrixHeight
+const size_t _nbBombs
+size_t _bombsLeft
+size_t _score
+time_point _timer
+int64_t _elapsedTime
+GameStatus _status
+bool _firstMove
+:vector<vector<Tile>> _map
}
class Menu {
+enum Chunk
+void compute(queue<arcade::Event> &eventQueue) final
+void handleTexts()
+void handleEvents(queue<Event> &eventQueue)
+void init_mapReferences(Data &data)
+void addReference(int label, string path, char symbol, Data &data)
+void setLibsNames()
+void eventSwitch(Event &event)
+void runGame()
+size_t _selectedGraphic
+size_t _selectedGame
+vector<string> _gameLibs
+vector<string> _graphicLibs
}
To add a new game in this arcade, you must follow these steps:
- Create a folder in
src/games
andinclude/games
folders (example:src/games/snake
/include/games/snake
). - In this folder in
src
, create a Makefile that will compile your game and put.o
in abin
folder (you can have an example here). - Your lib must follow this format
arcade_[game_name].so
in./lib
folder. - Add your Makefile in the global
./Makefile
inGAMES
section. - Your main class of your game must add these extern C functions:
extern "C"
{
bool isGame()
{
return true;
}
arcade::IGame *entryPoint()
{
return new arcade::[YOUR_GAME_CLASS];
}
}
- Your game must inherit from
AGame
and implement at least functions inIGame
andAGame
- Compile and test it !
Note: You can't launch your game directly with
./arcade lib/aracade_game.so
, this is only with graphical lib and you will select your game in the menu
To add a new graphical library in this arcade, you must follow these steps:
- Create a folder in
src/graphicals
andinclude/graphicals
folders (example:src/graphicals/SDL2
/include/graphicals/SDL2
). - In this folder in
src
, create a Makefile that will compile your graphical lib and put.o
in abin
folder (you can have an example here). - Your lib must follow this format
arcade_[graphical_lib_name].so
in./lib
folder. - Add your Makefile in the global
./Makefile
inGRAPHICALS
section. - Your main class of your game must add these extern C functions:
extern "C"
{
bool isGame()
{
return false;
}
arcade::IGraphical *entryPoint()
{
return new arcade::[YOUR_GRAPHICAL_LIB_CLASS];
}
}
- Your game must inherit from
AGraphcial
and implement at least functions inIGraphcial
andAGraphcial
- Compile and test it !
- commands must always be added at the end of the arcade::Data._texts vector
- commands always begin with "$-"
- commands can be added in chain
- a colon must be used to separate the command from the value "$-cmd:value"
- swgme / swgrc
- swply
- score
Graphical or game library switching. Commands : "$-swgrc" for graphical or "$-swgme" for game. Following the Commands must be colons and the lib name or the keyword $next.
Here are some examples:
- "$-swgme:$next"
- "$-swgme:$arcade_snake.so"
- "$-swgrc:$next"
- "$-swgrc:$arcade_sfml.so"
$next switches to the next available lib, ignoring the menu.
Change stored player name. Following the Command must be colons and the player name.
Here are some examples:
- "$-swply:duckling"
- "$-swply:iamtheplayer"
Add new score to the leaderboard if it is a high score. Following the Command must be colons and the score as a number.
Here are some examples:
- "$-score:54"
- "$-score:147526"
- "$-score:0"
Library names are passed to menu from core through the arcade::Data._texts vector of the menu under the following format: ["game1.so", "game2.so", ":", "graphical1.so", "graphical2.so", "$-libs"] the vector is emptied by the menu after recuperating the libraries.