need help making making a dos text adventure
Although I am getting pretty good at DirectX, I decided I would try my hand at making the best Text Adventure ever. I am using pure DOS code, as I don''t want to mess with windows inits to use the GDI. But since I have little experience with legacy DOS, I need some help. I have been looking at my old C for Dummies books from yesteryear, but they use older DOS libraries and such, not the "new" stuff that Visual C++ 5.0 has. Here are my two questions:
1) How do you clear the screen in pure text mode?
2) When I use printf() to print text to the screen, how do I relocate the position of the cursor? (ie if the cursor is at the bottom of the screen, how would I relocate it to the upper-right to print some stats or something?)
To use both of the following functions, #include <conio.h>
To clear the screen, use clrscr();
To reposition the cursor, use gotoxy();
This stuff works in BC. Don't blame me if it doesn't in VC... Anyway, BC 5.5 is free for download, so get it.
Edited by - abe_bcs on 4/6/00 1:57:06 AM
To clear the screen, use clrscr();
To reposition the cursor, use gotoxy();
This stuff works in BC. Don't blame me if it doesn't in VC... Anyway, BC 5.5 is free for download, so get it.
Edited by - abe_bcs on 4/6/00 1:57:06 AM
/ // / |< <-
Those functions don''t work in VC. Where can I get BC 5.5? Is it easy to use?
In VC++ console program, to clear the screen you can use: system("cls")
To reposition the cursor is a little trickier. I created a little wrapper function. I don't think (or at least can't get to work) the standard C and C++ libraries for output like cout or printf get positioned correctly with these functions. You have to use like WriteConsole, I think. This function I have hear draws text at the X and Y location specified. Look up "console functions" or one of the functions themselves in the VC++ help for documenation on these functions.
void draw_text(char* text, int x, int y)
{
//this is the structure that holds the x and y position that the text will be drawn to
COORD pos;
//this holds the length of the text we will draw which is needed by WriteConsole()
DWORD length = strlen(text);
//this initializes the screen buffer HANDLE structure needed to be passed to several console functions
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
//this fills in the x and y position used for SetConsoleCursorPosition()
pos.X = x;
pos.Y = y;
//this changes the cursor position with the x, y coordinates we set above
SetConsoleCursorPosition(handle, pos);
//this writes out the actual text with the location being already set in previous functions
WriteConsole(handle, text, length, &length, NULL);
}
An example program that uses that function:
#include "windows.h"
void draw_text(char* text, int x, int y);
void main()
{
draw_text("This is text", 2, 2);
}
//the draw_text() function goes here
Edited by - Sheltem on 4/7/00 12:52:04 AM
To reposition the cursor is a little trickier. I created a little wrapper function. I don't think (or at least can't get to work) the standard C and C++ libraries for output like cout or printf get positioned correctly with these functions. You have to use like WriteConsole, I think. This function I have hear draws text at the X and Y location specified. Look up "console functions" or one of the functions themselves in the VC++ help for documenation on these functions.
void draw_text(char* text, int x, int y)
{
//this is the structure that holds the x and y position that the text will be drawn to
COORD pos;
//this holds the length of the text we will draw which is needed by WriteConsole()
DWORD length = strlen(text);
//this initializes the screen buffer HANDLE structure needed to be passed to several console functions
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
//this fills in the x and y position used for SetConsoleCursorPosition()
pos.X = x;
pos.Y = y;
//this changes the cursor position with the x, y coordinates we set above
SetConsoleCursorPosition(handle, pos);
//this writes out the actual text with the location being already set in previous functions
WriteConsole(handle, text, length, &length, NULL);
}
An example program that uses that function:
#include "windows.h"
void draw_text(char* text, int x, int y);
void main()
{
draw_text("This is text", 2, 2);
}
//the draw_text() function goes here
Edited by - Sheltem on 4/7/00 12:52:04 AM
I''ve emailed CoolMike a collection of old DOS C code, from one of my ''History'' books!
It''s actually PC Intern circa 1992!
If anyone else would like to see it email me.
Cheers
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
It''s actually PC Intern circa 1992!
If anyone else would like to see it email me.
Cheers
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
Thanks guys, I got both things working. But now I have two more questions. How do I get rid of the DOS mouse cursor that appears when I switch the app to fullscreen, and how can I get the game to start immediately in fullscreen when run from windows (or run after the build)?
Did you find that stuff really useful?
I was hoping to get into PC programming in those early days, but it was just too much all at once...
Anyway, if you get it to run full-screen, there should not be a DOS mouse cursor! To get it to run full-screen in the first place, adjust the settings of the short-cut icon under win9x.
If you want a partner for a text based adventure, give me a mail. I started one in 1995 for Qbasic that I recently unearthed. It still looks good to me!
Later
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
I was hoping to get into PC programming in those early days, but it was just too much all at once...
Anyway, if you get it to run full-screen, there should not be a DOS mouse cursor! To get it to run full-screen in the first place, adjust the settings of the short-cut icon under win9x.
If you want a partner for a text based adventure, give me a mail. I started one in 1995 for Qbasic that I recently unearthed. It still looks good to me!
Later
Matt
Check out my project at: www.btinternet.com/~Matthew.Bennett
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement