SFML community forums

General => SFML projects => Topic started by: The Illusionist Mirage on May 15, 2014, 06:24:39 am

Title: Conway's game of Life (implementation in C++ and SFML)
Post by: The Illusionist Mirage 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 (https://github.com/TheIllusionistMirage/Game-Of-Life). 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:

(http://puu.sh/8MS5P.png)

(http://puu.sh/8MS8G.jpg)



I'd be grateful if you provide some critics/comments on the code.
Thanks!
Title: Re: Conway's game of Life (implementation in C++ and SFML)
Post by: amhndu 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 (http://www.cplusplus.com/articles/j3wTURfi/).
If you want to clear console , you can do these (http://www.cplusplus.com/articles/4z18T05o/).
And why aren't you using sf::sleep() ?

Everything else looks good.
Title: Re: Conway's game of Life (implementation in C++ and SFML)
Post by: The Illusionist Mirage 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!
Title: Re: Conway's game of Life (implementation in C++ and SFML)
Post by: amhndu 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 ...
Title: Re: Conway's game of Life (implementation in C++ and SFML)
Post by: The Illusionist Mirage 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! :)