Share this post

Link to post

Share on other sites

You could easily make your game multiplatform with a few minor changes, if interested.

First, cls doesn't usually exist in linux, so it just prints an error. This, however, keeps the game playable. as most terminals are 25-lines, you could replace system("cls"); with for (int i = 0; i < 25; i++) cout << endl;

Then, Sleep and windows.h doesn't exist in windows. On most platforms, (Linux, Mac, and I think every other Unix) there is another function called usleep, defined in unistd.h, with microsecond precision, so you can do:

Share this post

Link to post

Share on other sites

Original post by ravengangrelFirst, cls doesn't usually exist in linux, so it just prints an error. This, however, keeps the game playable. as most terminals are 25-lines...

So you are replacing platform dependency with assumptions. My terminal is 80 characters wide and 26 characters high. What do you think would annoy people more, the fact that they can only play it on Windows, or that it doesn't work well on any system.

@tnutty: You use a loop else while(play == 'y' || play == 'Y') ... but don't set play at the end of the loop and you exit() once the game is over. Either remove the while loop or ask the player at the end if they want to play again.

Share this post

Link to post

Share on other sites

However, as far as I know you can't (easily, at least) change the console size on windows, so it would still work on windows and also on most other platforms.

We can replace the 25 with a 200, then it will be work on any terminal with <= 200 lines. It seems good enough from the user's view. Then we are again assuming the user's terminal won't have more than 200 lines.

We can also make good ol'#ifdef WIN32 #define CLEAR_SCREEN system("cls");#else #define CLEAR_SCREEN system("clear");#endifBut again we are assuming every platform different from windows will have the "clear" command.

We can also check every operating system out there, and add an #elif for each. But then we are ignoring future platforms.

Even more, the OP is assuming the user has a terminal, which could not be true.

Hey, I just wanted to show the OP a quick and easy way to go multiplatform, without giving boring details, because most people aren't interested in anything but windows, and if the OP decided not to ignore my post, he can investigate further on his own or just keep asking here.

Don't take me wrong, please. You made a good point. But you must make some assumptions if you want to program.

0

Share this post

Link to post

Share on other sites

Probably the best way to do console stuff that is non-standard would be to create a wrapper around all the functions (using something like #ifdef WIN32 as you mentioned) or use some third-party library that is cross-platform. But i really don't think the OP needs to worry about that for just a simple little game unless they decide to actually make it cross-platform.