Advertisement

C++ Workshop - Project 1

Started by August 16, 2006 05:41 PM
193 comments, last by me_minus 14 years, 10 months ago
Quote:
First, how is the monster's difficulty calculated by level in D&D? Should we just start a monster off just like our character and level him up the same way each time? Or do we do that and buy them a better weapon and armor too? Or is there a whole different process?

Second, How are attributes gained when levelling? Does every attribute raise after every level?


These things were not specified in the project requirments, so theres no reason to blindly follow the D&D rules. However, it DOES have rules for all that stuff.

If I'm reading the 3rd edition Player's Handbook correctly, players gain 1 attribute point which they can assign to any attribute every 4 levels.

Creating monsters is complicated by difficulty ratings and party sizes. But, yes, they are created 'at a level', their stats are rolled (or simply chosen based on their species), and their hp is rolled the same as players. It can be tedious; that's why they published a monster manual. :)
Im getting towards the end of my first attempt at this project. Although I might end up rewriting it a few times before I am happy. How would you recommend to handle eronious input? I come from a java background and there an exception would be thrown, is this similar to how C++ works?

Another thing is using inline for functions like,

inline std::string Item::getName() const
{
return itemName;
}

Is that worth doing?




[Edited by - alexjp on August 26, 2006 2:10:01 PM]
Advertisement
ive seen some of the D+D formulae posted here, and 2 of them are made far more complicated then they need to be.

heres what ive found using a TI-83 calculator and the regression functions.

Ability Score Modifiers: round((X/2)-5.1, 0) ::x=score, the ",0" is how far to round::

Exp to next level: (500x^2)-500x ::x=level::


that should make things far simpler. though i dont know much about C++, i do know a sizeable bit about statistics.
Hello all,

Been working on my menu logic and I think that's coming along pretty good. I'm starting to get into some work on actual characters though and am having some problems...

I had originally though I could create a character class, declare the player's hero (of class character) at the start of my program and refer to it throughout all my files. Does this sound right? Or crazy?

So I have the line hero *warrior = new hero; in my main program, but when I then try to refer to refer to a object method in another cpp file in the project(warrior->setname(name);), I get the following error:

.\nameheromenu.cpp(16) : error C2065: 'warrior' : undeclared identifier

I feel a little confused because in the book, examples using the free-store appear to be all confined to a single main function(I think?), whereas in this project I'll (obviously) being running class methods in all sorts of different functions.

I know lots of you are already blazing through this project, but I hope I'm just missing a small bit of info. here and can catch up quick:) Thanks again, as always...
Trying to address everything at one go here.

Quote: Im getting towards the end of my first attempt at this project. Although I might end up rewriting it a few times before I am happy. How would you recommend to handle eronious input? I come from a java background and there an exception would be thrown, is this similar to how C++ works?

Yes, C++ has exceptions. I'm not a Java programmer, so I can't tell you how they are different from Java's, but I'm sure there are some differences. However, you should make a distinction between 'errors' and 'exceptions'. Reserve the exception mechanism for truly exceptional situations. Errors are not things that might happen if the moon is full on tuesday; they are things that WILL happen. It's usually prudent to handle them through more conventional means, or you needlessly complicate the code.

Quote:
Another thing is using inline for functions like,

inline std::string Item::getName() const
{
return itemName;
}

Is that worth doing?


