Module AM37

Class Worker

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

    Constructors 
    Constructor Description
    Worker​(Cell position, Color color)
    Class Constructor
  • Method Summary

    Modifier and Type Method Description
    Worker cloneWorker()
    Creates a clone of this worker
    boolean equals​(java.lang.Object o)
    Compares the argument to the receiver, and answers true if their coordinates and color are equals
    Color getColor()
    color getter
    Cell getPosition()
    position getter
    int hashCode()  
    void setPosition​(Cell position)
    position setter
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Worker

      public Worker​(Cell position, Color color)
      Class Constructor

      The 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 on
      color - the color of the worker
  • Method Details

    • getColor

      public Color getColor()
      color getter
      Returns:
      the color of the worker
    • getPosition

      public Cell getPosition()
      position getter
      Returns:
      the Cell containing the Worker
    • setPosition

      public void setPosition​(Cell position)
      position setter

      Used 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

      public Worker cloneWorker()
      Creates a clone of this worker
      Returns:
      a clone of the worker
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.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:
      equals in class java.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 class java.lang.Object