Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file modified Code & Resources/design-docs/WBA/WorkBreakdown.txt.odt
Binary file not shown.
107 changes: 57 additions & 50 deletions Code & Resources/src/starwars/SWActor.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Class that represents an Actor (i.e. something that can perform actions) in the starwars world.
*
*
* @author ram
*
*
* @modified 20130414 dsquire
* - changed constructor so that affordances that all SWActors must have can be added
* - changed team to be an enum rather than a string
Expand All @@ -28,31 +28,31 @@
import starwars.actions.Move;

public abstract class SWActor extends Actor<SWActionInterface> implements SWEntityInterface {

/**the <code>Team</code> to which this <code>SWActor</code> belongs to**/
private Team team;

/**The amount of <code>hitpoints</code> of this actor. If the hitpoints are zero or less this <code>Actor</code> is dead*/
private int hitpoints;

/**The world this <code>SWActor</code> belongs to.*/
protected SWWorld world;

/**Scheduler to schedule this <code>SWActor</code>'s events*/
protected static Scheduler scheduler;

/**The item carried by this <code>SWActor</code>. <code>itemCarried</code> is null if this <code>SWActor</code> is not carrying an item*/
private SWEntityInterface itemCarried;

/**If or not this <code>SWActor</code> is human controlled. <code>SWActor</code>s are not human controlled by default*/
protected boolean humanControlled = false;

/**A string symbol that represents this <code>SWActor</code>, suitable for display*/
private String symbol;

/**A set of <code>Capabilities</code> of this <code>SWActor</code>*/
private HashSet<Capability> capabilities;

/**
* Constructor for the <code>SWActor</code>.
* <p>
Expand All @@ -63,12 +63,12 @@ public abstract class SWActor extends Actor<SWActionInterface> implements SWEnti
* <li>All <code>SWActor</code>s can be attacked.</li>
* <li>Have their symbol set to '@'</li>
* </ul>
*
*
* @param team to which this <code>SWActor</code> belongs to
* @param hitpoints initial hitpoints of this <code>SWActor</code> to start with
* @param m message renderer for this <code>SWActor</code> to display messages
* @param world the <code>World</code> to which <code>SWActor</code> belongs to
*
*
* @see #team
* @see #hitpoints
* @see #world
Expand All @@ -81,27 +81,27 @@ public SWActor(Team team, int hitpoints, MessageRenderer m, SWWorld world) {
this.hitpoints = hitpoints;
this.world = world;
this.symbol = "@";

//SWActors are given the Attack affordance hence they can be attacked
SWAffordance attack = new Attack(this, m);
this.addAffordance(attack);
}

/**
* Sets the <code>scheduler</code> of this <code>SWActor</code> to a new <code>Scheduler s</code>
*
* @param s the new <code>Scheduler</code> of this <code>SWActor</code>
*
* @param s the new <code>Scheduler</code> of this <code>SWActor</code>
* @see #scheduler
*/
public static void setScheduler(Scheduler s) {
scheduler = s;
}

/**
* Returns the team to which this <code>SWActor</code> belongs to.
* <p>
* Useful in comparing the teams different <code>SWActor</code> belong to.
*
*
* @return the team of this <code>SWActor</code>
* @see #team
*/
Expand All @@ -111,8 +111,8 @@ public Team getTeam() {

/**
* Returns the hit points of this <code>SWActor</code>.
*
* @return the hit points of this <code>SWActor</code>
*
* @return the hit points of this <code>SWActor</code>
* @see #hitpoints
* @see #isDead()
*/
Expand All @@ -124,12 +124,12 @@ public int getHitpoints() {
/**
* Returns an ArrayList containing this Actor's available Actions, including the Affordances of items
* that the Actor is holding.
*
*
* @author ram
*/
public ArrayList<SWActionInterface> getActions() {
ArrayList<SWActionInterface> actionList = super.getActions();

//If the HobbitActor is carrying anything, look for its affordances and add them to the list
SWEntityInterface item = getItemCarried();
if (item != null)
Expand All @@ -138,15 +138,15 @@ public ArrayList<SWActionInterface> getActions() {
actionList.add((SWAffordance)aff);
return actionList;
}

/**
* Returns the item carried by this <code>SWActor</code>.
* Returns the item carried by this <code>SWActor</code>.
* <p>
* This method only returns the reference of the item carried
* This method only returns the reference of the item carried
* and does not remove the item held from this <code>SWActor</code>.
* <p>
* If this <code>SWActor</code> is not carrying an item this method will return null.
*
*
* @return the item carried by this <code>SWActor</code> or null if no item is held by this <code>SWActor</code>
* @see #itemCarried
*/
Expand All @@ -168,9 +168,9 @@ public void setTeam(Team team) {
}

/**
* Method insists damage on this <code>SWActor</code> by reducing a
* Method insists damage on this <code>SWActor</code> by reducing a
* certain amount of <code>damage</code> from this <code>SWActor</code>'s <code>hitpoints</code>
*
*
* @param damage the amount of <code>hitpoints</code> to be reduced
* @pre <code>damage</code> should not be negative
*/
Expand All @@ -182,20 +182,27 @@ public void takeDamage(int damage) {
}

/**
* Assigns this <code>SWActor</code>'s <code>itemCarried</code> to
* Method implements regeneration on this <code>SWActor</code> by increasing...
*
* @param damage the amount of <code>hitpoints</code> to be reduced
* @pre <code>damage</code> should not be negative
*/

/**
* Assigns this <code>SWActor</code>'s <code>itemCarried</code> to
* a new item <code>target</code>
* <p>
* This method will replace items already held by the <code>SWActor</code> with the <code>target</code>.
* A null <code>target</code> would signify that this <code>SWActor</code> is not carrying an item anymore.
*
*
* @param target the new item to be set as item carried
* @see #itemCarried
*/
public void setItemCarried(SWEntityInterface target) {
this.itemCarried = target;
}


/**
* Returns true if this <code>SWActor</code> is dead, false otherwise.
* <p>
Expand All @@ -208,72 +215,72 @@ public void setItemCarried(SWEntityInterface target) {
public boolean isDead() {
return hitpoints <= 0;
}


@Override
public String getSymbol() {
return symbol;
}


@Override
public void setSymbol(String s) {
symbol = s;
}

/**
* Returns if or not this <code>SWActor</code> is human controlled.
* <p>
* Human controlled <code>SWActors</code>' <code>SWActions</code> are selected by the user as commands from the Views.
*
*
* @return true if the <code>SWActor</code> is controlled by a human, false otherwise
* @see #humanControlled
*/
public boolean isHumanControlled() {
return humanControlled;
}


@Override
public boolean hasCapability(Capability c) {
return capabilities.contains(c);
}

/**
* This method will poll this <code>SWActor</code>'s current <code>Location loc</code>
* to find potential exits, and replaces all the instances of <code>Move</code>
* in this <code>SWActor</code>'s command set with <code>Moves</code> to the new exits.
* <p>
* This method doesn't affect other non-movement actions in this <code>SWActor</code>'s command set.
*
*
* @author ram
* @param loc this <code>SWActor</code>'s location
* @pre <code>loc</code> is the actual location of this <code>SWActor</code>
*/
public void resetMoveCommands(Location loc) {
HashSet<SWActionInterface> newActions = new HashSet<SWActionInterface>();

// Copy all the existing non-movement options to newActions
for (SWActionInterface a: actions) {
if (!a.isMoveCommand())
newActions.add(a);
}

// add new movement possibilities
for (CompassBearing d: CompassBearing.values()) {
for (CompassBearing d: CompassBearing.values()) {
if (loc.getNeighbour(d) != null) //if there is an exit from the current location in direction d, add that as a Move command
newActions.add(new Move(d,messageRenderer, world));
newActions.add(new Move(d,messageRenderer, world));
}

// replace command list of this SWActor
this.actions = newActions;
this.actions = newActions;

// TODO: This assumes that the only actions are the Move actions. This will clobber any others. Needs to be fixed.
/* Actually, that's not the case: all non-movement actions are transferred to newActions before the movements are transferred. --ram */
}





}
Loading