Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Idiot22

Pages: [1]
1
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
   }
}
 

2
So I have to code Conway's game of life using QT and SFML. I have a text version of the game and have to add graphics to it with SFML. The way my professor said we should do it is by drawing multiple rectangles (with an array) on the screen, like a grid, with each one being connected to the neighborhood array (the first rectangle is connected to (array)[0][0] and determines whether to print or not depending on if the cell is alive or dead). HOw can I do this?

Pages: [1]