You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.4 KiB

package mock.model;
import shared.model.Bearing;
import java.util.Random;
public class Wind {
/**
* Used to generate random numbers when changing the wind direction.
*/
private int changeWind = 4;
/**
* The bearing the wind direction starts at.
*/
private Bearing windBearing;
/**
* The lower bearing angle that the wind may have.
*/
private Bearing windLowerBound;
/**
* The upper bearing angle that the wind may have.
*/
private Bearing windUpperBound;
double windSpeed;
public Wind() {
this.windBearing = Bearing.fromDegrees(225);
this.windSpeed = 12;
this.windLowerBound = Bearing.fromDegrees(215);
this.windUpperBound = Bearing.fromDegrees(235);
}
public Wind(Bearing windBearing, double windSpeed, Bearing windLowerBound, Bearing windUpperBound) {
this.windBearing = windBearing;
this.windSpeed = windSpeed;
this.windLowerBound = windLowerBound;
this.windUpperBound = windUpperBound;
}
/**
* Changes the wind direction randomly, while keeping it within [windLowerBound, windUpperBound].
*/
public void changeWindDirection() {
//Randomly add or remove 0.5 degrees.
int r = new Random().nextInt(changeWind) + 1;
if (r == 1) {
//Add 0.5 degrees to the wind bearing.
this.windBearing.setDegrees(this.windBearing.degrees() + 0.5);
} else if (r == 2) {
//Minus 0.5 degrees from the wind bearing.
this.windBearing.setDegrees(this.windBearing.degrees() - 0.5);
}
//Ensure that the wind is in the correct bounds.
if (this.windBearing.degrees() > this.windUpperBound.degrees()) {
this.windBearing.setBearing(this.windUpperBound);
} else if (this.windBearing.degrees() < this.windLowerBound.degrees()) {
this.windBearing.setBearing(this.windLowerBound);
}
}
public Bearing getWindDirection() {
return this.windBearing;
}
public double getWindSpeed() {
return this.windSpeed;
}
public void setWindDirection(Bearing windBearing) {
this.windBearing = windBearing;
}
public void setWindSpeed(double windSpeed) {
this.windSpeed = windSpeed;
}
public void setDegrees(double degrees) {
this.windBearing.setDegrees(degrees);
}
}