• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Is there a way to make this console program portable?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

13 replies to this topic

### #1Alkhzar  Members

Posted 18 June 2012 - 09:09 AM

Hello all! I recently created a console program using Dev-C++. The program took a few days to write, but it is still not complete. As it stands, the program is currently using a <windows.h> header to change the background/foreground color of the console and to set the console cursor position to 0. I would like this program to be able to run on non-windows operating systems, but I dont know how to go about doing that. The code is in the attached file.
(Warning: noob code).

### #2Goran Milovanovic  Members

Posted 18 June 2012 - 03:36 PM

As far as I know, there is no "cross-platform" way to change console/terminal colors.

On unix based operating systems (linux, mac, etc) there is a library called ncurses, which can be used to manipulate the terminal in various ways (this library is not available on windows).

So, ultimately, I think you'll have to write a render function that will have two implementations: one for windows, using whatever you're using now, and one for unix based systems, using ncurses.

+---------------------------------------------------------------------+

| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

### #3Dragonsoulj  Members

Posted 18 June 2012 - 03:44 PM

Going on what Goran said, you will do an operating system check at the start of your program and decide which function/functions you want to use to change colors. You will use your <Windows.h> functions if the OS is Windows and if not, use NCurses.

### #4ApochPiQ  Moderators

Posted 18 June 2012 - 04:45 PM

I've heard reasonable things about PDCurses but haven't actually used it, so take with appropriate measure of salt.
Wielder of the Sacred Wands

### #5Alkhzar  Members

Posted 18 June 2012 - 07:34 PM

Thanks for the cool advice! I like the OS check idea! I was trying to do as much as I could with the console without the use of NCurses, PDCurses, etc. I never used those libraries so I don't know how to work with them yet, but I'll look into it!

First: So is there a way I could change the color of the console and set the cursor to the 0 position in the unix based OS' console without the use of external libraries? Or is using NCurses the only way?

Second: I had a lot of fun trying to make this program on the console, The challenges felt great to overcome, and the feeling I got when I first tried out the program was even better! Programming is amazing!!!! My goal is to try to emulate an event driven mini-rpg in the console. Is this too much or impossible? If anyone has an example of what I'm trying to do, please let me review it!!!! It would be great to see that I'm not alone!

Any advice or tips on what I should do next would be appreciated!

### #6Dragonsoulj  Members

Posted 18 June 2012 - 08:57 PM

### #7Bacterius  Members

Posted 19 June 2012 - 01:40 AM

Going on what Goran said, you will do an operating system check at the start of your program and decide which function/functions you want to use to change colors. You will use your <Windows.h> functions if the OS is Windows and if not, use NCurses.

Uhh I am unsure how you will be doing an OS check within the program itself considering Windows and Linux do not run the same executable format. I think you meant conditional compilation as such:
#ifdef WIN32
#include <windows.h>
#else
#include <ncurses.h>
#endif


Or something in that vein. So that when you build your program you get two outputs - one for Windows and one for Linux, and they will both use their respective libraries.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #8SimonForsman  Members

Posted 19 June 2012 - 02:11 AM

Thanks for the cool advice! I like the OS check idea! I was trying to do as much as I could with the console without the use of NCurses, PDCurses, etc. I never used those libraries so I don't know how to work with them yet, but I'll look into it!

First: So is there a way I could change the color of the console and set the cursor to the 0 position in the unix based OS' console without the use of external libraries? Or is using NCurses the only way?

curses isn't really an external library, it is the standard library for console manipulation in UNIX (it is part of the UNIX specification), ncurses is the modern replacement for it and is part of Linux, BSD and OS X. (ncurses is backwards compatible with curses so if you include curses.h rather than ncurses.h and restrict yourself to the old curses API you should be able to build your app on any *nix system released after ~1983)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

### #9Alkhzar  Members

Posted 19 June 2012 - 07:26 AM

Thanks Everyone for the info! This really clears things up for me. Guess I should give one of those Curses a try!

### #10Dragonsoulj  Members

Posted 19 June 2012 - 05:48 PM

