Advertisement

C++ Workshop - Project 1

Started by August 16, 2006 05:41 PM
193 comments, last by me_minus 15 years, 3 months ago
I already figured out how to get the handle, when we needed to change text colors, aswell as position text.

From what i understood on MSDN is that i need to call

SetConsoleDisplayMode(HANDLE, DWORD, PCOORD)

and pass in the handle, and then a DWORD variable which should be set to either

CONSOLE_FULLSCREEN_MODE or 1

or
CONSOLE_WINDOWED_MODE or 2


and a pointer to PCOORD which should hold new coordinates for text limit.

2 problems encountered:

1. "CONSOLE_FULLSCREEN_MODE undeclared"
2. "SetConsoleDisplayMode undeclared"

so i opened up wincon.h, and alas, they ARE declared, but both of these specifically are declared conditionally;

#if (_WIN32_WINNT >= 0x0501)#define CONSOLE_FULLSCREEN_MODE	1...#if (_WIN32_WINNT >= 0x0501)BOOL WINAPI SetConsoleDisplayMode(HANDLE,DWORD,PCOORD);


I commented out these conditions and boom- it worked! but i dont think i should play around with the wincon.h file to make my project work. What ARE these conditions? why do they fail? what can be done?

Regarding the ScreenBufferSize i figured it out, thanx!

In short: what i am trying to do is, that whatever computer my program will be played on, whatever settings that computer may already have set for its consoles, i want my program to set its console to such-and-such settings for best output display.

[Edited by - kingIZZZY on August 21, 2006 3:16:27 PM]
To jwalsh:

Can you please clarify exactly what do you mean by "constitution" of the character, and how does it affect the rest of the stats and the game.
Advertisement
Quote:
Original post by kingIZZZY
To jwalsh:

Can you please clarify exactly what do you mean by "constitution" of the character, and how does it affect the rest of the stats and the game.


No problem. In Dungeons & Dragons, as in our little combat simulator, a character is made up of a series of attributes, referred to as Ability Scores in D&D.

They are: Stength, Dexterity, Constitution, Intelligence, Wisdom, and Charisma. Feel free to add all six attributes to your Character class, or feel free to just add the first three (Strength, Dexterity, and Constituion), as those are the only 3 we will use for THIS project. Though we'll likely use the other three in the next project. =)

Each Ability score can have value in the range of 1 to 20, as in the previous exercise you had to do. For the sake of this combat simulator, however, we'll assume that all 3 scores (Str, Dex, Con) are in the range of 8-20.

Now, the score themselves mean little...What's important is the MODIFER which is computed from those scores. To compute the modifier, simply take the score, subtract 10, and then divide by 2 (truncating the fraction).

So for example if I had a strength of 15, my Strength Modifier (StrMod) would be 2. As well, if I had a Constitution of 18 my ConMod would be 4.

As for constitution, dictionary.com defines constitution as: "The physical makeup of the body, including its functions, metabolic processes, reactions to stimuli, and resistance to the attack of pathogenic organisms." In a nutshell, your character's constitution determines how "Healthy and resiliant" your character is. A person with high constitution is more likely to withstand things such as torture.

As to how the Constituion modifies the stats of the game. Just as Iced Eagle said "...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."

Specifically, the Constituion score determines the ConMod. And the ConMod is used to determine the character's bonus hitpoints. As I stated in my original post, whenever a character is created they are given hitpoints equal to 10 + their ConMod. Additionally, each time a character levels, they receive additional hitpoints equal to 1d10 + ConMod. This means they get hitpoints equal to a random value from 1 to 10, plus the ConMod.

So in summary:
New Character's Hiptoins: 10 + ConMod
Each Level Add Hitpoins: 1d10 + ConMod.

So my level 1 character with a constitution of 16 has 13 hitpoints. (10 + 3)
As well, if I were to level my character say 3 times, I might possibly have 37 hitpoints. (13 + 3*( 1d10 + 3))

Does this answer your question?
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Yes, that pretty much makes it clear, thanx alot.

(p.s. someone please take a look at my other post, the longer one)

