a pastebin project

Anonymous

  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

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you 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.

fantasy-obligation fantasy-obligation