-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServices.java
More file actions
77 lines (61 loc) · 1.99 KB
/
Services.java
File metadata and controls
77 lines (61 loc) · 1.99 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
package org.example.services;
import org.example.models.*;
public class Services implements IServices {
public Services() {
//empty constructor
}
@Override
public boolean canBuyWeapon(WeaponModel weapon, int playerScore) {
return playerScore >= weapon.getCost();
}
@Override
public boolean isPerfectNumber(int artifactCode) {
long sum = 0;
boolean isPerfect = false;
for (int i = 1; i <= artifactCode / 2; i++) {
if (artifactCode % i == 0) {
sum += i;
}
}
if (artifactCode == 0) {
return isPerfect;
} else if (sum == artifactCode) {
isPerfect = true;
}
return isPerfect;
}
@Override
public boolean isPrime(int artifact) {
if (artifact <= 1) {
return false;
}
for (int i = 2; i < artifact; i++) {
if (artifact % i == 0) {
return false;
}
}
return true;
}
@Override
public boolean isTrap(int artifact) {
return isSumDivBy3(artifact) && artifact % 2 == 0;
}
@Override
public boolean myWinProbability(PlayerStatus opponent, int health, int score) {
var opponentWinProb = (3 * opponent.getHealth() + opponent.getScore() / 1000) / 4;
var myWinProb = (3 * health + score / 1000) / 4;
return myWinProb >= opponentWinProb;
}
@Override
public double getDistance(PlayerStatus opponent, double posX, double posY) {
double ac = Math.abs(opponent.getPositionX() - posX);
double cb = Math.abs(opponent.getPositionY() - posY);
return Math.hypot(ac, cb);
}
@Override
public boolean winDuel(PlayerStatus opponent, double distance, WeaponModel myWeapon) {
opponent.getWeaponInHand().setCombatValue(distance);
myWeapon.setCombatValue(distance);
return opponent.getWeaponInHand().getCombatValue() > myWeapon.getCombatValue();
}
}