-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerStatus.java
More file actions
138 lines (115 loc) · 3.28 KB
/
PlayerStatus.java
File metadata and controls
138 lines (115 loc) · 3.28 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
128
129
130
131
132
133
134
135
136
137
138
package org.example.models;
import org.example.enums.*;
import org.example.services.*;
public class PlayerStatus {
private static final String GAME_NAME = "UNREAL";
private final IServices service;
private String nickname;
private int score = 0;
private int lives = 3;
private int health;
private WeaponModel weaponInHand;
private double positionX;
private double positionY;
public PlayerStatus(IServices service) {
this.service = service;
}
public boolean shouldAttackOpponent(PlayerStatus opponent, PlayerStatus self) {
if (opponent.getWeaponInHand() == self.getWeaponInHand()) {
return service.myWinProbability(opponent, self);
} else {
var distance = service.getDistance(opponent, self);
return service.opponentWins(opponent, distance, weaponInHand);
}
}
public WeaponModel getWeaponInHand() {
return weaponInHand;
}
public boolean setWeaponInHand(WeaponModel weapon) {
weaponInHand = new WeaponModel(Weapons.FIST);
if (service.canBuyWeapon(weapon, score)) {
weaponInHand = weapon;
this.score -= weapon.getCost();
return true;
}
return false;
}
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 setPositionX(double posX) {
positionX = posX;
}
public double getPositionY() {
return positionY;
}
public void setPositionY(double positionY) {
this.positionY = positionY;
}
public void movePlayer(double newPosX, double newPosY) {
positionX += newPosX;
positionY += newPosY;
}
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);
if (score < 0) {
setScore(0);
}
setHealth(-25);
} else {
score += artifactCode;
}
}
}