- Anonymous
- Tuesday, December 11th, 2007 at 11:29:57pm MST
- //Java Fighters Universe v2007
- //the second homework_ism001
- //by LAW MEI KWAN 8048955
- //2007-12-10
- import java.util.Random; // program class Ramdom number genarator
- public class Player {
- //Instanca variable (attributes)
- protected int playerPower=10;//power is from 0 to 100
- protected String playerName;
- protected Random randomNumbers = new Random();
- protected int r=1;
- protected boolean isDead=false;
- protected int Difference;
- //Constructors
- public Player( String playerName){
- this.playerName = playerName; }
- //get and set player name
- public void setPlayerName( String playerName ){this.playerName = playerName;}
- public String getPlayerName(){return playerName;}
- //get and set player power
- public void setPlayerPower( int playerPower,int Difference ){this.playerPower = playerPower+Difference;}
- public int getPlayerPower(){return playerPower;}
- //Other method
- public void Attack( Player victim ) {
- int temp=getPlayerPower(),temp1=victim.getPlayerPower();
- Difference= Math.abs(getPlayerPower() - victim.getPlayerPower() );
- if(Difference==0) Difference=1;
- System.out.println("====Round " + r + "====");
- System.out.println( getPlayerName() + " attacks "+ victim.getPlayerName() +"! " );
- if (randomNumbers.nextDouble() <= 0.5 ){
- System.out.println(getPlayerName()+" wins! *.* ");
- setPlayerPower(playerPower,Difference);
- victim.setPlayerPower(victim.getPlayerPower(),-Difference);
- }
- else{
- System.out.println(getPlayerName()+" loses! >.<");
- setPlayerPower(getPlayerPower(),-Difference);
- victim.setPlayerPower(victim.getPlayerPower(),Difference);
- }
- if (victim.getPlayerPower()<=0){
- victim.isDead=true;
- System.out.println(victim.getPlayerName()+" is killed >< ! !");
- }
- if (getPlayerPower()<=0){
- isDead=true;
- System.out.println(getPlayerName()+" is killed >< ! !");
- }
- System.out.println(getPlayerName()+" 's power = " +getPlayerPower());
- System.out.println(victim.getPlayerName()+" 's power = " +victim.getPlayerPower());
- }//end method attack
- }// 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.
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.