This what I have. When I try to run it all I get is a blank window.
#include "game.h"
#include <gol_functions.h>
#include <iostream>
using namespace std;
Game::Game(){
window.create(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Game of Life");
window.setFramerateLimit(60);
int x=10;
int y=10;
initialize(world);
for (int i=0; i<MAX; i++)
{
for (int j=0; j<COL; j++)
{
int n;
n=count_neighbors(world, rowpos, colpos);
if (n<2 || n>3){
box[i][j].setFillColor(sf::Color::Black);
}
if (n==3)
{
box[i][j].setFillColor(sf::Color::Red);
}
box[i][j].setSize(sf::Vector2f(20, 20));
box[i][j].setPosition(sf::Vector2f(x+=25, y+=25));
}
}
}
void Game::Draw(){
//Look at the data and based on the data, draw shapes on window object.
// window.draw(box);
for (unsigned int i = 0; i <MAX ; i++)
{
for (int j=0; j<COL; j++)
{
window.draw(box[i][j]);
}
}
}
void Game::update()
{
play=true;
do
{
next_gen(world, rowpos, colpos);
}while(play);
}
void Game::render(){
window.clear();
Draw();
window.display();
}
void Game::processEvents()
{
sf::Event event;
while (window.pollEvent(event))//or waitEvent
{
// check the type of the event...
switch (event.type)
{
// window closed
// "close requested" event: we close the window
case sf::Event::Closed:
window.close();
break;
// key pressed
case sf::Event::KeyPressed:
switch(sf::Event::KeyPressed)
{
case 'p':
case 'P':
if (play)
{
play=false;
}
if (!play)
{
play=true;
}
break;
case 's':
case 'S':
save_neighborhood(world);
break;
case 'R':
case 'r':
initialize(world);
break;
default:
break;
}
break;
default:
break;
}
}
}
void Game::run()
{
while (window.isOpen())
{
processEvents();
update();
render(); //clear/draw/display
}
}