mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Removed Legs from the race, using coordinates instead
Tags: #implement #refactor #test #story[9]
This commit is contained in:
@@ -8,11 +8,12 @@ import java.util.Date;
|
||||
* event location such as leg.
|
||||
*/
|
||||
public class Event {
|
||||
|
||||
private long time; // Time the event occurs
|
||||
private Double time; // Time the event occurs
|
||||
private Boat boat;
|
||||
private Leg leg; // Leg of the race the event occurs on
|
||||
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
|
||||
private Mark mark1; // This mark
|
||||
private Mark mark2; // Next Mark
|
||||
|
||||
|
||||
/**
|
||||
* Event class containing the time of specific event, related team/boat, and
|
||||
@@ -20,12 +21,13 @@ public class Event {
|
||||
*
|
||||
* @param eventTime, what time the event happens
|
||||
* @param eventBoat, the boat that the event belongs to
|
||||
* @param eventLeg, the leg the event happens on
|
||||
*/
|
||||
public Event(long eventTime, Boat eventBoat, Leg eventLeg) {
|
||||
public Event(Double eventTime, Boat eventBoat, Mark mark1, Mark mark2) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.leg = eventLeg;
|
||||
//this.leg = eventLeg;
|
||||
this.mark1 = mark1;
|
||||
this.mark2 = mark2;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,14 +36,12 @@ public class Event {
|
||||
*
|
||||
* @param eventTime, what time the event happens
|
||||
* @param eventBoat, the boat that the event belongs to
|
||||
* @param eventLeg, the leg the event happens on
|
||||
* @param isFinishingEvent, true if this event is the boat crossing the finishing line
|
||||
*/
|
||||
public Event(long eventTime, Boat eventBoat, Leg eventLeg, boolean isFinishingEvent) {
|
||||
public Event(Double eventTime, Boat eventBoat, Mark mark1) {
|
||||
this.time = eventTime;
|
||||
this.boat = eventBoat;
|
||||
this.leg = eventLeg;
|
||||
this.isFinishingEvent = isFinishingEvent;
|
||||
this.mark1 = mark1;
|
||||
this.isFinishingEvent = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ public class Event {
|
||||
*
|
||||
* @return the time for event in millisecond
|
||||
*/
|
||||
public long getTime() {
|
||||
public double getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class Event {
|
||||
*
|
||||
* @param eventTime the time for event in millisecond
|
||||
*/
|
||||
public void setTime(long eventTime) {
|
||||
public void setTime(double eventTime) {
|
||||
this.time = eventTime;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class Event {
|
||||
* @return the string of time
|
||||
*/
|
||||
public String getTimeString() {
|
||||
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time));
|
||||
return (new SimpleDateFormat("mm:ss:SSS")).format(new Date(time.longValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,30 +89,12 @@ public class Event {
|
||||
this.boat = eventBoat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the involved location/leg
|
||||
*
|
||||
* @return the leg involved in the event
|
||||
*/
|
||||
public Leg getLeg() {
|
||||
return this.leg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the involved location/leg
|
||||
*
|
||||
* @param eventLeg the involved leg
|
||||
*/
|
||||
public void setLeg(Leg eventLeg) {
|
||||
this.leg = eventLeg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the boat in this event passes
|
||||
* the marker.
|
||||
*/
|
||||
public void boatPassedMarker() {
|
||||
this.leg.addBoatToMarker(boat);
|
||||
this.mark1.addBoat(boat);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,13 +110,45 @@ public class Event {
|
||||
* @return A string that details what happened in this event
|
||||
*/
|
||||
public String getEventString() {
|
||||
String currentHeading = Integer.toString(this.getLeg().getHeading());
|
||||
|
||||
// This event is a boat finishing the race
|
||||
if (this.isFinishingEvent) {
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
|
||||
}
|
||||
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.getLeg().getMarkerLabel() + " going heading " + currentHeading + "°");
|
||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the distance between the two marks
|
||||
*/
|
||||
public double getDistanceBetweenMarks(){
|
||||
return Math.sqrt(Math.pow(mark1.getLatitude()-mark2.getLatitude(), 2) + Math.pow(mark1.getLongitude()-mark2.getLongitude(), 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the boats heading
|
||||
*/
|
||||
public double getBoatHeading(){
|
||||
double bearing = Math.atan2(mark2.getLatitude() - mark1.getLatitude(), mark2.getLongitude() - mark1.getLongitude());
|
||||
if (bearing < 0) {
|
||||
bearing += Math.PI * 2;
|
||||
}
|
||||
return bearing * 180 / Math.PI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mark the event happened on
|
||||
* @return the mark
|
||||
*/
|
||||
public Mark getMark(){
|
||||
return this.mark1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next mark
|
||||
* @return the next mark
|
||||
*/
|
||||
public Mark getNextMark(){
|
||||
return this.mark2;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user