![JAR search and dependency download from the Maven repository](/logo.png)
com.brettonw.game.Move Maven / Gradle / Ivy
The newest version!
package com.brettonw.game;
public class Move {
private int x;
private int y;
public Move (int x, int y) throws InvalidMoveException {
if ((x >= 0) && (x < Board.DIMENSION) && (y >= 0) && (y < Board.DIMENSION)) {
this.x = x;
this.y = y;
} else {
throw new InvalidMoveException (x, y);
}
}
public int getX () {
return x;
}
public int getY () {
return y;
}
public int getOffset () {
return (y * Board.DIMENSION) + x;
}
@Override
public String toString () {
return "(" + x + ", " + y + ")";
}
@Override
public boolean equals (Object obj) {
boolean result = obj instanceof Move;
Move move = (Move) obj;
result &= (getOffset () == move.getOffset ());
return result;
}
@Override
public int hashCode () {
return getOffset ();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy