refactor: generated equals, hashCode and toString for entity classes
This commit is contained in:
parent
1cb2c145d1
commit
28ac25fa55
@ -2,6 +2,8 @@ package uulm.teamname.marvelous.gamelibrary.entities;
|
|||||||
|
|
||||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Represents a playable character inside a match. */
|
/** Represents a playable character inside a match. */
|
||||||
public class Character extends Entity {
|
public class Character extends Entity {
|
||||||
/** The name of the character */
|
/** The name of the character */
|
||||||
@ -72,4 +74,33 @@ public class Character extends Entity {
|
|||||||
clone.ap.setValue(ap.getValue());
|
clone.ap.setValue(ap.getValue());
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
Character character = (Character) o;
|
||||||
|
return attackRange == character.attackRange && rangedDamage == character.rangedDamage && meleeDamage == character.meleeDamage && Objects.equals(name, character.name) && Objects.equals(hp, character.hp) && Objects.equals(mp, character.mp) && Objects.equals(ap, character.ap) && Objects.equals(inventory, character.inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), name, hp, mp, ap, attackRange, rangedDamage, meleeDamage, inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Character{" +
|
||||||
|
"name='" + name + '\'' +
|
||||||
|
", hp=" + hp +
|
||||||
|
", mp=" + mp +
|
||||||
|
", ap=" + ap +
|
||||||
|
", attackRange=" + attackRange +
|
||||||
|
", rangedDamage=" + rangedDamage +
|
||||||
|
", meleeDamage=" + meleeDamage +
|
||||||
|
", inventory=" + inventory +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package uulm.teamname.marvelous.gamelibrary.entities;
|
|||||||
|
|
||||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Represents an infinity stone {@link Entity}. Can only exist on the map. */
|
/** Represents an infinity stone {@link Entity}. Can only exist on the map. */
|
||||||
public class InfinityStone extends Entity {
|
public class InfinityStone extends Entity {
|
||||||
/** The {@link StoneType} of the infinity stone */
|
/** The {@link StoneType} of the infinity stone */
|
||||||
@ -24,4 +26,26 @@ public class InfinityStone extends Entity {
|
|||||||
public InfinityStone clone() {
|
public InfinityStone clone() {
|
||||||
return new InfinityStone(id, position, type);
|
return new InfinityStone(id, position, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
InfinityStone that = (InfinityStone) o;
|
||||||
|
return type == that.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "InfinityStone{" +
|
||||||
|
"type=" + type +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package uulm.teamname.marvelous.gamelibrary.entities;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Represents an inventory of 6 slots of {@link StoneType}s that can be manipulated. */
|
/** Represents an inventory of 6 slots of {@link StoneType}s that can be manipulated. */
|
||||||
public class Inventory implements Iterable<StoneType> {
|
public class Inventory implements Iterable<StoneType> {
|
||||||
@ -79,4 +80,27 @@ public class Inventory implements Iterable<StoneType> {
|
|||||||
public Iterator<StoneType> iterator() {
|
public Iterator<StoneType> iterator() {
|
||||||
return content.iterator();
|
return content.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Inventory that = (Inventory) o;
|
||||||
|
return size == that.size && Objects.equals(content, that.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(size, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Inventory{" +
|
||||||
|
"size=" + size +
|
||||||
|
", content=" + content +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package uulm.teamname.marvelous.gamelibrary.entities;
|
|||||||
|
|
||||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Represents a rock entity on the map. */
|
/** Represents a rock entity on the map. */
|
||||||
public class Rock extends Entity {
|
public class Rock extends Entity {
|
||||||
/** The maximum hp of the rock */
|
/** The maximum hp of the rock */
|
||||||
@ -38,4 +40,29 @@ public class Rock extends Entity {
|
|||||||
clone.hp = hp;
|
clone.hp = hp;
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
if (!super.equals(o)) return false;
|
||||||
|
Rock rock = (Rock) o;
|
||||||
|
return maxHP == rock.maxHP && hp == rock.hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), maxHP, hp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Rock{" +
|
||||||
|
"maxHP=" + maxHP +
|
||||||
|
", hp=" + hp +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package uulm.teamname.marvelous.gamelibrary.entities;
|
package uulm.teamname.marvelous.gamelibrary.entities;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Represents a stat property of a {@link Character}. */
|
/** Represents a stat property of a {@link Character}. */
|
||||||
public class Stat {
|
public class Stat {
|
||||||
/** The {@link StatType} of the stat */
|
/** The {@link StatType} of the stat */
|
||||||
@ -37,4 +39,27 @@ public class Stat {
|
|||||||
public void decreaseValue(int value) {
|
public void decreaseValue(int value) {
|
||||||
this.value -= value;
|
this.value -= value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Stat stat = (Stat) o;
|
||||||
|
return max == stat.max && value == stat.value && type == stat.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(type, max, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Stat{" +
|
||||||
|
"type=" + type +
|
||||||
|
", max=" + max +
|
||||||
|
", value=" + value +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user