-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerStatus.java
More file actions
127 lines (105 loc) · 3.05 KB
/
PlayerStatus.java
File metadata and controls
127 lines (105 loc) · 3.05 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package org.example.models;
import org.example.enums.*;
import org.example.services.*;
import static org.example.enums.Weapons.*;
public class PlayerStatus {
private static final String GAME_NAME = "UNREAL";
private final IServices service;
private String nickname;
private int score;
private int lives;
private int health = 100;
private WeaponModel weaponInHand;
private double positionX;
private double positionY;
public PlayerStatus(IServices service) {
this.service = service;
}
public boolean shouldAttackOpponent(PlayerStatus opponent) {
if (opponent.getWeaponInHand() == weaponInHand) {
return service.myWinProbability(opponent, health, score);
} else {
var distance = service.getDistance(opponent, positionX, positionY);
return service.winDuel(opponent, distance, weaponInHand);
}
}
public WeaponModel getWeaponInHand() {
return weaponInHand;
}
public void setWeaponInHand(WeaponModel weapon, Weapons weaponType) {
weaponInHand = new WeaponModel(FIST);
if (service.canBuyWeapon(weapon, score)) {
weaponInHand.setName(weaponType);
this.score -= weapon.getCost();
}
}
public String getGameName() {
return GAME_NAME;
}
public void initPlayer(String nickname) {
this.nickname = nickname;
}
public void initPlayer(String nickname, int lives) {
this.nickname = nickname;
this.lives = lives;
}
public void initPlayer(String nickname, int lives, int score) {
this.nickname = nickname;
this.lives = lives;
this.score = score;
}
public String getNickname() {
return nickname;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getLives() {
return lives;
}
public void setLives(int lives) {
this.lives += lives;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health += health;
if (this.health < 0) {
lives--;
this.health = 100;
}
if (this.health + health > 100) {
this.health = 100;
}
}
public double getPositionX() {
return positionX;
}
public void movePlayer(double newPosX, double newPosY) {
positionX += newPosX;
positionY += newPosY;
}
public double getPositionY() {
return positionY;
}
public void findArtifactCode(int artifactCode) {
if (service.isPerfectNumber(artifactCode)) {
setScore(5000);
setLives(1);
setHealth(100);
} else if (service.isPrime(artifactCode)) {
setScore(1000);
setLives(2);
setHealth(25);
} else if (service.isTrap(artifactCode)) {
setScore(-3000);
setHealth(-25);
} else {
score += artifactCode;
}
}
}