Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathEncapsulation.java
More file actions
Latest commit
98 lines (79 loc) · 2.29 KB
/
Copy pathEncapsulation.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
classPlayer{
privateStringname;
privateintbaseHealth;
privateintbaseAttack;
privateintlevel;
privateintincrementHealth;
privateintincrementAttack;
privateArmorarmor;
privateWeaponweapon;
publicPlayer(Stringname){
this.name = name;
this.baseHealth = 100;
this.baseAttack = 100;
this.level = 1;
this.incrementHealth = 30;
this.incrementAttack = 30;
}
publicvoiddisplay(){
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");
}
publicvoidlevelUp(){
this.level++;
}
publicvoidsetArmor(Armorarmor){
this.armor = armor;
}
publicvoidsetWeapon(Weaponweapon){
this.weapon = weapon;
}
publicintmaxHealth(){
returnthis.baseHealth + this.level*this.incrementHealth + this.armor.getAddHealth();
}
publicintgetAttackPower(){
returnthis.baseAttack + this.level*this.incrementAttack + this.weapon.getAttack();
}
}
classWeapon{
privateStringname;
privateintattack;
publicWeapon(Stringname, intattack){
this.name = name;
this.attack = attack;
}
publicintgetAttack(){
returnthis.attack;
}
}
classArmor{
privateStringname;
privateintstrength;
privateinthealth;
publicArmor(Stringname, intstrength, inthealth){
this.name = name;
this.strength = strength;
this.health = health;
}
publicintgetAddHealth(){
returnthis.strength*20 + this.health;
}
}
publicclassMain{
publicstaticvoidmain(String[] args) {
Playerplayer1 = newPlayer("Firman");
Armorarmor1 = newArmor("Tameng",10,100);
Weaponweapon1 = newWeapon("Shotgun", 50);
player1.setArmor(armor1);
player1.setWeapon(weapon1);
Playerplayer2 = newPlayer("Alia");
Armorarmor2 = newArmor("Helm",5,90);
Weaponweapon2 = newWeapon("Panah", 30);
player2.setArmor(armor2);
player2.setWeapon(weapon2);
player1.display();
player2.display();
}
}