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

Anonymous
Tuesday, December 11th, 2007 at 11:29:57pm MST 

  1. //Java Fighters Universe v2007
  2. //the second homework_ism001
  3. //by LAW MEI KWAN 8048955
  4. //2007-12-10
  5.  
  6. import java.util.Random; // program class Ramdom number genarator
  7.  
  8. public class Player {
  9.  
  10.   //Instanca variable (attributes)
  11.   protected int playerPower=10;//power is from 0 to 100
  12.   protected String playerName;
  13.   protected Random randomNumbers = new Random();
  14.   protected int r=1;
  15.   protected boolean isDead=false;
  16.   protected int Difference;
  17.  
  18.   //Constructors
  19.   public Player( String playerName){         
  20.     this.playerName = playerName; }
  21.  
  22.   //get and set player name
  23.   public void setPlayerName( String playerName ){this.playerName = playerName;}
  24.   public String getPlayerName(){return playerName;}
  25.  
  26.   //get and set player power
  27.   public void setPlayerPower( int playerPower,int Difference ){this.playerPower = playerPower+Difference;}
  28.   public int getPlayerPower(){return playerPower;}
  29.  
  30.   //Other method
  31.    public void Attack( Player victim ) {
  32.    int temp=getPlayerPower(),temp1=victim.getPlayerPower();
  33.    Difference= Math.abs(getPlayerPower() - victim.getPlayerPower() );
  34.    if(Difference==0) Difference=1;
  35.    
  36.    System.out.println("====Round " + r + "====");
  37.    System.out.println( getPlayerName() + " attacks "+ victim.getPlayerName() +"! " );
  38.  
  39.    if (randomNumbers.nextDouble() <= 0.5 ){
  40.         System.out.println(getPlayerName()+" wins! *.* ");
  41.         setPlayerPower(playerPower,Difference);
  42.         victim.setPlayerPower(victim.getPlayerPower(),-Difference);
  43.     }
  44.     else{
  45.             System.out.println(getPlayerName()+" loses! >.<");
  46.             setPlayerPower(getPlayerPower(),-Difference);
  47.             victim.setPlayerPower(victim.getPlayerPower(),Difference);   
  48.     }
  49.    
  50.     if (victim.getPlayerPower()<=0){
  51.         victim.isDead=true;
  52.         System.out.println(victim.getPlayerName()+" is killed >< ! !");
  53.     }
  54.                
  55.     if (getPlayerPower()<=0){
  56.         isDead=true;
  57.         System.out.println(getPlayerName()+" is killed >< ! !");
  58.     }
  59.                
  60.     System.out.println(getPlayerName()+" 's power = " +getPlayerPower());
  61.     System.out.println(victim.getPlayerName()+" 's power = " +victim.getPlayerPower())
  62.  
  63.    }//end method attack
  64.  
  65. }// end class Player

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.

fantasy-obligation