in reply to Re^2: (OT) Brawling Javascript
in thread (OT) Brawling Javascript
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.
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:var player_one = { dexterity: 0, strength: 1, level: 2, hp: 25 };
This requires you to write the following additionalfunction 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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: (OT) Brawling Javascript
by mariol (Initiate) on Oct 12, 2004 at 12:02 UTC |