mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user