I'm trying to use the colored Ansi/Ascii Characters (particularly form Code Page 437) for a console game that I'm making. When I discovered Code Page 437, I found some very useful characters that I could use, but I have no idea as to how I would implement them into my code. Does anybody know how to insert colored Ansi/Ascii chars into the C++ console?
Curses.
[QUOTE=boombon;32797180]I'm trying to use the colored Ansi/Ascii Characters (particularly form Code Page 437) for a console game that I'm making. When I discovered Code Page 437, I found some very useful characters that I could use, but I have no idea as to how I would implement them into my code. Does anybody know how to insert colored Ansi/Ascii chars into the C++ console?[/QUOTE]
If you're trying to do a roguelike style game (with windows, etc), then I second the recommendation for using Curses (pdcurses if you want cross platform)
Otherwise, you can take a look at my [url=https://github.com/mnmlstc/hue]Hue library[/url], which lets you write colored text as if it were a C++ iostream. (The code is also under a BSD License, so you can just rip it straight from the code. It's nothing special, really :P)
Yeah, curses is the way to go.
Stolen shamelessly off the internet
[code]#include <iostream>
#include <windows.h>
using namespace std;
HANDLE hCon;
enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };
void SetColor(Color c){
if(hCon == NULL)
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon, c);
}[/code]
Thats pretty much how i wrote the graphical part of my first game, in ascii
Then you get platform locked.
[QUOTE=Jookia;32801340]Then you get platform locked.[/QUOTE]
As far as i can remember, that runs/ran perfectly well through wine last time i tried it. ( Edit: Im a moron :v: )
Im not saying its the best solution, just an easy one if you are lazy and not bothered about compiling for something other than windows
[QUOTE=Icedshot;32801401]As far as i can remember, that runs/ran perfectly well through wine last time i tried it.
Im not saying its the best solution, just an easy one if you are lazy and not bothered about compiling for something other than windows[/QUOTE]
[quote]well through wine[/quote]
That's like me writing a game for a console and saying it works well in an emulator. That doesn't mean it's no platform locked at all.
[QUOTE=BlkDucky;32801468]That's like me writing a game for a console and saying it works well in an emulator. That doesn't mean it's no platform locked at all.[/QUOTE]
Looking back on it, that post is really badly worded. I dont mean its cross platform, I dont even know what i really meant with that :v:
What it should have said really is: its a cheap easy, and not particularly great solution if you are too lazy to delve into something like Curses and arn't too bothered about getting the thing to compile on linux. Which, most beginners-intermediates on windows who are writing an ascii based game arn't.
[QUOTE=Icedshot;32802029]Looking back on it, that post is really badly worded. I dont mean its cross platform, I dont even know what i really meant with that :v:
What it should have said really is: its a cheap easy, and not particularly great solution if you are too lazy to delve into something like Curses and arn't too bothered about getting the thing to compile on linux. Which, most beginners-intermediates on windows who are writing an ascii based game arn't.[/QUOTE]
I'd say it's pretty bad practice to write your code to be platform locked, regardless of your code going to be cross-platform or not.
The reason is pretty simple. Most platform-locking code is non-standard code (and Microsoft standards don't count), giving you a pretty darn hard time converting your code to standard, if you ever want to write for more than one platform.
It's ALWAYS better to follow the standards and try to stay neutral.
It'll usually pay of well in the long run, and even in the short run in many cases.
Sorry, you need to Log In to post a reply to this thread.