Going on what Goran said, you will do an operating system check at the start of your program and decide which function/functions you want to use to change colors. You will use your <Windows.h> functions if the OS is Windows and if not, use NCurses.

Uhh I am unsure how you will be doing an OS check within the program itself considering Windows and Linux do not run the same executable format. I think you meant conditional compilation as such:
#ifdef WIN32
#include <windows.h>
#else
#include <ncurses.h>
#endif


Or something in that vein. So that when you build your program you get two outputs - one for Windows and one for Linux, and they will both use their respective libraries.

Occasionally I forget about that. Your code is what I was thinking of, so yes, something in that vein.

### #11Narf the Mouse  Members

Posted 19 June 2012 - 06:42 PM

Second: I had a lot of fun trying to make this program on the console, The challenges felt great to overcome, and the feeling I got when I first tried out the program was even better! Programming is amazing!!!! My goal is to try to emulate an event driven mini-rpg in the console. Is this too much or impossible? If anyone has an example of what I'm trying to do, please let me review it!!!! It would be great to see that I'm not alone!

Any advice or tips on what I should do next would be appreciated!

Certainly. For RPGs using the console, some fall into the Roguelike subcategory.

Typical attributes of a roguelike include:

1) Is an RPG.
2) Uses dynamically-created content (rather than content being created before the game, the game itself creates some or all of the content).
3) Uses text as a display - 'T' to represent a tree, for example.
4) Permadeath - That is, if your character dies, that game is over and your save is erased. This makes Roguelikes one of the few types of games that fully qualify as a challenge.

OTOH, you may be thinking of a text adventure - Zork is a classic example of a Text Adventure.

Typical attributes of a text adventure include:

1) It's a puzzle game.
2) Uses entirely pre-generated and often very deep content.
3) Everything is represented by descriptive text and/or relatively static pictures.
4) Commands are given in the form of short sentences usually with no more than one noun, verb and/or object.

Edited by Narf the Mouse, 19 June 2012 - 06:42 PM.

### #12Alkhzar  Members

Posted 19 June 2012 - 07:23 PM

Nice info Narf! I was snooping around the internet and came across this article. http://www.cplusplus.com/articles/G13hAqkS/
It pretty much puts down what I'm trying to do, but I understand where the OP is coming from. For instance, the console is not the best medium for event driven games.
Does anyone else think its a good idea for me to start working with graphics instead of the console?

### #13Narf the Mouse  Members

Posted 19 June 2012 - 07:49 PM

Nice info Narf! I was snooping around the internet and came across this article. http://www.cplusplus...icles/G13hAqkS/
It pretty much puts down what I'm trying to do, but I understand where the OP is coming from. For instance, the console is not the best medium for event driven games.
Does anyone else think its a good idea for me to start working with graphics instead of the console?

Does the type of games we want to make, matter to the type of game you want to make? Should it? How and how much?

### #14Alkhzar  Members

Posted 19 June 2012 - 08:25 PM

Nice info Narf! I was snooping around the internet and came across this article. http://www.cplusplus...icles/G13hAqkS/
It pretty much puts down what I'm trying to do, but I understand where the OP is coming from. For instance, the console is not the best medium for event driven games.
Does anyone else think its a good idea for me to start working with graphics instead of the console?

Does the type of games we want to make, matter to the type of game you want to make? Should it? How and how much?

I totally agree with you. I like what I've been doing. The challenges of trying to make the console work the way I want it to feel great to overcome!
I also have been wanting to get back into programming games with graphics like I did in high school (2005), but I've just recently got back into programming, and I've forgotten many things. I'm relearning everything one step at a time.

The reason I was trying to make a Roguelike style game in the console was that I thought doing so would make programming graphics games easier. In other words I dont have much confidence in my moving up to Graphical games.

So a little question. Based on the program I made in the console, does anything think I'm ready to move on to programming graphical games?
The program I made was pretty basic. I've also made text based RPG's in the console with a battle system, an inventory, some quests, and etc.

Any advice/constructive criticism would be very much appreciated!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.