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());
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user