Skip to content

Instantly share code, notes, and snippets.

@FarisR99
Last active August 29, 2015 14:04
Show Gist options
  • Save FarisR99/4e28c08b1d4e4a2dc036 to your computer and use it in GitHub Desktop.
Save FarisR99/4e28c08b1d4e4a2dc036 to your computer and use it in GitHub Desktop.
UK Mini-Game
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class Main {
public static void main(String[] args) {
final Random random = new Random();
Country country = new Country("United Kingdom", random.nextInt() - 300, random.nextInt() - 1000, 300, 1000);
country.addCity(new City("London", 250, 900));
country.addCity(new City("Manchester", 10, 500));
country.getCities().get(random.nextInt(country.getCities().size())).castLightning(random.nextInt(country.getCapitalCity().getWidth()), random.nextInt(country.getCapitalCity().getHeight()));
}
public static class Country {
private String countryName = "";
private int xCoord = 0, yCoord = 0, countryWidth = 0, countryHeight = 0;
private List<City> countryCities = new ArrayList<City>();
public Country(String countryName, int x, int y, int width, int height) {
this.countryName = countryName;
this.xCoord = x;
this.yCoord = y;
this.countryWidth = width;
this.countryHeight = height;
}
public Country addCity(City city) {
if (!this.countryCities.contains(city)) this.countryCities.add(city);
return this;
}
public City getCapitalCity() {
return !this.countryCities.isEmpty() ? this.countryCities.get(0) : null;
}
public List<City> getCities() {
return this.countryCities;
}
public String getCountryName() {
return this.countryName;
}
public int[] getCoords() {
return new int[] { this.xCoord, this.yCoord };
}
public int[] getSize() {
return new int[] { this.countryWidth, this.countryHeight };
}
}
public static class City {
private Country country = null;
private String cityName = "";
private int cityWidth = 0, cityHeight = 0;
public City(String cityName, int width, int height) {
this.cityName = cityName;
this.cityWidth = width;
this.cityHeight = height;
}
public void castLightning(int x, int y) {
System.out.println(this.cityName + " has been smitten at coordinates (" + x + ", " + y + ")");
}
public String getCityName() {
return this.cityName;
}
public Country getCounty() {
return this.country;
}
public int getWidth() {
return this.cityWidth;
}
public int getHeight() {
return this.cityHeight;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment