Advertisement

C++ Workshop - Project 1

Started by August 16, 2006 05:41 PM
193 comments, last by me_minus 14 years, 10 months ago
If you don't have a main function, how will the compiler know where to enter your code at?
Alright I'm finally back from my trip (you can read about it here: http://www.eternal-silence.net/ )

Anyways, I'm finally back working on this project. I'm having trouble with the weapons though... I've never played D&D and I know what none of those fields are for.

I'm using an XML document for all of the weapons (to make it real simple on me hopefully, and I've also never used XML so it will be fun to experiment... I'm using ezXML if anyone is curious)

Right now, I simply have weaponName, gold value and thats it :P I don't know what the other junk is for.

I've never played any of those dice-rolling games, so that's why I'm having troubles mis-understanding. If it was up to me, I would simply have it have a min attack value and a max attack value. Only problem is that it won't scale to player level (or well I could just do some hacks, but I want to keep the design minimilistic and keep code seperated)

If anyone could help explain the weapons and armor a bit more, I would be _much_ appreciated... Once I get that system coded in, it's all implementation from there on out! :D



Deyja: I'd assume that the TI-83 doesn't need a main function or something? IDK, I'm as stumped as you are. I've never worked with calculator programming so I can't give much info :P
Advertisement
Quote: Original post by RavynousHunter
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.


If you're doing 83 programming you probably don't have to have a main() function. But at the same time, doesn't the 83 use basic? I thought only the 89 used C. Either way, you're going to have a hard time doing the exercise because neither C nor basic supports OOP which is really the purpose of the project. Though feel free to do it anyway as a learning experience, but you're going to run into problems that are unique to you specifically and not the rest of us.
Quote: Original post by Iced_Eagle
I've never played any of those dice-rolling games, so that's why I'm having troubles mis-understanding. If it was up to me, I would simply have it have a min attack value and a max attack value. Only problem is that it won't scale to player level (or well I could just do some hacks, but I want to keep the design minimilistic and keep code seperated)

If anyone could help explain the weapons and armor a bit more, I would be _much_ appreciated... Once I get that system coded in, it's all implementation from there on out! :D


It's really very easy. I'll pretty much repeat what JWalsh said but maybe it will make more sense if you see it another way.

If Bob wants to attack John:

