Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

FighterTest
Wednesday, October 17th, 2007 at 7:56:13am MDT 

This post has 1 comment thread shown at the end of this page.

  1. import java.util.Random;
  2. import java.awt.*;
  3. public class FighterTest {
  4.         static Random ranGen = new Random();
  5.         static Player player1 = new Player("Ho Yin");
  6.         static Player player2 = new Player("Jenifer");
  7.         static Player winner, loser;
  8.         static Player roundWinner, roundLoser;
  9.         public static void main(String args[]) {
  10.                
  11.                
  12.                 int roundNum = 0;
  13.                 do {
  14.                         roundNum++;
  15.                         System.out.println();
  16.                         System.out.println("Round "+ roundNum);
  17.                        
  18.                         boolean attackSuccessed;
  19.                        
  20.                         switch (ranGen.nextInt(2)) {
  21.                                 case 0:
  22.                                 System.out.println(player1.getName() + "'s power: " + player1.getPower());
  23.                                 System.out.println(player2.getName() + "'s power: " + player2.getPower());
  24.                                 attackSuccessed = player1.attack(player2);
  25.                                 roundWinner = attackSuccessed? player1: player2;
  26.                                 roundLoser  = attackSuccessed? player2: player1;
  27.                                 System.out.print(roundWinner.getName() + " wins");
  28.                                 System.out.println();
  29.                                 break;
  30.                                 case 1:
  31.                                 System.out.println(player1.getName() + "'s power: " + player1.getPower());
  32.                                 System.out.println(player2.getName() + "'s power: " + player2.getPower());
  33.                                 attackSuccessed = player2.attack(player1);
  34.                                 roundWinner = attackSuccessed? player2: player1;
  35.                                 roundLoser  = attackSuccessed? player1: player2;
  36.                                 System.out.print(roundLoser.getName() + " loses");
  37.                                 System.out.println();
  38.                                 break;
  39.                         }
  40.                        
  41.                         int difference = Math.abs(roundWinner.getPower()-roundLoser.getPower());
  42.                         if (difference==0) {
  43.                                 roundWinner.gainPower (1);
  44.                                 roundLoser.losePower  (1);
  45.                         }
  46.                         else {
  47.                                 roundWinner.gainPower (difference);
  48.                                 roundLoser.losePower  (difference);
  49.                         }
  50.                 } while (!anyoneIsDead());
  51.                
  52.                 if (player1.isDead()) {
  53.                         winner = player2;
  54.                         loser = player1;
  55.                 }
  56.                 else {
  57.                         winner = player1;
  58.                         loser = player2;
  59.                 }
  60.                
  61.                 System.out.println();
  62.                 System.out.println("Game over:");
  63.                 System.out.println(loser.getName() + " is dead!");
  64.                 System.out.println(winner.getName()+"'s power:"+winner.getPower());
  65.                 System.out.println(loser.getName()+"'s power:"+loser.getPower());
  66.         }
  67.                
  68.         public static boolean anyoneIsDead() {
  69.                 return (player1.isDead() || player2.isDead());
  70.         }
  71.        
  72. }

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

comments on this paste

FighterTest (#739779)

Posted By: 張真人

Posted: October 19th, 2007 at 12:17pm MDT

Interesting.

fantasy-obligation
fantasy-obligation