Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: (OT) Brawling Javascript

by mariol (Initiate)
on Oct 12, 2004 at 00:14 UTC ( [id://398337]=note: print w/replies, xml ) Need Help??


in reply to Re: (OT) Brawling Javascript
in thread (OT) Brawling Javascript

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: (OT) Brawling Javascript
by tilly (Archbishop) on Oct 12, 2004 at 01:14 UTC
    I have successfully helped people learn to get through exactly the barrier that you have. Perhaps there is a better way, but the most successful approach that I found involved letting that person be stuck for a couple of weeks to make them learn for themselves that they cannot hold a complex problem in their head and tackle it all at once.

    Do you know how to create an object in JavaScript? You do it something like this. This will let you pass people around to functions without a big maze of variables to declare.

    var player_one = { dexterity: 0, strength: 1, level: 2, hp: 25 };
    Do you know how to write a function? I'm rusty on my JavaScript and didn't test, so there may be obvious errors, but here's one you might write from the top-down approach:
    function do_battle (player1, player2) { var attack_order = get_attack_order(player1, player2); var turn = 0; while ((player1.hp > 0) && (player2.hp > 0)) { turn++; document.write("turn " + turn + " begins!<br>"); for (attacker in attack_order) { if (1 == attacker) { resolve_attack(player1, player2); if (player2.hp < 1) break; } else { resolve_attack(player2, player1); if (player1.hp < 1) break; } } } hold_funeral(player1.hp < 1 ? player1 : player2); celebrate_victory(player1.hp < 1 ? player2 : player1); }
    This requires you to write the following additional attacksfunctions:
    1. get_attack_order decides what sequence of attacks happen in a turn. It gets 2 people and returns an array of 1's and 2's.
    2. resolve_attack figures out what happens when one person tries to hit another.
    3. hold_funeral remembers the departed.
    4. celebrate_victory for the winner.
    I'll let you write those functions yourself. If you get stuck, you're taking on too much at once. Break the problem up.
      Thank you tilly, I will try what you have suggested and i will not be posting anymore in here since they are not pearl questions but I thank you for your help and I will try to use what you have given me to learn more on it.
Re^3: (OT) Brawling Javascript
by BUU (Prior) on Oct 12, 2004 at 00:20 UTC
    You appear to be horribly confused. Do you see the name of this website? Perlmonks. Perl Monks. This means we do Perl here. Not javascript. Perhaps you can find some other website that does javascript.
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://398337]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-19 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found