Boat collision packets are now sent. Command class created for boat collision. Currently prints out message depending on if user crashed or someone else crashed. #story[1195]
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
package visualiser.Commands.VisualiserRaceCommands;
|
||||
|
||||
import mock.model.commandFactory.Command;
|
||||
import network.Messages.YachtEvent;
|
||||
import visualiser.model.VisualiserRaceState;
|
||||
|
||||
/**
|
||||
* Created by zwu18 on 4/09/17.
|
||||
*/
|
||||
public class BoatCollisionCommand implements Command {
|
||||
|
||||
YachtEvent yachtEvent;
|
||||
|
||||
VisualiserRaceState visualiserRace;
|
||||
|
||||
public BoatCollisionCommand(YachtEvent yachtEvent, VisualiserRaceState visualiserRace){
|
||||
this.yachtEvent = yachtEvent;
|
||||
this.visualiserRace = visualiserRace;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
if(visualiserRace.getPlayerBoatID()==yachtEvent.getSourceID()){
|
||||
System.out.println("Someone else crashed!");
|
||||
} else {
|
||||
System.out.println("I crashed!");
|
||||
}
|
||||
|
||||
//System.out.println("Collision command executed!");
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -23,7 +23,9 @@ public class VisualiserRaceCommandFactory {
|
||||
|
||||
switch (message.getType()) {
|
||||
|
||||
case BOATLOCATION: return new BoatLocationCommand((BoatLocation) message, visualiserRace);
|
||||
case BOATLOCATION:
|
||||
//System.out.println("Boat location received");
|
||||
return new BoatLocationCommand((BoatLocation) message, visualiserRace);
|
||||
|
||||
case RACESTATUS: return new RaceStatusCommand((RaceStatus) message, visualiserRace);
|
||||
|
||||
@@ -31,6 +33,11 @@ public class VisualiserRaceCommandFactory {
|
||||
|
||||
case ASSIGN_PLAYER_BOAT: return new AssignPlayerBoatCommand((AssignPlayerBoat) message, visualiserRace);
|
||||
|
||||
case YACHTEVENTCODE:
|
||||
return new BoatCollisionCommand((YachtEvent) message, visualiserRace);
|
||||
|
||||
|
||||
|
||||
default: throw new CommandConstructionException("Could not create VisualiserRaceCommand. Unrecognised or unsupported MessageType: " + message.getType());
|
||||
|
||||
}
|
||||
|
||||
@@ -96,15 +96,15 @@ public class App extends Application {
|
||||
);
|
||||
|
||||
updateMessage("Preparing ingredients . . .");
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(100);
|
||||
for (int i = 0; i < burgerFilling.size(); i++) {
|
||||
Thread.sleep(800);
|
||||
Thread.sleep(100);
|
||||
updateProgress(i + 1, burgerFilling.size());
|
||||
String nextFilling = burgerFilling.get(i);
|
||||
addedFilling.add(nextFilling);
|
||||
updateMessage("Adding the " + nextFilling + " . . .");
|
||||
}
|
||||
Thread.sleep(400);
|
||||
Thread.sleep(100);
|
||||
updateMessage("Burger's done!");
|
||||
|
||||
return addedFilling;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class VisualiserRaceController implements RunnableWithFramePeriod {
|
||||
compositeRaceCommand.addCommand(command);
|
||||
|
||||
} catch (CommandConstructionException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "VisualiserRaceController could not create a command for incoming message.");
|
||||
//Logger.getGlobal().log(Level.WARNING, "VisualiserRaceController could not create a command for incoming message.");
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
Logger.getGlobal().log(Level.SEVERE, "VisualiserRaceController was interrupted on thread: " + Thread.currentThread() + " while waiting for messages.");
|
||||
|
||||
Reference in New Issue
Block a user