Sign in to follow this  
Hardball

Hello There

Recommended Posts

Hi there. I am completly new to C++ and needed some help. This page was highly recommended to me. I am using the program Dev-C++ and although know little about it am learning quickly. I am currently working on a text based game. MY question was this. I have combat scenes in the game and I wanted to know is it possible to change the text color of certain lines only. For example a little combat imitation: You attack and do damage <----- Text appears in red or blue Monster attacks and does damage <------ Text appears in green or yellow Is this at all possible and if it is can somone provide me a little walk threw on how to do it? Like i said I jsut started learning C++ and I find it very interesting. Thank you for any help you can provide.

Share this post


Link to post
Share on other sites
This is an OS-specific thing... On windows I think you need to use the "SetConsoleTextAttribute" function.

Have a look at this thread. They're trying to do something simmilar. Or alternatively, use the forums search function to look for "SetConsoleTextAttribute".

Share this post


Link to post
Share on other sites
I don't have much to add to Hodgman's answer, but a bit of general forum advice; you'll probably get better responses in general if your thread title is relevent to your question, and if you post in the correct forum (for beginners seems more appropriate to this question).

Good luck.

Share this post


Link to post
Share on other sites
Here is a page that shows you how to change the console text color. However, this is NOT part of C++, but rather part of Windows programming(Win32). It is probably fairly difficult to understand if you are just beginning C++, so good luck.

Share this post


Link to post
Share on other sites
I see. I found the answer on this thread:

http://www.gamedev.net/community/forums/topic.asp?topic_id=250995

And I have figured out how to make colored text now. Now I have another question but insince this thread is still small I will post it here if no-one minds. How is it possible to make a "PLEASE WAIT" line that has dots or dashes or simply the word flashing. And after a designated time it goes to the next line of the program. I know you can do cin.ignore to make the person press enter. But I mean way to make it automatic where the person does not have to press anyhting and simply after a 5 second pause the program continues. And during those 5 seconds dots or dashes are be printed on the screen or jsut the word please wait. Does anyone have a code to do this or can anyone let me know how to do this? Thank you and sorry for all the pestering.

Share this post


Link to post
Share on other sites
You could use the <windows.h> function Sleep() for a quick and easy solution, which takes the number of milleseconds to pause for as a parameter. Sleep(1000); for example pauses the program for 1 second.

I'm not really sure how to do flashing text in the console, but repeatedly clearing and redrawing all of the text, using Sleep() and the system("cls") command could work.

Share this post


Link to post
Share on other sites
Sleep is fine for a rough estimate - but if you need accuracy then be aware that it sleeps for at least the number of milliseconds you specify - it may sleep for longer.

For high precision, you could use QueryPerformanceCounter and loop until the specified time has passed.

For lower precision you could use SetTimer and its associates.

Of course, I'm assuming you're using Windows here.

Share this post


Link to post
Share on other sites
Yes i am using windows. And I will try both methods. Thank you for the help. So far everything is working great. Now I i will see if I can get the pause to work. Thanks again for both methods. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this