Package breitband.game.board
Class City
- java.lang.Object
-
- breitband.game.board.City
-
- All Implemented Interfaces:
java.lang.Comparable<City>
public class City extends java.lang.Object implements java.lang.Comparable<City>
Class containing all information regarding cities (such as location, direct connections, etc.) with some functionalities (such as distance between to cities) This class implements the Comparable interface so cities can get sorted by their x-coordinate- Author:
- Klara Schöbel
-
-
Constructor Summary
Constructors Constructor Description City(int x, int y, java.lang.String name, int maxConnections)
Constructs a city at the given coordinates, with a name and maximum capacity for connections
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDirectConnection(City cityB)
adds another city to vector containing all direct connections (directConnections)boolean
atMaxCapacity()
test if the max capacity has been reachedint
compareTo(City other)
Method needed for the implementation of the comparable interface.boolean
equals(java.lang.Object o)
Override for equals method to fit the logic behind cities,
cities are equal if they have the same name and coordinatesint
getActualConnections()
getter for actualConnectionsint
getDistanceBetweenCities(City cityB)
calculates the distance between this city and a given cityint
getMaxConnections()
getter for maxConnectionsjava.lang.String
getName()
getter for nameint
getX()
getter for xPosint
getY()
getter for yPosboolean
hasDirectConnections(City cityB)
tests for direct connection between this city and another given cityvoid
setActualConnections()
setter for actual Connections (since only one connection can be made at a time it only increments)
-
-
-
Constructor Detail
-
City
public City(int x, int y, java.lang.String name, int maxConnections)
Constructs a city at the given coordinates, with a name and maximum capacity for connections- Parameters:
x
- x Coordinate (see alsogetX()
)y
- y Coordinate (see alsogetY()
)name
- Name of the city (see alsogetName()
)maxConnections
- number of possible connections (see alsogetMaxConnections()
)
-
-
Method Detail
-
addDirectConnection
public void addDirectConnection(City cityB)
adds another city to vector containing all direct connections (directConnections)- Parameters:
cityB
- city-object this city has a direct connection to
-
hasDirectConnections
public boolean hasDirectConnections(City cityB)
tests for direct connection between this city and another given city- Parameters:
cityB
- a city-object to be tested- Returns:
- if there is a direct connection to cityB
-
getDistanceBetweenCities
public int getDistanceBetweenCities(City cityB)
calculates the distance between this city and a given city- Parameters:
cityB
- a city-object- Returns:
- distance to the given city object
-
getX
public int getX()
getter for xPos- Returns:
- x coordinate of this city
-
getY
public int getY()
getter for yPos- Returns:
- y coordinate of this city
-
getName
public java.lang.String getName()
getter for name- Returns:
- name of this city
-
getMaxConnections
public int getMaxConnections()
getter for maxConnections- Returns:
- maximal number of connections possible in this city
-
getActualConnections
public int getActualConnections()
getter for actualConnections- Returns:
- number of actual connections
-
setActualConnections
public void setActualConnections()
setter for actual Connections (since only one connection can be made at a time it only increments)
-
atMaxCapacity
public boolean atMaxCapacity()
test if the max capacity has been reached- Returns:
- if there are less actual connections than possible connections
-
compareTo
public int compareTo(City other)
Method needed for the implementation of the comparable interface. Used to sort the cities in the board class by their x-coordinate.- Specified by:
compareTo
in interfacejava.lang.Comparable<City>
-
equals
public boolean equals(java.lang.Object o)
Override for equals method to fit the logic behind cities,
cities are equal if they have the same name and coordinates- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- object (city) to be compared with- Returns:
- if the two objects are equal
-
-