mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +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:
@@ -283,10 +283,9 @@ public class GameState implements Runnable {
|
||||
Random random = new Random();
|
||||
tokensInPlay.clear();
|
||||
|
||||
//Get a random token location
|
||||
//Get a random token location with random type
|
||||
Token token = allTokens.get(random.nextInt(allTokens.size()));
|
||||
//Set a random type to this token
|
||||
token.setTokenType(TokenType.values()[random.nextInt(TokenType.values().length)]);
|
||||
token.assignRandomType();
|
||||
|
||||
tokensInPlay.add(token);
|
||||
}
|
||||
@@ -389,6 +388,7 @@ public class GameState implements Runnable {
|
||||
//Yacht Collision
|
||||
ServerYacht collidedYacht = checkYachtCollision(serverYacht);
|
||||
Mark collidedMark = checkMarkCollision(serverYacht);
|
||||
Token collidedToken = checkTokenPickUp(serverYacht);
|
||||
|
||||
if (collidedYacht != null) {
|
||||
GeoPoint originalLocation = serverYacht.getLocation();
|
||||
@@ -433,8 +433,10 @@ public class GameState implements Runnable {
|
||||
}
|
||||
|
||||
//Token Collision
|
||||
Token collidedToken = checkTokenPickUp(serverYacht);
|
||||
if (collidedToken != null) {
|
||||
if (collidedToken.getTokenType() == TokenType.RANDOM) {
|
||||
collidedToken.realiseRandom();
|
||||
}
|
||||
sendServerMessage(serverYacht.getSourceId(),
|
||||
serverYacht.getBoatName() + " has picked up a " + collidedToken.getTokenType()
|
||||
.getName() + " token");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,6 +446,16 @@ public class GameClient {
|
||||
// TODO: 11/09/17 wmu16 - Add in functionality to viually indicate a pickup to a user
|
||||
private void showTokenPickUp(TokenType tokenType) {
|
||||
Sounds.playTokenPickupSound();
|
||||
switch (tokenType) {
|
||||
case BOOST:
|
||||
break;
|
||||
case HANDLING:
|
||||
break;
|
||||
case WIND_WALKER:
|
||||
break;
|
||||
case BUMPER:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void formatAndSendChatMessage(String rawChat) {
|
||||
|
||||
Reference in New Issue
Block a user