Archived

This topic is now archived and is closed to further replies.

SonShadowCat

How would i do this in console?

Recommended Posts

SonShadowCat    122
i have seen some text games have blinking boxes around the choice the user picks, lines around the screen, etc i was wondering how do i do that? i dont want to make a visually dead game( text is dull as it is) so plz hlp me thx "Those who serve no purpose, have no purpose"

Share this post


Link to post
Share on other sites
Dactylos    122
To make blinking text you set the 7th bit (most significant) in the attribute byte of a character.

To make lines and stuff, just look at an ascii chart for the codes representing line-fragments etc. and write those codes to the screen. They should be somewhere around 170-220, or something like that (it probably depends on which codepage you''re using).

Share this post


Link to post
Share on other sites
Johnny T    122
Johnny T can tell that Dactylos thought you were making a DOS program, not a Windows 9x console program. His advice doesn''t apply to you, so Johnny T thinks its a good sign you didn''t know what he was talking about.

There are lots of functions in MSVC help. Look up SetConsoleTextAttribute in the index. Johnny T uses this to change colors of the text to print. Johnny T uses GetStdHandle(STD_OUTPUT_HANDLE) as the first parameter to that function, and then a description of the color to use as the next parameter. This is how Johnny T makes his text yellow:

// this is how Johnny T makes his text yellow
SetConsoleTextAttribute(
GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);

Johnny T thinks there is more information in the help file on how to describe colors. Johnny T uses the "Console Functions" link under the "See Also" section in the "SetConsoleTextAttribute" function reference in the "Microsoft Visual C++ 6.0 Help File" for more obscure but powerful functions on doing cool stuff in console mode. Johnny T says the only way to make text blink is to print the text, use some timing mechanism to wait a half a second or so, and then print blank spaces in place of the text. In order to print back over the same space after he just printed other stuff onto it, Johnny T has to move the cursor back to the beginning of the text so the spaces are printed in the right place. Johnny T uses the SetConsoleCursorPosition function, with the first parameter being GetStdHandle(STD_OUTPUT_HANDLE).

Johnny T thinks the best way to make a text game come alive is to use colorful language, not colorful colors. Johnny T thinks that when a text game is made by someone with a broken Shift and apostrophe key, it''s stupid. Johnny T thinks if the stupid text blinks, it looks stupid and incompetent. Johnny T hopes he made you smarter.
Johnny T made a program that does cool things with the Windows Console. Johnny T is about to paste it right here.

// Johnny T made a program that does some cool things with the Windows console

// Johnny T has to use header files
#include
#include

// Johnny T thinks "std" is ambiguous
using std::cout;
using std::cin;
using std::endl;

// Johnny T thinks "const" is ambiguous
const int BIG_WIDTH = 160;
const int BIG_HEIGHT = 50;
const int DEF_WIDTH = 80;
const int DEF_HEIGHT = 25;
const int SMALL_WIDTH = 8;
const int SMALL_HEIGHT = 2;

// Johnny T wants the program to start here
void main()
{
// Johnny T will make this text look normal
SetConsoleTitle("Welcome! - ConsoleFun.exe");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);

// Johnny T will make this text look yellow
cout << "Press Enter" << endl;
char input[256];
cin.getline(input,256);

COORD c = {BIG_WIDTH,BIG_HEIGHT};

// Johnny T will make the console buffer window big
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),c);
SMALL_RECT rect;
rect.Left = 0;
rect.Right = BIG_WIDTH - DEF_WIDTH;
rect.Top = 0;
rect.Bottom = BIG_HEIGHT - DEF_HEIGHT;

// Johnny T will make the console window itself big
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE),FALSE,&rect);

// Johnny T will change the color
SetConsoleTextAttribute
(
GetStdHandle(STD_OUTPUT_HANDLE),
BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY
);

// Johnny T will make this text black on a white background
cout << "Big!!" << endl;
cin.getline(input,256);

// Johnny T will make the console window buffer change to small
rect.Left = 0;
rect.Right = SMALL_WIDTH - BIG_WIDTH;
rect.Top = 0;
rect.Bottom = SMALL_HEIGHT - BIG_HEIGHT;

// Johnny T will make the console window itself change to small
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE),FALSE,&rect);
c.X = SMALL_WIDTH;
c.Y = SMALL_HEIGHT;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),c);

// Johnny T will change the color again
SetConsoleTextAttribute
(
GetStdHandle(STD_OUTPUT_HANDLE),
FOREGROUND_BLUE | FOREGROUND_INTENSITY
);

// Johnny T thinks this text will appear blue
cout << "Small??" << endl;
cin.getline(input,256);
}

Share this post


Link to post
Share on other sites