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

Author Topic: Conway's game of Life (implementation in C++ and SFML)  (Read 6602 times)

0 Members and 1 Guest are viewing this topic.

The Illusionist Mirage

  • Full Member
  • ***
  • Posts: 115
  • My Life = Linux, C++ & Computers
    • View Profile
    • fleptic
    • Email
Conway's game of Life (implementation in C++ and SFML)
« on: May 15, 2014, 06:24:39 am »
Hello Programmers!

I just wrote a simple clone of the famous Conway's Game of Life as a programming practice. You can find the source here. To compile the code for the SFML version, add the preprocessor RENDERER_SFML. Or else the program will compile the terminal version.

Below are a few screenshots:







I'd be grateful if you provide some critics/comments on the code.
Thanks!
« Last Edit: May 15, 2014, 07:12:46 am by The Illusionist Mirage »

amhndu

  • Newbie
  • *
  • Posts: 42
  • Err, err and err again, but less, less and less
    • View Profile
    • amhndu.github.io
    • Email
Re: Conway's game of Life (implementation in C++ and SFML)
« Reply #1 on: May 16, 2014, 03:07:25 am »
Nice work !  :)
Quote
I'd be grateful if you provide some critics/comments on the code.
#if defined(_WIN32)
    #include <windows.h>
    #define SLEEP Sleep
    #define SLEEP_TIME 200
    #define CLEAR_SCREEN system("cls")

#else
    #include <unistd.h>
    #define SLEEP usleep
    #define SLEEP_TIME 200 * 1000
    #define CLEAR_SCREEN system("clear")
#endif
 
You shouldn't be using system() call , it's bad practice , here's why.
If you want to clear console , you can do these.
And why aren't you using sf::sleep() ?

Everything else looks good.

The Illusionist Mirage

  • Full Member
  • ***
  • Posts: 115
  • My Life = Linux, C++ & Computers
    • View Profile
    • fleptic
    • Email
Re: Conway's game of Life (implementation in C++ and SFML)
« Reply #2 on: May 16, 2014, 10:42:55 am »
Quote from: ahmndu
You shouldn't be using system() call , it's bad practice , here's why.
Yes sir, I know that using system() is a bad practice and had already gone through the article you gave me sometime ago.

Quote from: ahmndu
If you want to clear console , you can do these.
I've read that article also. Well I didn't want to use boost(since I'd have to use its addstr() and getnstr() functions and can't use std::cout and std::cin simultaneously). I'd also tried creating a clearScreen() function that'd print multiple newlines but I couldn't really get it to work neatly. I need to clear the screen only when the code is compiled in the terminal mode(i.e., without using SFML).

If any observation of mine in the previous facts are erroneous, please correct me.

Quote from: ahmndu
And why aren't you using sf::sleep() ?
I've tried to create two versions in one program - one, the simple console version that does not require SFML and the other, the SFML version. So, in case someone compiles the terminal version(assuming he's not installed SFML), using sf::Sleep() won't help. If you can give me a better alternative than this, it's welcome.

Quote from: ahmndu
Everything else looks good.
Thanks! :D Glad you liked it!

amhndu

  • Newbie
  • *
  • Posts: 42
  • Err, err and err again, but less, less and less
    • View Profile
    • amhndu.github.io
    • Email
Re: Conway's game of Life (implementation in C++ and SFML)
« Reply #3 on: May 16, 2014, 12:21:07 pm »
Quote
Yes sir, I know that using system() is a bad practice and had already gone through the article you gave me sometime ago.
First , you don't need to sir me , I am about the same age you are (If your profile is correct) :P
Quote
I've read that article also. Well I didn't want to use boost(since I'd have to use its addstr() and getnstr() functions and can't use std::cout and std::cin simultaneously). I'd also tried creating a clearScreen() function that'd print multiple newlines but I couldn't really get it to work neatly. I need to clear the screen only when the code is compiled in the terminal mode(i.e., without using SFML).
That's okay then, your application is simple and using system() won't mean the end of the world,I just wanted to point it out if you didn't knew ...

The Illusionist Mirage

  • Full Member
  • ***
  • Posts: 115
  • My Life = Linux, C++ & Computers
    • View Profile
    • fleptic
    • Email
Re: Conway's game of Life (implementation in C++ and SFML)
« Reply #4 on: May 16, 2014, 04:40:13 pm »
Quote from: ahmndu
That's okay then, your application is simple and using system() won't mean the end of the world,I just wanted to point it out if you didn't knew ...

Yea, thanks! :)
« Last Edit: May 16, 2014, 04:53:48 pm by The Illusionist Mirage »