Did commenting

This commit is contained in:
Malte Tammena 2017-10-20 13:57:50 +02:00 committed by Maurizio Bruetsch
parent a4110b96a2
commit 62f6466370

View file

@ -1,15 +1,43 @@
package player.malte;
/**
* An item of a pattern for the game of Connect Four.
*/
public class Item {
/**
* The relative horizontal position of the item.
*/
private int posX;
/**
* The relative vertical position of the item.
*/
private int posY;
/**
* The IDs this item recognizes valid.
*/
private int[] ids;
/**
* Basic constructor.
*
* @param posX Relative horizontal position.
* @param posY Relative vertical position.
* @param The accepted id.
*/
public Item(int posX, int posY, int id) {
this(posX, posY, new int[]{id});
}
/**
* Basic constructor for multiple IDs.
*
* @param posX Relative horizontal position.
* @param posY Relative vertical position.
* @param The accepted IDs.
*/
public Item(int posX, int posY, int[] ids) {
this.posX = posX;
this.posY = posY;
@ -37,12 +65,22 @@ public class Item {
return false;
}
/**
* Changes the given oldID to the newID.
* If newID already exists, do nothing.
* IF oldID does not exist, do nothing.
*
* @param oldID The ID to be replaced.
* @param newID The new ID.
*/
public void changeID(int oldID, int newID) {
// If the ID already exists, do nothing.
for (int id: ids) {
if (id == newID) {
return;
}
}
// Otherwise replace it, if oldID exists.
for (int i = 0; i < ids.length; i++) {
if (ids[i] == oldID) {
ids[i] = newID;
@ -60,6 +98,11 @@ public class Item {
return s + "])";
}
/**
* Returns a deep copy of the item.
*
* @return A deep copy of this element.
*/
public Item copy() {
return new Item(posX, posY, ids);
}