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

Player
Wednesday, October 17th, 2007 at 7:57:42am MDT 

  1. import java.util.Random;
  2.  
  3. public class Player {
  4.         private Random ranGen = new Random();
  5.         private int power = 100;
  6.         private String name;
  7.        
  8.         public Player(String name, int power) {
  9.                 this.name = name;
  10.                 this.power = power;
  11.         }
  12.        
  13.         public Player(String name) {
  14.                 this.name = name;
  15.         }
  16.        
  17.         public String getName() {
  18.                 return name;
  19.         }
  20.        
  21.         public int getPower() {
  22.                 return this.power;
  23.         }
  24.        
  25.         public void gainPower(int attackment) {
  26.                 this.power += attackment;
  27.         }
  28.  
  29.         public void losePower(int attackment) {
  30.                 this.power -= attackment;
  31.         }
  32.  
  33.         public boolean attack(Player victim) {
  34.                 System.out.println(this.getName() + " attacks " + victim.getName());
  35.                 return (ranGen.nextInt(2)==0);
  36.         }
  37.        
  38.         public boolean isDead() {
  39.                 return (power <= 0);
  40.         }
  41.        
  42.        
  43. }

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.