-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathEncapsulation.java
More file actions
98 lines (79 loc) · 2.29 KB
/
Encapsulation.java
File metadata and controls
98 lines (79 loc) · 2.29 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class Player{
private String name;
private int baseHealth;
private int baseAttack;
private int level;
private int incrementHealth;
private int incrementAttack;
private Armor armor;
private Weapon weapon;
public Player(String name){
this.name = name;
this.baseHealth = 100;
this.baseAttack = 100;
this.level = 1;
this.incrementHealth = 30;
this.incrementAttack = 30;
}
public void display(){
System.out.println("Player\t\t: " + this.name);
System.out.println("Level\t\t: " + this.level);
System.out.println("MaxHealth\t: " + this.maxHealth());
System.out.println("Attack\t\t: " + this.getAttackPower() + "\n");
}
public void levelUp(){
this.level++;
}
public void setArmor(Armor armor){
this.armor = armor;
}
public void setWeapon(Weapon weapon){
this.weapon = weapon;
}
public int maxHealth(){
return this.baseHealth + this.level*this.incrementHealth + this.armor.getAddHealth();
}
public int getAttackPower(){
return this.baseAttack + this.level*this.incrementAttack + this.weapon.getAttack();
}
}
class Weapon{
private String name;
private int attack;
public Weapon(String name, int attack){
this.name = name;
this.attack = attack;
}
public int getAttack(){
return this.attack;
}
}
class Armor{
private String name;
private int strength;
private int health;
public Armor(String name, int strength, int health){
this.name = name;
this.strength = strength;
this.health = health;
}
public int getAddHealth(){
return this.strength*20 + this.health;
}
}
public class Main{
public static void main(String[] args) {
Player player1 = new Player("Firman");
Armor armor1 = new Armor("Tameng",10,100);
Weapon weapon1 = new Weapon("Shotgun", 50);
player1.setArmor(armor1);
player1.setWeapon(weapon1);
Player player2 = new Player("Alia");
Armor armor2 = new Armor("Helm",5,90);
Weapon weapon2 = new Weapon("Panah", 30);
player2.setArmor(armor2);
player2.setWeapon(weapon2);
player1.display();
player2.display();
}
}