- All Implemented Interfaces:
java.io.Serializable
public class Cell
extends java.lang.Object
implements java.io.Serializable
class contains all information about a cell inside a gameBoard, such as:
This class uses JacksonAnnotations to export the internal status to an external JSON file, in order to save the current state and recover it in case of a server failure.- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Cell
cloneCell()
Creates a clone of the cellboolean
equals(java.lang.Object o)
Compares the argument to the receiver, and answers true if their coordinates and blocks built (including dome) are equalsBlock
getBlock()
block getterint
getCoordX()
coordX getterint
getCoordY()
coordY getterWorker
getOccupiedBy()
occupiedBy getterboolean
hasDome()
hasDome getterint
hashCode()
int
heightDifference(Cell cell)
Provides the height difference between two cellsvoid
setBlock(Block block)
block settervoid
setHasDome(boolean hasDome)
hasDome settervoid
setOccupiedBy(Worker occupiedBy)
occupiedBy setterjava.lang.String
toString()
-
Constructor Details
-
Cell
public Cell(int coordX, int coordY)Default constructorCreates a new Cell, assigning its coordinates. At the time of their creation, the Cells are empty; this means that there are no buildings nor workers.
- Parameters:
coordX
- the X coordinate of the cell to createcoordY
- the Y coordinate of the cell to create
-
Cell
Jackson ConstructorLoads a previously saved Cell state; the Cell is "reassembled" in this constructor (after reading the saved state from file) instead of being built during the file parsing to avoid reference problems.
- Parameters:
coordX
- the X coordinate of the cell to restorecoordY
- the Y coordinate of the cell to restorehasDome
- the hasDome flag of the cell to restoreoccupiedBy
- the Worker occupying the cellblock
- the building block on the cell
-
-
Method Details
-
getCoordX
public int getCoordX()coordX getter- Returns:
- the X coordinate of the cell
-
getCoordY
public int getCoordY()coordY getter- Returns:
- the Y coordinate of the cell
-
hasDome
public boolean hasDome()hasDome getter- Returns:
- true if there is a dome on the cell, false otherwise
-
setHasDome
public void setHasDome(boolean hasDome)hasDome setterFollowing the classic game flow, this method is used only to set the hasDome attribute to true upon a dome construction; since there might be additional gods that allows a dome to be removed, we decided to leave it as a setter. At the current stage of development, this method is always called passing true as a parameter.
- Parameters:
hasDome
- boolean flag to notify the dome presence
-
getOccupiedBy
occupiedBy getter- Returns:
- the
Worker
on the cell if present, null otherwise
-
setOccupiedBy
occupiedBy setter- Parameters:
occupiedBy
- the Worker to be placed on the cell
-
getBlock
block getter- Returns:
- the last Block built on the cell
-
setBlock
block setter- Parameters:
block
- the Block to build on the cell
-
heightDifference
Provides the height difference between two cellsReturns the height difference as (parameterCell.height - thisCell.height).
The height difference between two cells is defined as the difference between the Blocks built on the two cells.- Parameters:
cell
- the Cell to compare- Returns:
- the height difference
-
cloneCell
Creates a clone of the cellUsing the private constructor to create a new Cell instance having the same attributes; used to clone and send the gameBoard over the network.
- Returns:
- a clone of the cell
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)Compares the argument to the receiver, and answers true if their coordinates and blocks built (including dome) are equals- Overrides:
equals
in 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:
hashCode
in classjava.lang.Object
-