Defining the function inside the header (Yes, that's okay - for class members) gives it an implicit inline. I wouldn't bother with placing a 'get' function that just returns a member into the CPP file. Furthermore, understand that declaring a function inline does not mean it will be inlined. It's a suggestion to the compiler. It's been shown that some modern compilers - MSVC in particular - simply ignore it, and inline what's safe and sensible to inline. It's usually better to let the compiler decide - it can even inline some calls and not others. If you're really sure you know what you're doing, and a profiler has told you inlining is a good idea, and the compiler isn't already doing it for you anyway, your compiler probably has an extension to force inlining. In MSVC, it's the '__force_inline_' macro (Or something like that. MSDN is your friend.)
Not then, the actual get function - that opens a whole 'nother can of worms. It's one of the (fairly common) religious wars that pop up in the 'for beginners' and 'general programming' forums every month or so. Just keep a watch out for the next one, and read what the people with high ratings say.

Quote: I feel a little confused because in the book, examples using the free-store appear to be all confined to a single main function(I think?), whereas in this project I'll (obviously) being running class methods in all sorts of different functions.


You can place globals in headers using the 'extern' keyword. I'm certain the book covers it.
It's pretty simple. Inside the header, you would declare the variable like 'extern int my_global;'. Then in 1 and only 1 source file, place 'int my_global;'. Any file that includes that header can access 'my_global'.
But just because you can do this doesn't mean you should. See if you can figure out how to do it using no globals at all.
Quote: Original post by ChurchSkiz
I have two questions that I haven't seen asked or answered yet about the project.

First, how is the monster's difficulty calculated by level in D&D? Should we just start a monster off just like our character and level him up the same way each time? Or do we do that and buy them a better weapon and armor too? Or is there a whole different process?

Second, How are attributes gained when leveling? Does every attribute raise after every level?


Good questions. I'm sorry I missed these issues. I'll update the project requirements today to answer these there. In the mean time, let me say that how D&D does it is not how we'll do it - for simplicity.

First, assume that each 'level' combatant is simply another randomly generated character, such as your own. So it will have randomly assigned ability scores and progressively better equipment.

Regarding equipment, I'd say another table needs to be created which shows the armor and weapons used by enemy combatants at each level. You can make your own, but I'll provide one later. In either event, more difficult combatants should have better equipment.

Second, in D&D the player is allowed to raise 1 ability score of their choice every 4 levels. This was an intentional omission, as we'll not do it that way for simplicity. We'll just assume that ability scores do not change as the character advances in level. So the only things that change are the character's hit points and equipment.

If you so feel inclined, you can implement it so that when a character levels after combat they are shown a menu which allows them to assign a new attribute point to one of their stats, however this is strictly optional. As well, if you do implement this, then you will need to factor in the additional ability score when randomly generating enemy combatants as well, else your character will have an unfair advantage.

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
Advertisement
[opinion]
In response to handling erroneous input:

While you could throw an exception and handle it that way, you could use a slightly more simple method.

In my program, whenever I get user input, I put it into a std::string. This is better then trying to use a char or something to catch menu input, because if you try to use a char (or even worse if you decide to use numbered menu options and use an int) is that the program will likely crash. However, by putting it into a string, it can handle just about any number of inputted characters. Then, I simply use a function to check to see if the input matches what I need it to be. For example, my check for input for menu option choices is something like:

bool Menu::checkInput(){ //Make sure it is only one character long. if(mInput.length() == 1)   //Check to see if any of the option keys match the input   for(int i = 0; i < (int)mOptions.size(); i++)   {    if(mInput[0] == mOptions.getKey())       // Do some stuff for the correct option.       return true;   } return false;}


This is a little easier to understand then trying to use exceptions, although, if you want to use try...catch and exception, be my guest as it would be a good learning experinece.
[/opinion]
Ack, sorry. Net lagged and it ended up getting double posted. If a moderator sees this, please delete it. Thanks.
There's a checkbox on the edit page to delete posts.
ive begun work on my own little game based off my TI-83+ game with DevC++, and since i dont have a book currently, i was wondering if anyone could point me in the direction of some resources for file creation/reading/alteration, and any other online resources i could use for the development of this little game.

thanks tons in advance,
RavynousHunter


ps: Do i absolutely have to have a main() function? because if i didnt, that would make things a whole lot easier on me.

[Edited by - RavynousHunter on August 28, 2006 7:00:50 PM]

This topic is closed to new replies.

Advertisement