First main created

This commit is contained in:
krilius 2015-04-29 15:42:41 +04:00
parent 08113f5b6d
commit 3840053da7
7 changed files with 112 additions and 694 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}
}

View file

@ -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

View file

@ -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);
Grid * grid = new Grid();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
grid->description();
window.clear();
window.draw(shape);
window.display();
}
return 0;
return 0;
}