Quote:
so i opened up wincon.h, and alas, they ARE declared, but both of these specifically are declared conditionally;

#if (_WIN32_WINNT >= 0x0501)
#define CONSOLE_FULLSCREEN_MODE 1
...
#if (_WIN32_WINNT >= 0x0501)
BOOL WINAPI SetConsoleDisplayMode(HANDLE,DWORD,PCOORD);



I commented out these conditions and boom- it worked! but i don’t think i should play around with the wincon.h file to make my project work. What ARE these conditions? why do they fail? what can be done?





Fair questions. There is certain functionality in the visual studio libraries which only work on specific operating systems. How horrible would it be if you accidentally used these functions without knowing that you were forcing your users to have a specific operating system in order to run your program?!?

To avoid this scenario Microsoft wraps its operating system specific functionality within conditional compiles, such as you see above. Then, in order to use that functionality YOU must specifically state that you understand you're forcing your customers to have a specific operating system in order to run your application.

So the solution to your problem is to just, somewhere in your code, define _WIN32_WINNT to have a value greater than or equal to 0x0501. By doing this you're telling your compiler its ok to use operating system specific code.

For the record, defining _WIN32_WINNT to have a value of 0x0501 means that your code will only run on WinXP or better. If you don’t have WinXP or better, I'd recommend not using that code. =) 90% of Windows users are using WinXP these days, however, so its generally safe to use 0x0501 specific functions.

Also, NEVER MODIFY THE SYSTEM HEADERS. They are implemented in a specific way for a specific reason. If you find you must modify a system header, you're generally screwing yourself somewhere down the road. Figure out the correct way to solve your problem. [cool]

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Quote:
#if (_WIN32_WINNT >= 0x0501)

#define CONSOLE_FULLSCREEN_MODE 1

...

#if (_WIN32_WINNT >= 0x0501)

BOOL WINAPI SetConsoleDisplayMode(HANDLE,DWORD,PCOORD);








I hope you remembered to comment out the #endifs too!

These are just saying 'if they are compiling for winnt 5.01 or higher, support these functions'. What compiler are you using? It's likely that your compiler just didn't set _WIN32_WINNT to the proper value. If you are using VCExpress, it should work. If you are using VC6, it might not. And DevCPP - eh, your guess is as good as mine.

A better alternative to messing with the header is to just drop them into your cpp file. Yes, that's right, just copy and paste those two declarations right into the top of the cpp file that uses them, right under where you include the file that is supposed to declare them. Of course, this will break if you switch to a compiler that does define _WIN32_WINNT properly.
Advertisement
Ah, JWalsh's answer is better then mine.

However, I expect that Microsoft did this to maintain backwards compatibility; so they could ship the same headers for older systems; and not to make the developer specifically state 'XP Only'. It seems it would be in Microsoft's favor, and good business practice, to prefer new programs be 'XP Only'.
kingIZZY: You are adding Kernel32.lib as a dependency, correct? Also including Windows.h in the code?

Other than that, what's your compiler? You never ever should touch the system headers and such... It will bite you in the ass later down the road, I promise you.

Let's see today I implemented the monster class, and prototyped the fighting...

I'm leaving on a plane in 12.5 hours, so I won't be able to work until tomorrow until like 5pm-ish...
Not sure what the kernel32 thingy is or what does it mean to add it as a dependancy...yes, i included windows.h in my project.

I use Dev-cpp 4.9.9.2 (latest version, i think).
(Are there any other free good ones out there to download?)
This question most probably relates to chapter 6-11 thread, but ill post here cuz it also concerns this project.

Im having a hard time learning and remembering the steps of Object Oriented analysis/design. Since i am currently not really planning out for myself some big project, whatever i read in chapter 11 sounds all the same in all phases: "Just get it straight what is this thing in the real world, and how do we need it to interact with users, and make it that way". whatever, I just cant get chapter 11 in my head.
Therefore, if finnishing the analysis phase is part of project 1, then im in trouble. And, uh, if OO Analysis/Design is part of being a C++ programmer (duh), then im in REAL trouble...

Any suggestions?

This topic is closed to new replies.

Advertisement