- FighterTest
- Wednesday, October 17th, 2007 at 7:56:13am MDT
This post has 1 comment thread shown at the end of this page.
- import java.util.Random;
- import java.awt.*;
- public class FighterTest {
- static Player player1 = new Player("Ho Yin");
- static Player player2 = new Player("Jenifer");
- static Player winner, loser;
- static Player roundWinner, roundLoser;
- int roundNum = 0;
- do {
- roundNum++;
- boolean attackSuccessed;
- switch (ranGen.nextInt(2)) {
- case 0:
- attackSuccessed = player1.attack(player2);
- roundWinner = attackSuccessed? player1: player2;
- roundLoser = attackSuccessed? player2: player1;
- break;
- case 1:
- attackSuccessed = player2.attack(player1);
- roundWinner = attackSuccessed? player2: player1;
- roundLoser = attackSuccessed? player1: player2;
- break;
- }
- if (difference==0) {
- roundWinner.gainPower (1);
- roundLoser.losePower (1);
- }
- else {
- roundWinner.gainPower (difference);
- roundLoser.losePower (difference);
- }
- } while (!anyoneIsDead());
- if (player1.isDead()) {
- winner = player2;
- loser = player1;
- }
- else {
- winner = player1;
- loser = player2;
- }
- }
- public static boolean anyoneIsDead() {
- return (player1.isDead() || player2.isDead());
- }
- }
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.