-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from Team-40-IDATT2003/52-player-status-enum
52 player status enum
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| /** | ||
| * Enum representing a players' current status. | ||
| * | ||
| * <p>The player has the responsibility for getting | ||
| * a status.</p> | ||
| * */ | ||
| public enum PlayerStatus { | ||
|
|
||
| /** Status representing a beginner. */ | ||
| NOOB, | ||
|
|
||
| /** | ||
| * Status representing a player who has increased | ||
| * their net worth by at least 20 percent. */ | ||
| NOVICE, | ||
|
|
||
| /** | ||
| * Status representing a player who has increased | ||
| * their net worth by at least 50 percent. */ | ||
| GOOD, | ||
|
|
||
| /** Status representing a player who has at least doubled their net worth. */ | ||
| TRYHARD, | ||
|
|
||
| /** Status representing a player who has at least tripled their net worth. */ | ||
| PRO, | ||
|
|
||
| /** | ||
| * Status representing a player who has at least quintupled their | ||
| * net worth. */ | ||
| SEER, | ||
|
|
||
| /** | ||
| * Status representing a player who has at least dectupled their | ||
| * net worth. */ | ||
| OMNIPOTENT; | ||
| } | ||
|
|
54 changes: 54 additions & 0 deletions
54
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| /** | ||
| * Controls and calculates the players' status. | ||
| * | ||
| * @see PlayerStatus | ||
| * */ | ||
| public final class PlayerStatusController { | ||
| private PlayerStatusController() { | ||
| /* This utility class should not be instantiated */ | ||
| } | ||
|
|
||
| /** | ||
| * Method for getting a player status based on a player. | ||
| * | ||
| * <p>Calculates what status the player should get | ||
| * based on players' net worth compared to starting | ||
| * money, and current week.</p> | ||
| * | ||
| * @param player the player to give a status to. | ||
| * | ||
| * @return a PlayerStatus | ||
| * */ | ||
| public static PlayerStatus getStatus(final Player player) { | ||
| Integer startingMoneyInt = player.getStartingMoney().intValue(); | ||
|
|
||
| BigDecimal difference = | ||
| player.getNetWorth().subtract(player.getStartingMoney()); | ||
|
|
||
| return switch ((Integer) difference.intValue()) { | ||
| case Integer val when val >= percentAmount(startingMoneyInt, 900) -> PlayerStatus.OMNIPOTENT; | ||
| case Integer val when val >= percentAmount(startingMoneyInt, 400) -> PlayerStatus.SEER; | ||
| case Integer val when val >= percentAmount(startingMoneyInt, 200) -> PlayerStatus.PRO; | ||
| case Integer val when val >= percentAmount(startingMoneyInt, 100) -> PlayerStatus.TRYHARD; | ||
| case Integer val when val >= percentAmount(startingMoneyInt, 50) -> PlayerStatus.GOOD; | ||
| case Integer val when val >= percentAmount(startingMoneyInt, 20) -> PlayerStatus.NOVICE; | ||
| default -> PlayerStatus.NOOB; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Helper method for increasing a value by x percent. | ||
| * | ||
| * @param value the value to calculate from | ||
| * @param x the percent amount | ||
| * | ||
| * @return the increased value. | ||
| * */ | ||
| private static Integer percentAmount(final Integer value, final Integer x) { | ||
| return (value * x) / 100; | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/PlayerStatusTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class PlayerStatusTest { | ||
|
|
||
| @Test | ||
| void getStatusReturnsProperStatuses() { | ||
| Player testPlayer = new Player("Player", new BigDecimal(1000)); | ||
| PlayerStatus gottenStatus = PlayerStatusController.getStatus(testPlayer); | ||
| assertEquals(PlayerStatus.NOOB, gottenStatus); | ||
|
|
||
| testPlayer.addMoney(new BigDecimal(1000)); | ||
| PlayerStatus gottenStatus2 = PlayerStatusController.getStatus(testPlayer); | ||
|
|
||
| assertEquals(PlayerStatus.TRYHARD, gottenStatus2); | ||
| } | ||
| } |