-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pokemon.java
52 lines (40 loc) · 1.3 KB
/
Pokemon.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Random;
public class Pokemon {
private String name;
private int hp;
private String bestAttack;
public Pokemon() {
name = "";
hp = 0;
}
public Pokemon(String name, String bestAttack, int hp) {
this.name = name;
this.hp = hp;
this.bestAttack = bestAttack;
}
public double getHitPoints() {
return hp;
}
public void battle() {
int damage = new Random().nextInt(31) + 20;
hp -= damage;
System.out.println(name + " got hit for " + damage + " hitpoints!");
}
public boolean knockedOut() {
return hp <= 0;
}
public String getBestAttack() {
return bestAttack;
}
public static void main(String[] args) {
Pokemon charmander = new Pokemon("Charmander", "Blaze", 39);
System.out.println("Charmander has " + charmander.getHitPoints() + " hitpoints.");
charmander.battle();
System.out.println("Charmander has " + charmander.getHitPoints() + " hitpoints.");
System.out.println("Charmander is knocked out: " + charmander.knockedOut());
charmander.battle();
System.out.println("Charmander is knocked out: " + charmander.knockedOut());
Pokemon abra = new Pokemon();
abra.getHitPoints();
}
}