Fixed random token assigning and realisation

Token class now has two functions: assignRandomType and realiseRandomType
The former can be used to assign any random type to the token including the random type
The latter can be used to assign a concrete random type to the token (not the random type)

#story[1245]
This commit is contained in:
William Muir
2017-09-20 12:02:12 +12:00
parent 52d3cea592
commit 6cde016401
4 changed files with 39 additions and 19 deletions
+21 -2
View File
@@ -1,5 +1,9 @@
package seng302.model.token;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import seng302.model.GeoPoint;
/**
@@ -9,6 +13,7 @@ import seng302.model.GeoPoint;
public class Token extends GeoPoint {
private TokenType tokenType;
private Random random = new Random();
public Token(TokenType tokenType, double lat, double lng) {
super(lat, lng);
@@ -19,7 +24,21 @@ public class Token extends GeoPoint {
return tokenType;
}
public void setTokenType(TokenType tokenType) {
this.tokenType = tokenType;
/**
* Assigns a random type to the token (including the random type token)
*/
public void assignRandomType() {
tokenType = TokenType.values()[random.nextInt(TokenType.values().length)];
}
/**
* Assigns a random, concrete type to the token (cannot be the random type)
*/
public void realiseRandom() {
List<TokenType> tokenTypeList = new ArrayList<>(Arrays.asList(TokenType.values()));
tokenTypeList.remove(TokenType.RANDOM);
tokenType = tokenTypeList.get(random.nextInt(tokenTypeList.size()));
}
}
@@ -8,8 +8,8 @@ public enum TokenType {
BOOST(0, "Boost"),
HANDLING(1, "Handling"),
BUMPER(2, "Bumper"),
RANDOM(3, "Random"),
WIND_WALKER(4, "Wind Walker");
WIND_WALKER(3, "Wind Walker"),
RANDOM(4, "Random");
private int value;
private String name;
@@ -26,15 +26,4 @@ public enum TokenType {
public String getName() {
return name;
}
public static TokenType getToken(int value) {
switch (value) {
case 0:
return BOOST;
case 1:
return HANDLING;
default:
return BOOST;
}
}
}