Sign in to follow this  

Is there a way to make this console program portable?

This topic is 2000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
[quote]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.[/quote]

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

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.

Share this post


Link to post
Share on other sites
[quote name='Alkhzar' timestamp='1340069642' post='4950450']
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?
[/quote]

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)

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1340091615' post='4950511']
[quote]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.[/quote]

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

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.
[/quote]
[img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img] Occasionally I forget about that. Your code is what I was thinking of, so yes, something in that vein.

Share this post


Link to post
Share on other sites
[quote name='Alkhzar' timestamp='1340069642' post='4950450']
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!
[/quote]
Certainly. For RPGs using the console, some fall into the [url="http://roguebasin.roguelikedevelopment.org/index.php/Main_Page"]Roguelike[/url] 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 [url="http://en.wikipedia.org/wiki/Interactive_fiction"]Text Adventure[/url].

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

Share this post


Link to post
Share on other sites
Nice info Narf! I was snooping around the internet and came across this article. [url="http://www.cplusplus.com/articles/G13hAqkS/"]http://www.cplusplus.com/articles/G13hAqkS/[/url]
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?

Share this post


Link to post
Share on other sites
[quote name='Alkhzar' timestamp='1340155388' post='4950796']
Nice info Narf! I was snooping around the internet and came across this article. [url="http://www.cplusplus.com/articles/G13hAqkS/"]http://www.cplusplus...icles/G13hAqkS/[/url]
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?
[/quote]
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?

Share this post


Link to post
Share on other sites
[quote name='Narf the Mouse' timestamp='1340156969' post='4950800']
[quote name='Alkhzar' timestamp='1340155388' post='4950796']
Nice info Narf! I was snooping around the internet and came across this article. [url="http://www.cplusplus.com/articles/G13hAqkS/"]http://www.cplusplus...icles/G13hAqkS/[/url]
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?
[/quote]
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?
[/quote]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!

Share this post


Link to post
Share on other sites

This topic is 2000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this