This commit is contained in:
vimo 2025-03-01 16:04:33 +01:00
parent 2ae13ee689
commit 398bfc7a8d
2 changed files with 84 additions and 57 deletions

View File

@ -6,7 +6,6 @@ public class Board {
private static final int SIZE = 8;
private Field field;
private final Piece[/* column */][/* row */] grid;
public Board() {
@ -60,15 +59,27 @@ public class Board {
* just getting replaced.
*/
public void move(Field from, Field to) {
System.out.println(getPiece(from).getType());
System.out.println(from.getColumn());
//System.out.println(getPiece(from).getType());
//System.out.println(from.getColumn());
if (getPiece(from).getType() == Type.PAWN &&
(getPiece(from).getColor() == Color.WHITE ||
getPiece(from).getColor() == Color.BLACK)) {
grid[to.getColumn()][to.getRow()] = getPiece(from);
grid[from.getColumn()][from.getRow()] = null;
} else if (getPiece(from).getType() == Type.ROOK &&
getPiece(from).getColor() == Color.WHITE) {
grid[0][4] = new Pawn()
}
grid[to.getColumn()][to.getRow()] = new Rook(Color.WHITE, Type.ROOK);
grid[from.getColumn()][from.getRow()] = null;
//check if move is valid by piece
//set Piece to new position
// if (getPiece(from).getType() == Type.PAWN &&
// getPiece(from).getColor() == Color.WHITE) {
// grid[to.getColumn()][to.getRow()] = getPiece(from);
// grid[from.getColumn()][from.getRow()] = null;
// } else
}
}
/**

View File

@ -40,57 +40,73 @@ public class Field {
* it should throw an IllegalArgument exception.
*/
public static Field fromString(String value) throws IllegalArgumentException {
try {
char[] array = value.toCharArray();
int column_ = 0;
int row_ = 0;
//System.out.println(array[0]);
switch(array[0]) {
case 'A': column_ = 0;
switch (array[0]) {
case 'A':
column_ = 0;
break;
case 'B': column_ = 1;
case 'B':
column_ = 1;
break;
case 'C': column_ = 2;
case 'C':
column_ = 2;
break;
case 'D': column_ = 3;
case 'D':
column_ = 3;
break;
case 'E': column_ = 4;
case 'E':
column_ = 4;
break;
case 'F': column_ = 5;
case 'F':
column_ = 5;
break;
case 'G': column_ = 6;
case 'G':
column_ = 6;
break;
case 'H': column_ = 7;
case 'H':
column_ = 7;
break;
default:
System.out.println("Wrong input");
}
//System.out.println(array[1]);
switch(array[1]) {
case '1': row_ = 0;
switch (array[1]) {
case '1':
row_ = 0;
break;
case '2': row_ = 1;
case '2':
row_ = 1;
break;
case '3': row_ = 2;
case '3':
row_ = 2;
break;
case '4': row_ = 3;
case '4':
row_ = 3;
break;
case '5': row_ = 4;
case '5':
row_ = 4;
break;
case '6': row_ = 5;
case '6':
row_ = 5;
break;
case '7': row_ = 6;
case '7':
row_ = 6;
break;
case '8': row_ = 7;
case '8':
row_ = 7;
break;
default:
System.out.println("Wrong input");
}
//System.out.println(from(column_, row_));
return from(column_, row_);
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}
public int getColumn() {