I want to know more about text-games.

Started by
6 comments, last by Kylotan 18 years, 10 months ago
I'm a beginner in C++. I've just read a book that mentions text-game programing. I think it's interesting and I want to know more about it(such as how to change textcolor and background color, and how to make a timer). Are there any articles? Thanks a lot.
Advertisement
a) Changing colors - it depends on the nature of your console. Is it a Win32 console window? A tty? A telnet client window?

b) Do you want the program to keep running and/or accept input while the timer is running or just to completely sleep for a given amount of time?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
1.win32 console window
2.I want to add time limit when player's making choices.

I know nothing about windows programing and I don't know how to use DirectDraw. I just want to use characters to output. As simple as possible.
1.win32 console window

The relevant documentation is there, look particularly at SetConsoleTextAttribute.

2.I want to add time limit when player's making choices.

You'll have to write custom input routines, that poll the console for input (instead of a blocked wait) and still updates the timer. In any case, if you want to have the program still do things while the player is typing stuff, multithreading is generally necessary.

Functions from <conio.h> will likely be useful.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Hi there,

If you really need to learn text-based game programming.I recommend you this book :Beginning C++ game programming.
http://www.gamedev.net/columns/books/bookdetails.asp?productid=379

This book actually helps you to start on text=based console games.Teaching timers,which you want to learn too.Everything is in c++ no directX is needed.Try this book.Is a good book to start with for beginners too.:)

Hope this helps you!

commy
If you're just interested in making text games you might want to look at the Inform programming language. It's really powerful and easy to use. Take a look at the Download the Inform Beginner's Guide to get started. Or do a web search for interactive fiction.

However, if you're interested in doing them in C++ (perhaps with the intention of later making non text based games) it's probably not for you.

If you're looking to make more of an action game, do a search for tutorials on roguelike games. Some popular ones are Nethack and Angband, they both have their source code available for download, but it might be a bit hard for you to follow.

As for changing text and background color, there's no standard way to do this in c++. Since you're using windows you'll have to learn how to do it the windows way - I wish I could help you, but I have no experience developing windows console apps - but it does look like some of the other posts can help you out.
Thank you for helping.
I have one more request. Can you say something about the "windows.h"? It's said that there's some useful functions in it.
windows.h contains most of the Windows-specific functions. You don't need to know much about it though. Just look up the functions you want in MSDN and include windows.h if it is required.

This topic is closed to new replies.

Advertisement