public void clearBoard(Board board) { int i, j; for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { Piece standardVoid = new VoidCase("void", i, j); grid[i, j, 0] = new Case(standardVoid, 0); } } }
private void ClickOnCase(object sender, EventArgs e) { int oldI = i; int oldJ = j; string playerTurn; if (btnBlackTurn.Checked == true) { playerTurn = "black"; } else { playerTurn = "white"; } DrawGrid(mainBoard); PictureBox pctBox = sender as PictureBox; i = pctBox.TabIndex / 10; j = pctBox.TabIndex % 10; if (mainBoard.Grid[i, j, mainBoard.SelectedTurn].WhoIsOnIt.Color != playerTurn && mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt.Color == playerTurn) { if (mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt.CanMoveThere(pctBox.TabIndex / 10, pctBox.TabIndex % 10, this.MainBoard) > 0) { mainBoard.NewTurn(mainBoard); if (mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt is King && pctBox.TabIndex % 10 - oldJ == 2) //Castling { mainBoard.Grid[oldI, 5, mainBoard.SelectedTurn].WhoIsOnIt = mainBoard.Grid[oldI, 7, mainBoard.SelectedTurn].WhoIsOnIt; mainBoard.Grid[oldI, 5, mainBoard.SelectedTurn].WhoIsOnIt.Y = mainBoard.Grid[oldI, 7, mainBoard.SelectedTurn].WhoIsOnIt.Y; VoidCase newVoidCase = new VoidCase("void", oldI, 7); mainBoard.Grid[oldI, 7, mainBoard.SelectedTurn].WhoIsOnIt = newVoidCase; mainBoard.Grid[oldI, 7, mainBoard.SelectedTurn].WhoIsOnIt.Color = "void"; mainBoard.Grid[oldI, 7, mainBoard.SelectedTurn].WhoIsOnIt.Y = 5; mainBoard.Grid[oldI, 7, mainBoard.SelectedTurn].WhoIsOnIt.NbrOfMoves++; } if (mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt is King && pctBox.TabIndex % 10 - oldJ == -2)//Castling { mainBoard.Grid[oldI, 3, mainBoard.SelectedTurn].WhoIsOnIt = mainBoard.Grid[oldI, 0, mainBoard.SelectedTurn].WhoIsOnIt; mainBoard.Grid[oldI, 3, mainBoard.SelectedTurn].WhoIsOnIt.Y = mainBoard.Grid[oldI, 0, mainBoard.SelectedTurn].WhoIsOnIt.Y; VoidCase newVoidCase = new VoidCase("void", oldI, 0); mainBoard.Grid[oldI, 0, mainBoard.SelectedTurn].WhoIsOnIt = newVoidCase; mainBoard.Grid[oldI, 0, mainBoard.SelectedTurn].WhoIsOnIt.Color = "void"; mainBoard.Grid[oldI, 0, mainBoard.SelectedTurn].WhoIsOnIt.Y = 3; mainBoard.Grid[oldI, 0, mainBoard.SelectedTurn].WhoIsOnIt.NbrOfMoves++; } mainBoard.Grid[pctBox.TabIndex / 10, pctBox.TabIndex % 10, mainBoard.SelectedTurn].WhoIsOnIt = mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt; mainBoard.Grid[pctBox.TabIndex / 10, pctBox.TabIndex % 10, mainBoard.SelectedTurn].WhoIsOnIt.X = pctBox.TabIndex / 10; mainBoard.Grid[pctBox.TabIndex / 10, pctBox.TabIndex % 10, mainBoard.SelectedTurn].WhoIsOnIt.Y = pctBox.TabIndex % 10; VoidCase voidCase = new VoidCase("void", oldI, oldJ); mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt = voidCase; mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt.Color = "void"; mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt.X = i; mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt.Y = j; mainBoard.Grid[oldI, oldJ, mainBoard.SelectedTurn].WhoIsOnIt.NbrOfMoves++; DrawGrid(mainBoard); TestForEndGame(); ColorCheckedKing(mainBoard); } } else { if (mainBoard.Grid[i, j, mainBoard.SelectedTurn].WhoIsOnIt.Color == playerTurn) { pctBox.Image = Image.FromFile("Assets/selection.png"); lbl1.Text = mainBoard.Grid[i, j, mainBoard.SelectedTurn].WhoIsOnIt.Color + mainBoard.Grid[i, j, mainBoard.SelectedTurn].WhoIsOnIt.GetType().ToString().Substring(6, mainBoard.Grid[i, j, mainBoard.SelectedTurn].WhoIsOnIt.GetType().ToString().Length - 6); ColorValidMoves(mainBoard.Grid[i, j, mainBoard.SelectedTurn].WhoIsOnIt); } } }