Did commenting

This commit is contained in:
Malte Tammena 2017-10-20 13:57:50 +02:00
parent b0a1999b94
commit 54b015ec77

View file

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