From 64f6f1eaa2ecc188292cfe4a7223606b8bcb3bf2 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 20 Mar 2020 10:29:56 +0100 Subject: refactoring to more cplusplusy version of classes --- include/game.hpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'include/game.hpp') diff --git a/include/game.hpp b/include/game.hpp index 62a024c..5e01b0d 100644 --- a/include/game.hpp +++ b/include/game.hpp @@ -1,6 +1,8 @@ #ifndef GAME_HPP # define GAME_HPP +#include +#include #include #include #include @@ -9,23 +11,27 @@ class Game { public: - Game(int s); + Game(int size); + Game(Game const &other); + Game &operator=(Game const &other); ~Game(); - int getSize(); - int getScore(); - int at(int x, int y); - void move(Direction direction); + int getSize() const; + int getScore() const; + int get(int y, int x) const; + bool move(Direction direction); void spawn(); - bool lost(); + bool lost() const; private: - int size; - int **grid; - int score; + int m_size; + int m_score; + int **m_grid; + void mergeRow(std::vector &row); - int **gridCopy(); - bool gridEqual(int **other); - void gridDestroy(int **g); }; +bool operator==(Game const &a, Game const &b); +bool operator!=(Game const &a, Game const &b); +std::ostream &operator<<(std::ostream &out, Game const &game); + #endif -- cgit