package de.vivi.chess.board; import de.vivi.chess.pieces.Piece; /** * TODO: implement fields and constructor *
* This class contains information to identify a single field * on the board by its column and row. */ public class Field { private int column; private int row; private Board board; public Field(int column, int row) { this.column = column; this.row = row; //board = new Board(); } /** * TODO: implement *
* Returns a new field that represents the field at the * column and row indices. */ public static Field from(int column, int row) { return new Field(column, row); } /** * TODO: implement *
* Returns a new field that represents the field represented * by the provided string (like "A5", "E7", ...). If the string * is not valid, because it is garbage (like "hello", "world", ...) * or the indices are out of bounds (like "K3", "B9", ...") * it should throw an IllegalArgument exception. */ public static Field fromString(String value) throws IllegalArgumentException { char[] array = value.toCharArray(); int column_ = 0; int row_ = 0; //System.out.println(array[0]); switch(array[0]) { case 'A': column_ = 0; break; case 'B': column_ = 1; break; case 'C': column_ = 2; break; case 'D': column_ = 3; break; case 'E': column_ = 4; break; case 'F': column_ = 5; break; case 'G': column_ = 6; break; case 'H': column_ = 7; break; default: System.out.println("Wrong input"); } //System.out.println(array[1]); switch(array[1]) { case '1': row_ = 0; break; case '2': row_ = 1; break; case '3': row_ = 2; break; case '4': row_ = 3; break; case '5': row_ = 4; break; case '6': row_ = 5; break; case '7': row_ = 6; break; case '8': row_ = 7; break; default: System.out.println("Wrong input"); } //System.out.println(from(column_, row_)); return from(column_, row_); } public int getColumn() { // TODO: implement return column; } public int getRow() { // TODO: implement return row; } }