1. Bob rolls a 20 sided dice.
2. If Bob's weapon says 19-20 and he rolls a 19 or 20 on this roll, his attack will be a critical attack. This roll is called an attack roll.
3. Bob adds his level and his strength modifer to the attack roll.
3. If Bob's attack roll is higher than John's Armor (the armor's AC or armor class value), plus his dexterity modifier, then the attack is successful.
4.If the attack is successful, then Bob rolls again to see how much damage he does. A 1d6 weapon means you roll 1, 6 sided dice to determine damage and then add the strength modifier to that. If his weapon says 3d10 you would roll 3, 10 sided dice for damage, and then add the strength modifier to that value. If the attack was critical, you take the damage you just created, and multiply by it by the (x2) or (x3) part of the item.

Let's do an example:

Bob's level is 5
Bob has 16 strength
Bob's strength modifier is (16-10) /2 or simply 3.
Bob's weapon is the Greatsword 2d6 (19-20/x2)
Bob rolls a 20 sided dice for attack, he rolls a 16 (not a critical strike).
Bob adds his level and strength modifier to the 16.
Bob's final attack roll is (16+5+3) or 24.

John has 20 dexterity
John's dexterity modifier is (20-10) /2 or 5.
John's armor is Chainmail AC: +5 Max Dex: +2
John's armor class is 5.
John adds his dexterity modifier of five to his armor class, but because the armor states it's max dexterity bonus is 2, he can only add two.
John's final armor class value is (5+2) or 7.

Bob's 24 roll is higher than John's armor check value of 7.
Bob's attack is successful.

Bob rolls 2, 6 sided dice.
The first roll is a 1, the second roll is a 5.
Bob adds his strength modifier to the damage.
Bob's final damage output is (1+5+3) or 9.
If he would have rolled a 19 or 20 on his attack roll, he would do (9x2) or 18 damage.


Does that clear things up?
Heya all,

ChurchSkiz was correct except for one little thing:

Quote: John has 20 dexterity
John's dexterity modifier is (20-10) /2 or 5.
John's armor is Chainmail AC: +5 Max Dex: +2
John's armor class is 5.
John adds his dexterity modifier of five to his armor class, but because the armor states it's max dexterity bonus is 2, he can only add two.
John's final armor class value is (5+2) or 7.


First, when calculating John's defense, Church forgot to add the base value of 10. This "10" represents the default 'armor' given to all humans as a result of their skin...at least that's what D&D says...In reality its just a scalar added to the defense calculation to make it map better to attackers attack roll. So the actual defense is as follows:

John has 20 dexterity
John's dexterity modifier is (20-10) /2 or 5.
John's armor is Chainmail AC: +5 Max Dex: +2
John's armor class is 5.
John adds his dexterity modifier of five to his armor class, but because the armor states it's max dexterity bonus is 2, he can only add two.
John gets a +10 to his armor value for being human.
John's final armor class value is (5+2+10) or 17.

Also, the notations used in this project (ie. 1d10) etc., are what's referred to as the d20 system. This is just a system of calculating statistical chances based upon a set of dice. Specifically, a d4, d6, d8, d10, d12, and d20 dice. This is the system most people have come to understand, and is thus the notation I use to describe the likelyhood and range of values. In reality, as was described before, you can just take the two values and use them to create a range of possible values to be used with the rand() function.

For example: 1d10 (roll 1, 10-sided dice)
This roll has a possible range of 1 to 10, as those are the only values on a 10-sided dice. To represent this in code you *could* create a Dice class, set the number of sides on it, and then "roll()" it to see what result it gives you...or you could just recognize that it would result in a value of 1-10 and do something like:

int roll = (rand() % 10) + 1;

which would result in a value between 1 and 10.

The same would be true for 2d8. This says to roll 2, 8-sided dice. Each dice has a possible range of 1 to 8. So the total range of values is 2-16.

For those interested in the d20 system, and how it can be used fully, look Here.

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
Doh, I would have loved to do this, but I'm about 2 weeks late.. ah I'll see what I can do anyway! Can't wait for the next one!
Advertisement
Quote: Original post by Crazyfool
Doh, I would have loved to do this, but I'm about 2 weeks late.. ah I'll see what I can do anyway! Can't wait for the next one!


You can still do it: it is a project, it is not a contest. The goal of this project is to make use of what have been learned in the C++ workshop since its very beginning, not to make "teh best gaem evar". Moreover, it is likely that the next project will be based on this one, so you'll have to do it in order to be able to do the next project.

Regards,
Quote: Original post by Emmanuel Deloget
Quote: Original post by Crazyfool
Doh, I would have loved to do this, but I'm about 2 weeks late.. ah I'll see what I can do anyway! Can't wait for the next one!


You can still do it: it is a project, it is not a contest. The goal of this project is to make use of what have been learned in the C++ workshop since its very beginning, not to make "teh best gaem evar". Moreover, it is likely that the next project will be based on this one, so you'll have to do it in order to be able to do the next project.

Regards,


To add to that, you still have two weeks left before the "deadline." If you do a little bit every day and spend a few hours on the weekends you should be able to get it done in time. Time pressure is a great motivator to work more efficiently, use it!
Quote: This roll has a possible range of 1 to 10, as those are the only values on a 10-sided dice. To represent this in code you *could* create a Dice class, set the number of sides on it, and then "roll()" it to see what result it gives you...or you could just recognize that it would result in a value of 1-10 and do something like:

int roll = (rand() % 10) + 1;

which would result in a value between 1 and 10.


That isn't such a great idea. An example; a 2d6 has a very different distribution than a 1d11 + 1. For a 2d6, 7 is more common than any other value. For a 1d11 + 1, all numbers are equally likely.
Quote: Original post by Deyja
Quote: This roll has a possible range of 1 to 10, as those are the only values on a 10-sided dice. To represent this in code you *could* create a Dice class, set the number of sides on it, and then "roll()" it to see what result it gives you...or you could just recognize that it would result in a value of 1-10 and do something like:

int roll = (rand() % 10) + 1;

which would result in a value between 1 and 10.


That isn't such a great idea. An example; a 2d6 has a very different distribution than a 1d11 + 1. For a 2d6, 7 is more common than any other value. For a 1d11 + 1, all numbers are equally likely.


Which part isn't such a great idea - creating a dice class, or using rand-mod to create random numbers? They are not mutually exclusive, btw, and in fact you're most likely going to implement your dice in just this way.

For the dice class method, you'd simply create two d6 dice object, roll them both, and sum up the values and that's your dice roll.

For the rand-mod (non-class) method, you simply do:

// Create a random value from 1 to 6
(rand() % 6) + 1

for each represented dice....so for a generic example:
int RollDice( int numDice, int numSides, int modifier ){    int roll = 0;    for( int i = 0; i < numDice; i++ )    {        roll += (rand() % numSides) + 1;    }    roll += modifier;    return roll;}


And that should work just fine for all dice roll combinations. If you were talking about doing the following scenario:

// Compute a random value from 2 to 12 (2d6)
int roll = (rand() % 11) + 2;

Then you're absolutely correct. The above line of code creates an even distribution of values from 2 to 12, however dice provide a different distribution. By nature of the fact that there are multiple dice, each being summed to create a combined value, there's a greater odd of receiving certain values around the middle. Ie. in order to receive a 2, both dice have to show a 1. But for a roll of 6, you can have 1+5, 2+4, or 3+3. So there's a much greater likelyhood of rolling a 6 when using two 6-sided dice, then say 2.

So you'll need to treat each dice as a seperate roll, you cannot just do the line directly above or you will be greatly simplifying the statistics.

Was that what you were trying to say?

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

This topic is closed to new replies.

Advertisement