de.uni_paderborn.robots.data
Class Fields

java.lang.Object
  |
  +--de.uni_paderborn.robots.data.Fields
All Implemented Interfaces:
java.io.Serializable

public class Fields
extends java.lang.Object
implements java.io.Serializable

This class is used to save the fields of the arena and its contents. It provides an interface for access to certain fields or fields with specified items. The class Fields implements the Serializable interface to save and load arena data easily from and to a disk file.

See Also:
Serialized Form

Field Summary
private  java.util.HashSet cards
          all cards
private  boolean exitPlaced
          true, if an exit is placed in the arena
private  Field[][] fields
          the fields of the arena in matrix representation
private  int height
          height of the arena
private  java.util.HashSet robotFields
          all robot fields
private  java.util.HashSet robots
          all robots
static long serialVersionUID
          used for serialization
private  int width
          width of the arena
private  java.util.HashSet wormholes
          all wormholes
 
Constructor Summary
Fields(int width, int height)
          constructor, creates a new arena matrix with the specified width and height
 
Method Summary
 void addCard(Card card)
          Adds card to hashset.
 void addRobot(Robot robot)
          Adds robot to hashset.
 void addRobotField(RobotField robotField)
          Adds robot field to hashset.
 void addWormhole(Wormhole wormhole)
          Adds wormhole to hashset.
 boolean exitOccurs()
          Determines if exit occurs in the arena.
 void exitStatus(boolean placed)
          This method is called to inform this class that an exit was placed / removed.
 java.util.HashSet getAllIDs()
          This method returns all IDs for this Fields object.
 java.util.HashSet getCards()
          Returns a hashset containing all cards in the arena.
 Fields getDuplicate()
          This method duplicates this object.
 Field getField(int x, int y)
          Returns the field with the specified coordinates.
 Field getFieldInDirection(Field currentField, int direction)
          This method calculates calculates a field in a specified direction
 int getHeight()
          Returns height of arena in matrix representation.
 java.util.HashSet getRobotFields()
          Returns a hashset containing all robot fields in the arena.
 java.util.HashSet getRobots()
          Returns a hashset containing all robots in the arena.
 int getWidth()
          Returns width of arena in matrix representation.
 java.util.HashSet getWormholes()
          Returns a hashset containing all wormholes in the arena.
 boolean moveRobot(Robot robot, ArenaCanvas canvas)
          This method manages the movement of the robot when the method is called the robot will be moved toward the direction it is looking to and a GUI update will be performed
 void removeCard(Card card)
          Removes card from hashset.
 void removeRobot(Robot robot)
          Removes robot from hashset.
 void removeRobotField(RobotField robotField)
          Removes robot field from hashset.
 void removeWormhole(Wormhole wormhole)
          Removes wormhole from hashset.
 boolean replaceRobot(Robot robot, Field newField, ArenaCanvas canvas)
          This method is called to replace a robot
 void turnRobot(Robot robot, int bearing, ArenaCanvas canvas)
          This method turns the robot into the specified direction
 boolean wormholesAreLinked()
          This method is called to check if all wormholes are linked.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
used for serialization

fields

private Field[][] fields
the fields of the arena in matrix representation

width

private int width
width of the arena

height

private int height
height of the arena

robots

private java.util.HashSet robots
all robots

robotFields

private java.util.HashSet robotFields
all robot fields

cards

private java.util.HashSet cards
all cards

wormholes

private java.util.HashSet wormholes
all wormholes

exitPlaced

private boolean exitPlaced
true, if an exit is placed in the arena
Constructor Detail

Fields

public Fields(int width,
              int height)
constructor, creates a new arena matrix with the specified width and height
Method Detail

getField

public Field getField(int x,
                      int y)
               throws java.lang.ArrayIndexOutOfBoundsException
Returns the field with the specified coordinates.
Parameters:
x - x-coordinate of the wanted field
y - y-coordinate of the wanted field
Returns:
field at position (x,y) in the arena matrix
Throws:
java.lang.ArrayIndexOutOfBoundsException - if an invalid position is given

getWidth

public int getWidth()
Returns width of arena in matrix representation.
Returns:
width of arena in matrix representation

getHeight

public int getHeight()
Returns height of arena in matrix representation.
Returns:
height of arena in matrix representation

getRobots

public java.util.HashSet getRobots()
Returns a hashset containing all robots in the arena.
Returns:
hashset containing all robots in the arena

getRobotFields

public java.util.HashSet getRobotFields()
Returns a hashset containing all robot fields in the arena.
Returns:
hashset containing all robot fields in the arena

getCards

public java.util.HashSet getCards()
Returns a hashset containing all cards in the arena.
Returns:
hashset containing all cards in the arena

getWormholes

public java.util.HashSet getWormholes()
Returns a hashset containing all wormholes in the arena.
Returns:
hashset containing all wormholes in the arena

addRobot

public void addRobot(Robot robot)
Adds robot to hashset.
Parameters:
a - robot

addRobotField

public void addRobotField(RobotField robotField)
Adds robot field to hashset.
Parameters:
a - robot field

addCard

public void addCard(Card card)
Adds card to hashset.
Parameters:
a - card

addWormhole

public void addWormhole(Wormhole wormhole)
Adds wormhole to hashset.
Parameters:
a - wormhole

removeRobot

public void removeRobot(Robot robot)
Removes robot from hashset.
Parameters:
a - robot

removeRobotField

public void removeRobotField(RobotField robotField)
Removes robot field from hashset.
Parameters:
a - robot field

removeCard

public void removeCard(Card card)
Removes card from hashset.
Parameters:
a - card

removeWormhole

public void removeWormhole(Wormhole wormhole)
Removes wormhole from hashset.
Parameters:
a - wormhole

exitOccurs

public boolean exitOccurs()
Determines if exit occurs in the arena.
Returns:
true, if exit occurs in arena, false, if not

exitStatus

public void exitStatus(boolean placed)
This method is called to inform this class that an exit was placed / removed.
Parameters:
placed - true, if exit was placed, else, if it has been removed

wormholesAreLinked

public boolean wormholesAreLinked()
This method is called to check if all wormholes are linked.
Returns:
true, if wormholes are linked, false, if not

getAllIDs

public java.util.HashSet getAllIDs()
This method returns all IDs for this Fields object.
Returns:
IDs for Fields object

turnRobot

public void turnRobot(Robot robot,
                      int bearing,
                      ArenaCanvas canvas)
This method turns the robot into the specified direction
Parameters:
robot - reference to the robot
direction - the direction the robot should be turned to
ArenaCanvas - reference to the canvas which should be updated

moveRobot

public boolean moveRobot(Robot robot,
                         ArenaCanvas canvas)
This method manages the movement of the robot when the method is called the robot will be moved toward the direction it is looking to and a GUI update will be performed
Parameters:
robot - reference to the robot
ArenaCanvas - reference to the canvas which should be updated
Returns:
boolean true if the action has been performed

getFieldInDirection

public Field getFieldInDirection(Field currentField,
                                 int direction)
This method calculates calculates a field in a specified direction
Parameters:
reference - to the current field
direction - to the field which should be returned
Returns:
reference to a field in the direction

replaceRobot

public boolean replaceRobot(Robot robot,
                            Field newField,
                            ArenaCanvas canvas)
This method is called to replace a robot
Parameters:
robot - reference to the robot
newField - reference to the field were the robot should be placed
ArenaCanvas - reference to the canvas which should be updated
Returns:
boolean true if the action has been performed

getDuplicate

public Fields getDuplicate()
This method duplicates this object. We do not use clone(), because we want to have a deep copy and not a swallow copy!
Returns:
copy of this object