Skip to content
Snippets Groups Projects
Commit ced8cd1d authored by Thomas BREIL's avatar Thomas BREIL
Browse files

Change money system and remove warnings

parent 063f3ffa
Branches main
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
Dwarf firstPlayer = new Dwarf("Florian", "Ruzberg de Rivehaute", 200, new ArrayList<>());
firstPlayer.addMoney(400);
firstPlayer.changeMoney(400);
firstPlayer.addXp( 15);
System.out.println(Affichage.afficherJoueur(firstPlayer));
......
......@@ -2,7 +2,6 @@ package re.forestier.edu.rpg;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
import java.util.Random;
public abstract class player {
......@@ -11,7 +10,6 @@ public abstract class player {
public String Avatar_class;
public Integer money;
private Float __real_money__;
public Integer lvlXp;
public Integer level;
......@@ -36,7 +34,7 @@ public abstract class player {
this.level = 1;
this.xp = 0;
this.lvlXp = 10;
this.abilities = new HashMap<String, Integer>();
this.abilities = new HashMap<>();
}
public String getAvatarClass() {
......@@ -45,14 +43,11 @@ public abstract class player {
public void removeMoney(Integer amount) throws IllegalArgumentException {
if (money - amount < 0) {
public void changeMoney(Integer amount) throws IllegalArgumentException {
if (money + amount < 0) {
throw new IllegalArgumentException("Player can't have a negative money!");
}
money -= amount;
}
public void addMoney(Integer amount) {
money = money + (amount != null ? amount : 0);
money += amount;
}
protected void levelUp() {
......
......@@ -7,7 +7,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.approvaltests.Approvals.verify;
import java.util.ArrayList;
......@@ -26,8 +25,8 @@ public class UnitTests {
Dwarf p = new Dwarf("Florian", "Grognak le barbare", 100, new ArrayList<>());
try {
p.removeMoney(50);
p.removeMoney(200);
p.changeMoney(-50);
p.changeMoney(-200);
} catch (IllegalArgumentException e) {
return;
}
......@@ -38,11 +37,13 @@ public class UnitTests {
@DisplayName("Test add money")
void testAddMoney() {
Archer player = new Archer("Florian", "Gnognak le Barbare", 200, new ArrayList<>());
player.addMoney(200);;
player.changeMoney(200);
assertThat(player.money, is(400));
}
@Test
@DisplayName("Test all levels")
void testAllLevels() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment