java.lang.Object
it.polimi.ingsw.model.Worker
public class Worker
extends java.lang.Object
Worker representation
The Workers are the pawns of this game. By default, each player gets at the beginning of the game two workers,
which are placed on an empty Cell of the board, at the beginning of the game.
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description WorkercloneWorker()Creates a clone of this workerbooleanequals(java.lang.Object o)Compares the argument to the receiver, and answers true if their coordinates and color are equalsColorgetColor()color getterCellgetPosition()position getterinthashCode()voidsetPosition(Cell position)position setterjava.lang.StringtoString()
-
Constructor Details
-
Worker
Class ConstructorThe constructor sets the two class attributes and assigns the occupiedBy field in the given cell to the newly created worker.
This constructor is also used to restore a previous state in case of a server failure.- Parameters:
position- the cell to place the new worker oncolor- the color of the worker
-
-
Method Details
-
getColor
color getter- Returns:
- the color of the worker
-
getPosition
position getter- Returns:
- the Cell containing the Worker
-
setPosition
position setterUsed to move a Worker around on the map; this method does not refresh the occupiedBy attribute in the corresponding
Cell.- Parameters:
position- the Cell to move the Worker to
-
cloneWorker
Creates a clone of this worker- Returns:
- a clone of the worker
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)Compares the argument to the receiver, and answers true if their coordinates and color are equals- Overrides:
equalsin classjava.lang.Object- Parameters:
o- the object to be compared with this- Returns:
- true if the object is the same as the cell, false otherwise
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-