public void redrawBoard() { for (int i = 0; i < NUM_ROWS; i++) { for (int j = 0; j < NUM_ROWS; j++) { if ((i + j) % 2 == 0) { matrix[i, j].BackgroundImage = Image.FromFile(path + "//WhiteWood.gif"); } else { matrix[i, j].BackgroundImage = Image.FromFile(path + "//BlackWood.gif"); } matrix[i, j].Image = null; } } Iterator it = whitePieces.getIterator(); while (it.MoveNext()) { drawPiece(it.Current as Piece); } it = blackPieces.getIterator(); while (it.MoveNext()) { drawPiece(it.Current as Piece); } }
//Methods for painting squares private void paintAllowedMovements(List positions) { int row, column; Iterator it = positions.getIterator(); while (it.MoveNext()) { row = (it.Current as Position).getRow(); column = (it.Current as Position).getColumn(); matrix[row, column].BackgroundImage = null; matrix[row, column].BackColor = Color.LightGreen; } }
/* * Checks whether a given position is valid as a next move. */ public bool isvalidMove(Position newPosition) { Iterator iterator = allowedMovements.getIterator(); while (iterator.MoveNext()) { Position p = iterator.Current as Position; if (p.Equals(newPosition)) { return(true); } } return(false); }
public void deleteAllowedMovements(List positions) { int row, column; Iterator it = positions.getIterator(); while (it.MoveNext()) { row = (it.Current as Position).getRow(); column = (it.Current as Position).getColumn(); matrix[row, column].BackColor = Color.Empty; if ((row + column) % 2 == 0) { matrix[row, column].BackgroundImage = Image.FromFile(Board.getInstance().getPath() + "//WhiteWood.gif"); } else { matrix[row, column].BackgroundImage = Image.FromFile(Board.getInstance().getPath() + "//BlackWood.gif"); } } }