Created
April 21, 2014 18:59
-
-
Save afontaine/11152768 to your computer and use it in GitHub Desktop.
Implementation of captain's chair in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Class that represnets a "Captain's Chair" | |
* It extends the {@link Chair} class and implements the {@link Conn} interface, | |
* providing a place to sit and control of the ship | |
* | |
* TODO Make into a singleton pattern | |
*/ | |
class CaptainsChair extends Chair implements Conn { | |
/** | |
* Implements the {@link Officer} interface. Represents the captain. | |
*/ | |
private Officer captain; | |
/** | |
* Implements the {@link Officer} and {@link Position} interfaces. Represents the crew. | |
*/ | |
private Map<Position, Officer> crew; | |
/** | |
* Creates a new instance of captain's chair. | |
* | |
* @param off The officer who sits in the chiar | |
*/ | |
CaptainsChair(Officer off) { | |
super(); | |
officer.setConn(true); | |
user = off; | |
} | |
@Override | |
boolean hasTheConn() { | |
return true; | |
} | |
/** | |
* Deploy orders to all crew | |
* | |
* @param order The order to deploy | |
*/ | |
void deployOrders(Order order) { | |
for(Officer officer: this.crew) { | |
crew.setOrders(order); | |
} | |
} | |
/** | |
* Deploy orders to speficic crewmember | |
* @param order The order to deploy | |
*/ | |
void deployOrders(Order order, Officer off) { | |
for(Officer officer: this.crew) { | |
if(officer.equals(name)) { | |
officer.setOrders(order); | |
return; | |
} | |
} | |
} | |
/** | |
* Sets course for ship | |
* | |
* @param order Contains the new course for the ship | |
*/ | |
void setCourse(Order order) { | |
Position helm = new Position("Helm"); | |
Office helmsman = crew.get(helm); | |
if(helmsman != null) | |
deployOrders(order, helmsman) | |
else { | |
this.deployOrders(order, this.captain); | |
} | |
} | |
/* | |
* Not implemented due to trivial nature | |
*/ | |
Collection<Officer> getCrew() {} | |
Officer getCrewMember(String name){} | |
void setCrew() {} | |
void addCrewMember(Officer off) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment