Computer Science Canada Monsters |
Author: | magicman [ Sat Jul 09, 2005 9:31 am ] | ||
Post subject: | Monsters | ||
ok, so this is what i have for code sofar, with the monsters attacking.
the only problem is when i want the program to exit the loop when "mhp" will equal zero. for some reason, i think this is how you do it, but its not working. am i doing something thats not possible? |
Author: | Bacchus [ Sat Jul 09, 2005 10:56 am ] | ||
Post subject: | |||
try:
|
Author: | Delos [ Sat Jul 09, 2005 1:34 pm ] | ||||
Post subject: | Re: Monsters | ||||
Let's clean this code up a bit why don't we? We'll start by declaring a character type. This can apply to both hero's and monsters:
Notice a few things: a single type will contain all the information about the character that you need, in a single variable. This saves having to declare a bunch of unnecassary variables. Also, you can have multiple characteristics for a single character. Possibilities are endless. I've used a function to initialize the variables as opposed to a procedure. This feels more intuitive, since 'myHero' gets the characteristics of '(100, 20, 10)'. For your action calls, you can now use Rand.Int()'s that incorporate the charcter's specific Atk. This means you don't have to have a set value of '6' for any attack. Here's a sample of what you can now accomplish:
See what happened? I made a function that used a random number in the first character's attack range, subtracted the defense of the second character (this could be random too); it then made sure that the result was greater than zero. Why? Later on, I subtract the result from 'aMonster's HP. If the result were ever -ve, then we would add HP to it by attacking! There are likely better ways of doing this little attack - but this shows you the power of types. |
Author: | wtd [ Sat Jul 09, 2005 5:46 pm ] |
Post subject: | |
I can't effectively give bits to another moderator, but if I could I'd give Delos 100 bits for that reply. |
Author: | Delos [ Sat Jul 09, 2005 5:53 pm ] |
Post subject: | |
Now, here's the clincher...I wrote that entire post in a certain style reminiscent of a certain..."duck"... |
Author: | wtd [ Sat Jul 09, 2005 6:57 pm ] |
Post subject: | |
Delos wrote: Now, here's the clincher...I wrote that entire post in a certain style reminiscent of a certain..."duck"...
Hexley isn't a duck, dammit! |