Advertisement

C++ Workshop - Project 1

Started by August 16, 2006 05:41 PM
193 comments, last by me_minus 15 years, 3 months ago
That's right at the very top of the article.
To clear the screen

Include StdLib.h
#include <stdlib.h>


Then simply
system("cls");


Not sure if it's the best way to do it, but it's certainly the way to do it with the least number of lines :)


Quote:

Otherwise, could you (or anyone) just post the bare basic instructions for how to place text at desired point on console screen? (much like the way the instructions for random numbers and colored text were posted, just the bottom line how to.)


Read the first code block in the article :) Fairly simple once you get the console handle.
Advertisement
I've seen comments on other C++ sites that say the use of system calls should be avoided. I'll be interested to know the feelings of the experts here.

I came across a function which clears the console. It's not been covered in the book so far, so suspect that the simple \n\n\n\n\n ... approach might be what's expected.

void clrscr(void){    COORD                       coordScreen = { 0, 0 };    DWORD                       cCharsWritten;    CONSOLE_SCREEN_BUFFER_INFO  csbi;    DWORD                       dwConSize;    HANDLE                      hConsole = GetStdHandle(STD_OUTPUT_HANDLE);    GetConsoleScreenBufferInfo(hConsole, &csbi);    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;    FillConsoleOutputCharacter(hConsole, TEXT(' '),                                dwConSize, coordScreen, &cCharsWritten);    GetConsoleScreenBufferInfo(hConsole, &csbi);    FillConsoleOutputAttribute(hConsole, csbi.wAttributes,                                dwConSize, coordScreen, &cCharsWritten);    SetConsoleCursorPosition(hConsole, coordScreen);}
That's unnecesarily complex. And also it's C.

This does it fine.
char buffer[50*80] = { ' ' };WriteConsole( GetStdHandle(STD_OUTPUT_HANDLE), buffer, 50*80, 0, 0 );


Of course, it assumes your window is 80 * 50. (Unless you change it, it is.)
Wow, this is so much fun with that text-positioning power...

Question 1:
Id like to have more text manipulation, like;

- set console to full screen when program starts
- set console width and height limit of text (on my computer, i right-click/properties and set it to 80 width, 50 height. but how to do this from within the program)
- how to center text. (id imagine there should be a "console_width" and "console_height" value, and after getting the string length (uh, how do you do THAT?), i subtract that from console_width, divide that by 2, and print my text at that point. is this correct?)

Question 2:
Excuse my ignorance, i've never played dungeons and dragons, what is "Constitution" of the character?

(p.s. isnt hit points and experience the same?)
Will start on this tomorrow. Looks like a good way to improve my C++ programming [smile]
Advertisement
Quote:
id imagine there should be a "console_width" and "console_height" value, and after getting the string length

Read CondorMan's code snippet.

Quote:
Excuse my ignorance, i've never played dungeons and dragons, what is "Constitution" of the character?


www.dictionary.com

Quote:
(p.s. isnt hit points and experience the same?)
No.
Quote:
Original post by kingIZZZY
Wow, this is so much fun with that text-positioning power...

Question 1:
Id like to have more text manipulation, like;

- set console to full screen when program starts
- set console width and height limit of text (on my computer, i right-click/properties and set it to 80 width, 50 height. but how to do this from within the program)
- how to center text. (id imagine there should be a "console_width" and "console_height" value, and after getting the string length (uh, how do you do THAT?), i subtract that from console_width, divide that by 2, and print my text at that point. is this correct?)

Question 2:
Excuse my ignorance, i've never played dungeons and dragons, what is "Constitution" of the character?

(p.s. isnt hit points and experience the same?)


Just a quick note... I don't have VS2005 on the partition I'm running off of right now, so I can't check if these functions will work for you or not. I've just done MSDN searches and these are the functions that have come up. Give them a try :)

1) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsoledisplaymode.asp

2) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setconsolescreenbuffersize.asp

3) You will have to do some calculations to get the exact center, but here it is the function that you will need to use once you get the center coordinates (just a note... IIRC (0,0) is at the upper left of the console): http://msdn.microsoft.com/library/en-us/dllproc/base/setconsolecursorposition.asp

*Edit* Ugh, no progress today on the game :( My WinXP partition is almost all but unusuable and thus I've almost gone completely to Vista... I also don't want to bother installing and setting up VS2005 when there should be a new build later this week. Unfortunately I will also be gone all of this week cause I'll be in Washington visiting VALVe, DigiPen and Microsoft... I may take a laptop with the files on it though so if I have any time to breath/program, I will have the chance to finish this project up :)

[Edited by - Iced_Eagle on August 20, 2006 10:34:22 PM]
Ive tried to understand how exactly to use the code on the MSDN site (supplied by Iced_Eagle), aswell as condorman's snippet (suggested by Deyja), Im probably too n00bish, couldnt figure out what exactly to type to get what i need, namely= set console to full screen, set console width/height (limit of text), and get console width.
Could someone just summarize (n00b style) how exactly to use (get, set) these console functions?

p.s. I dont understand what "constitution" (which is from 8 to 20) is supposed to mean in this context of our project. (dunno how dictionary.com should help with this, deyja)
I haven't played D&D so I have to use a little research for what Constitution is used for in the game. Here is a nice little quip about what Constitution is for.

Quote:
Constitution (CON)

Measuring your character health and stamina, Constitution grants bonus hit points at every level, making it incredibly important for anyone that is going to take damage. Which is just about everyone. Constitution also modifies Concentration checks for casters, making it doubly important for them, and your chances to resist poison and disease.
Effects

* HP bonuses
* Fortitude saves
* Concentration


http://ddo.warcry.com/content/guides/abilities

Hopefully that helps.

kingIZZZY, use MSDN.Microsoft.com and Google and Google what you can't figure out. I would start with looking how to get the handle of the console.

I'm just trying to encourage you to have some self-discovery :) If you really can't get it, then post parts of the code that you tried, and we can help you correct it. I don't want to take all of the fun of programming away by just giving you the answer ;)

Woot, I got the Create-A-Character completely up and running along with the Stats menu... Player class is also 90-95% implemented (just a few more methods I have to implement, but those will take 10 seconds a piece).

I fear implementing all of those weapons. I think I'm going to experiment with having an XML document store the data and I then parse everything (I've never used one before, and so I might as well try it out :) )... I don't want to recompile if I ever want to make weapon changes!

Oh, yea I lied about not being able to get work done, haha... I found a way! :P I installed Visual Studio on a laptop that I will bring with me on my trip. I'll be coding until 3am every day so this will be done this week as long as I don't run into any snags with my XML system.

This topic is closed to new replies.

Advertisement