|Syntactic Confectionery Delight|
|on Oct 11, 2004 at 23:31 UTC||Need Help??|
What is this doing on a Perl site?
This site is dedicated to learning, not getting other people to do your work. We'll help you learn, we won't generally write your own script for you.
I'll make the rest of my reply based on the assumption that you want to learn.
First of all the question is unclear. What exactly should a brawling script do? Go through a single hit? Or have 2 opponents duel to the death? (Possibly with random comments from, "XXX mercilessly attacks thin air." to "XXX delivers a crushing blow to the chest, doing 34 HP damage. A bloody smear marks YYY's passing.")
Either way your problem is probably that you're trying to bite off too much at once. There are two common strategies to use in this case - top down or bottom up.
For bottom up, you'd write a function that does something simple and necessary, then test it. For instance figures out what the results of a single blow are. Try running that function and see if it works. And another to update a character's stats after the blow. Try having one monster hit another one and see whether the other monster accumulates damage. Then continue to layer one task on top of another until you've got the whole thing. For instance next might be a function to track who strikes whom in what order. And so on.
For top down you'd look at the overall problem and try to break it into pieces. For instance you might say that a brawl breaks into attacks. So first you need to write a control loop that figures out who attacks whom in what order. (Be sure that this loop can tell if someone is dead!) And then try to write code for how to handle a single attack.
Both approaches work (and pros work them together). Either approach gives you a way to avoid getting stuck.
Remember. Work in small simple pieces. Stop often to see that you're still on a track to succeed.