You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.4 KiB
67 lines
1.4 KiB
package de.fd.fh;
|
|
|
|
public class FigureFarmer extends Figure
|
|
{
|
|
enum Color { Black, White};
|
|
public Color mColor;
|
|
|
|
public FigureFarmer(Color colorCode)
|
|
{
|
|
mColor = colorCode;
|
|
}
|
|
|
|
@Override
|
|
public boolean moveAllowed(int src, int dst, Figure[] field)
|
|
{
|
|
int rowDiff = src / fieldLength - dst / fieldLength; // hoch/runter
|
|
|
|
if (mColor == Color.Black)
|
|
{
|
|
rowDiff *= -1;
|
|
}
|
|
|
|
if (rowDiff > 1) // Bauer nicht mehr als 1 Schritt
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (rowDiff <= 0) // Bauer nur Schritte in erlaubte Richtung (weiß -> hoch, schwarz -> runter)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// TODO: nur ein Schritt nach oben, wenn auf Ziel keine Figur
|
|
// TODO: links, rechts verboten
|
|
// TODO: Diagonal links/rechts hoch, wenn Figur geschlagen werden kann (Figur auf Ziel)
|
|
|
|
return super.moveAllowed(src, dst, field);
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o)
|
|
{
|
|
if (o == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (this == o)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (this.getClass() != o.getClass())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
FigureFarmer otherFigure = (FigureFarmer)o;
|
|
|
|
if (this.mColor != otherFigure.mColor)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|