private void chooseButton(object sender, EventArgs e) { Button b = (Button)sender; switch (b.Name) { case "Queen": if (color) { p.sendEngineMove("Q"); } else { p.sendEngineMove("q"); } break; case "Rook": if (color) { p.sendEngineMove("R"); } else { p.sendEngineMove("r"); } break; case "Bishop": if (color) { p.sendEngineMove("B"); } else { p.sendEngineMove("b"); } break; case "Knight": if (color) { p.sendEngineMove("N"); } else { p.sendEngineMove("n"); } break; } this.Close(); }
void playMove() { if (isGameOver) { return; } try { Invoke((MethodInvoker) delegate { lblEngineCalc.Visible = true; lblMove.Text = string.Format("Move from {0} to {1}", srcSquare, dstSquare); lblMove.Visible = true; //lblEngineCalc.Invalidate(); label2.Visible = false; lblResult.Visible = false; this.Refresh(); // should send pipe to engine enginePipe.sendEngineMove(srcSquare.ToString() + dstSquare.ToString()); // should get pipe from engine string m = enginePipe.getEngineMessage(); if (!enginePipe.isConnected()) { MessageBox.Show("Connection to engine has lost. Bye bye."); this.Close(); return; } string res = convertEngineToText(m); if (res.ToLower().StartsWith("game over")) { isGameOver = true; } else if (res.ToLower().StartsWith("valid")) { isCurPlWhite = !isCurPlWhite; lblCurrentPlayer.Text = isCurPlWhite ? "White" : "Black"; matBoard[dstSquare.Row, dstSquare.Col].BackgroundImage = matBoard[srcSquare.Row, srcSquare.Col].BackgroundImage; matBoard[srcSquare.Row, srcSquare.Col].BackgroundImage = null; matBoard[srcSquare.Row, srcSquare.Col].FlatAppearance.BorderColor = Color.Blue; matBoard[dstSquare.Row, dstSquare.Col].FlatAppearance.BorderColor = Color.Blue; } lblEngineCalc.Visible = false; lblResult.Text = string.Format("{0}", res); lblResult.Visible = true; label2.Visible = true; this.Refresh(); }); } catch { } finally { Invoke((MethodInvoker) delegate { if (srcSquare != null) { matBoard[srcSquare.Row, srcSquare.Col].FlatAppearance.BorderColor = Color.Blue; } if (dstSquare != null) { matBoard[dstSquare.Row, dstSquare.Col].FlatAppearance.BorderColor = Color.Blue; } dstSquare = null; srcSquare = null; }); } }