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

FightersUniverse.java
Sunday, December 16th, 2007 at 6:22:10pm MST 

  1. import java.util.Random;
  2.  
  3. public class FightersUniverse {
  4.  
  5.         public static boolean isAllAlive( Player player[] ){
  6.                 for( Player p: player )
  7.                         if(p.isDead()) return false;
  8.                 return true;
  9.         }
  10.  
  11.         public static void main( String args[] ){
  12.  
  13.                 int counter=0;
  14.                 int one, two;
  15.                 final int N = 4;
  16.                 Random generator = new Random();
  17.  
  18.                 System.out.println("Java Fighters' Universe! v20071112");
  19.  
  20.                 // Define new players
  21.                 Player player[] = {
  22.                         new Player("Ho Yin"),
  23.                         new Player("Justin"),
  24.                         new BossPlayer("Boss Janice"),
  25.                         new BossPlayer("Boss Florence")
  26.                 };
  27.  
  28.                 do {
  29.                         System.out.println("== Round " + (++counter) + " ==");
  30.                         do { // Loop until valid players are selected
  31.                                 one = generator.nextInt(N);
  32.                                 two = generator.nextInt(N);
  33.                         } while ( player[one].isDead() || player[two].isDead() || one==two );
  34.  
  35.                         // Remember the original power
  36.                         int onePower = player[one].getPower();
  37.                         int twoPower = player[two].getPower();
  38.                         // Attack!
  39.                         player[one].attack(player[two]);
  40.                         // Print the change in power after the attack
  41.                         System.out.println("*** " + player[one].getName() + ": " + onePower + " -> " + player[one].getPower());
  42.                         System.out.println("*** " + player[two].getName() + ": " + twoPower + " -> " + player[two].getPower());
  43.  
  44.                 } while ( isAllAlive( player ) ); // Loop until any one is dead
  45.  
  46.                 System.out.println("== Game over ==");
  47.                 for( Player p: player ){
  48.                         System.out.println("*** " + p.getName() + "'s power = " + p.getPower());
  49.                 }
  50.         }
  51. }

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.

worth-right fantasy-obligation
fantasy-obligation