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.
59 lines
1.7 KiB
59 lines
1.7 KiB
package de.fd.fh;
|
|
|
|
public class Game
|
|
{
|
|
public Figure[] mField;
|
|
|
|
public static final int whiteRowOther = 7;
|
|
public static final int whiteRowFarmer = 6;
|
|
public static final int blackRowOther = 0;
|
|
public static final int blackRowFarmer = 1;
|
|
|
|
public void initNewGame()
|
|
{
|
|
mField = new Figure[Figure.fieldLength * Figure.fieldLength];
|
|
|
|
// Figuren platzieren
|
|
for (int i = 0; i < Figure.fieldLength; i++) // row
|
|
{
|
|
if (i == Game.whiteRowOther
|
|
|| i == Game.blackRowOther)
|
|
{
|
|
for (int j = 0; j < Figure.fieldLength; j++) // col
|
|
{
|
|
mField[i * Figure.fieldLength + j] = new Figure();
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < Figure.fieldLength; j++) // col
|
|
{
|
|
mField[Game.whiteRowFarmer * Figure.fieldLength + j] = new FigureFarmer(FigureFarmer.Color.White);
|
|
}
|
|
|
|
for (int j = 0; j < Figure.fieldLength; j++) // col
|
|
{
|
|
mField[Game.blackRowFarmer * Figure.fieldLength + j] = new FigureFarmer(FigureFarmer.Color.Black);
|
|
}
|
|
}
|
|
|
|
mField[Figure.fieldLength * 0 + 0] = new FigureRook(); // schwarzer Turm a8
|
|
mField[Figure.fieldLength * 0 + 7] = new FigureRook(); // schwarzer Turm h8
|
|
mField[Figure.fieldLength * 7 + 0] = new FigureRook(); // weißer Turm a1
|
|
mField[Figure.fieldLength * 7 + 7] = new FigureRook(); // weißer Turm h1
|
|
}
|
|
|
|
boolean moveFigure(int src, int dst)
|
|
{
|
|
Figure f = mField[src];
|
|
|
|
if (!f.moveAllowed(src, dst, mField))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
mField[dst] = f;
|
|
mField[src] = null;
|
|
|
|
return true;
|
|
}
|
|
}
|