diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Model/Cell.cpp | 27 | ||||
| -rw-r--r-- | src/Model/Cell.hpp | 15 | ||||
| -rw-r--r-- | src/Model/Grid.cpp | 37 | ||||
| -rw-r--r-- | src/Model/Grid.hpp | 27 | ||||
| -rw-r--r-- | src/main.cpp | 24 |
5 files changed, 110 insertions, 20 deletions
diff --git a/src/Model/Cell.cpp b/src/Model/Cell.cpp index e69de29..24fc53c 100644 --- a/src/Model/Cell.cpp +++ b/src/Model/Cell.cpp @@ -0,0 +1,27 @@ +#include "Cell.hpp" + +// Constructors + +Cell::Cell() +{ + m_value = " "; +} + +Cell::Cell(std::string value) +{ + m_value = value; +} + +// Destructor + +Cell::~Cell() +{ +} + +// Description + +void Cell::description() +{ + return m_value; +} + diff --git a/src/Model/Cell.hpp b/src/Model/Cell.hpp index 888c63c..7775bf5 100644 --- a/src/Model/Cell.hpp +++ b/src/Model/Cell.hpp @@ -1,17 +1,28 @@ #ifndef DEF_CELL #define DEF_CELL -/* Cell.cpp +/* Cell.h * Defines the class Cell * A cell represents a cell in the grid * Creators : krilius, manzerbredes * Date : 29/04/2015 */ #include <iostream> -#include <SFML/SFML.h> +#include <string> class Cell { + private: + std::string m_value; + + public: + Cell(); + Cell(std::string value); + ~Cell(); + + // Describes the cell in a terminal + std::string description(); + }; #endif diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index e69de29..94ef5d7 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -0,0 +1,37 @@ +#include "Grid.h" + +Grid::Grid(int size) +{ + m_table = std::vector<std::vector<Cell*>>(size); + for(int i = 0 ; i < size ; i++) + { + m_table[i] = std::vector<Cell*>(size); + for (int j = 0 ; j < size ; j++) + { + Cell * cell = new Cell(); + m_table[i][j] = cell; + } + } +} + +Grid::~Grid() +{ + for(int i = 0 ; i < m_table.size() ; i++) + { + for(int i = 0 ; j < m_table[i].size() ; j++) + delete m_table[i][j]; + } +} + +void Grid::description() +{ + for(int i = 0 ; i < m_table.size() ; i++) + { + for(int j = 0 ; j < m_table[i].size() ; i++) + { + std::cout << m_table[i][j]->description(); + } + std::cout << std::endl; + } +} + diff --git a/src/Model/Grid.hpp b/src/Model/Grid.hpp index e69de29..a9c6c86 100644 --- a/src/Model/Grid.hpp +++ b/src/Model/Grid.hpp @@ -0,0 +1,27 @@ +#ifndef DEF_GRID +#define DEF_GRID + +/* Grid.h + * Defines the class Grid + * A grid contains a table of cells the game will be set on + * Creators : krilius, manzerbredes + * Date : 29/04/2015 */ + +#include <iostream> +#include <vector> + +#include "Cell.hpp" + +class Grid +{ + private: + std::vector<std::vector<Cell*>> m_table; + + public: + Grid(int size); + ~Grid(); + void description(); +}; + +#endif + diff --git a/src/main.cpp b/src/main.cpp index 0d3b950..597ce39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,25 +1,13 @@ -#include <SFML/Graphics.hpp> +#include <iostream> #include <string> +#include "Model/Grid.hpp" + int main() { - sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); - sf::CircleShape shape(100.f); - shape.setFillColor(sf::Color::Green); - - while (window.isOpen()) - { - sf::Event event; - while (window.pollEvent(event)) - { - if (event.type == sf::Event::Closed) - window.close(); - } + Grid * grid = new Grid(); - window.clear(); - window.draw(shape); - window.display(); - } + grid->description(); - return 0; + return 0; } |
