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

Unnamed
Friday, October 5th, 2007 at 8:42:20am MDT 

  1. import java.util.Random;
  2. public class SuperPlayers
  3. {
  4.         //define Power and Difference and Round
  5.         private int Power=100,Difference,Round=1;
  6.         //define the Player Name
  7.         private String Name;
  8.         //define the Player is dead or not
  9.         public boolean isDead=false;
  10.         Random randomNumber;   
  11.         public SuperPlayers(String Name)
  12.         {
  13.                 //將傳回的Name傳給這個類別的Name
  14.                 this.Name=Name;
  15.                 //call a Object from Random
  16.                 randomNumber=new Random();
  17.         }
  18.         //call a method for setting the Power for the players after each round
  19.         public void setPower(int Power,int Difference)
  20.         {
  21.                 this.Power=(Power+Difference);
  22.         }
  23.         //call a method to get the value of power each round
  24.         public int getPower()
  25.         {
  26.                 return Power;
  27.         }
  28.         //call a method to get the name from the Players
  29.         public String getName()
  30.         {
  31.                 return Name;
  32.         }
  33.         //call a method for attacking the Players
  34.         public void Attack(SuperPlayers A)
  35.         {       //to check whether a player is dead or not               
  36.                 if (getPower() <= 0)
  37.                 {
  38.                         isDead=true;
  39.                         System.out.printf("==========GameOver===========\nWinner is %s!!!!!!", A.getName());
  40.                         return;
  41.                 }
  42.                 if (A.getPower() <= 0)
  43.                 {
  44.                         A.isDead=true;
  45.                         System.out.printf("==========GameOver===========\nWinner is %s!!!!!!", getName());
  46.                         return; 
  47.                 }
  48.                 //print out which round for this attack
  49.                 System.out.println("====Round " + Round + "====");
  50.                 Round++;
  51.                 //print out who attacks who
  52.                 System.out.println(getName() + " attacks " + A.getName() + "!!!");
  53.                 //to define a player have 50% chance of winning the battle
  54.                 if(randomNumber.nextDouble() < 0.5 )
  55.                 {
  56.                         System.out.println(getName()+" wins!");
  57.                         /*if own Power>enermy'sPower then own Power increases by the difference
  58.                         and enermy's Power  decreases by ther difference*/
  59.                         if(Power>A.getPower())
  60.                         {
  61.                         Difference=(Power-A.getPower());
  62.                         setPower(Power,Difference);
  63.                         A.setPower(A.getPower(),-Difference);
  64.                         }
  65.                         else
  66.                         /*if own Power=enermy'sPower then own Power increases by1
  67.                         and enermy's Power  decreases by 1*/
  68.                         {
  69.                         if (Power == A.getPower())
  70.                         {
  71.                         setPower(Power,1);
  72.                         A.setPower(A.getPower(),-1);
  73.                         }
  74.                         else
  75.                         {
  76.                         /*if own Power<enermy'sPower then own Power increases to the enermy's Power
  77.                         and enermy's Power  decreases to the winner's Power*/
  78.                         if(Power<A.getPower())
  79.                         {
  80.                         Difference=(A.getPower()-getPower());
  81.                         setPower(getPower(),Difference);
  82.                         A.setPower(A.getPower(),-Difference);
  83.                         }
  84.                         }
  85.                         }       
  86.                 }
  87.                 else
  88.                 {
  89.                         //vice versa
  90.                         System.out.println(getName()+" loses!");
  91.                         if(Power > A.getPower())
  92.                         {
  93.                         Difference=(Power-A.getPower());
  94.                         setPower(Power,-Difference);
  95.                         A.setPower(A.getPower(),Difference);
  96.                         }
  97.                         else
  98.                         {
  99.                         if (Power == A.getPower())
  100.                         {
  101.                         setPower(Power,-1);
  102.                         A.setPower(A.getPower(),1);
  103.                         }
  104.                         else
  105.                         {
  106.                         if (Power < A.getPower())
  107.                         {
  108.                         Difference=(A.getPower()-Power);
  109.                         A.setPower(getPower(),Difference);
  110.                         setPower(getPower(),-Difference);
  111.                         }
  112.                         }
  113.                         }       
  114.                 }
  115.                 //show out players hp at last
  116.                 System.out.println("J POWER="+getPower());
  117.                 System.out.println("H POWER="+A.getPower());   
  118.         }
  119. }

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
worth-right