Color in console game

Well I'm making a console ascii game for my final in class. What I can't seem to figure out is how to make a specific character or line of text a different color. I can only figure out how to make everything a different color. For instance say that ► is that player character and X is the enemy computer player, How would i make those different colors? Like one blue and one red, etc.

When I did look around for a solution I saw a bunch of posts talking about using different kinds of libraries and different commands to type in and it all just confused the crap out of me. I'm still a beginner so if someone could please tell me exactly how to do it in detail i would really appreciate it. :)
@Thewildfish
Hope this is of help to you. I use this method all the time in my programs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <windows.h>

using namespace std;
using namespace System;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
/*
	black,          //  0
	dark_blue,      //  1
	dark_green,     //  2
	dark_cyan,      //  3
	dark_red,       //  4
	dark_magenta,   //  5
	dark_yellow,    //  6
	light_gray,     //  7
	dark_gray,      //  8
	light_blue,     //  9
	light_green,    // 10
	light_cyan,     // 11
	light_red,      // 12
	light_magenta,  // 13
	light_yellow,   // 14
	white           // 15
*/
// To get the color desired, take the number for background color desired, multiplied by 16.
// Then add number for the foreground.
// Like so : int color = (f_color+(b_color*16)); 
SetConsoleTextAttribute(console, color);
Last edited on
closed account (GbX36Up4)
http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles4.html
This link is the page for console color, but if you snoop around the website you will find there are several pages with tons of cool stuff that can be done with the console with no need to install any libraries. :P
Use NCurses (or PDCurses if you're on Windows; It's just a port). It's a library for using console graphics, and it fully supports colors. I use it myself and it's pretty good, though you need to use a bit of C, since that's the language the library is written in. Here's a good tutorial on how to use it: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
Last edited on
Some links to get you started with Curses, including two examples of using colors:
http://www.cplusplus.com/forum/general/41965/#msg226792
Good luck!
Topic archived. No new replies allowed.