Exemple #1
0
        private void initForm()
        {
            enginePipe.connect();
            changePipe.connect();
            chatPipe.connect();
            Invoke((MethodInvoker) delegate
            {
                wait.Visible       = true;
                lblWaiting.Visible = false;
            });
            enginePipe.getEngineMessage();
            Invoke((MethodInvoker) delegate {
                wait.Visible             = false;
                lblCurrentPlayer.Visible = true;
                label1.Visible           = true;
                chatBox.SelectionStart   = chatBox.Text.Length;
                chatBox.ScrollToCaret();
                this.msgBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress);

                string s = enginePipe.getEngineMessage();

                if (s.Length != (BOARD_SIZE * BOARD_SIZE + 1))
                {
                    MessageBox.Show("The length of the board's string is not according the PROTOCOL");
                    this.Close();
                }
                else
                {
                    isCurPlWhite = (s[s.Length - 1] == '0');
                    paintBoard(s);
                }
            });
        }
Exemple #2
0
        private void initForm()
        {
            enginePipe.connect();

            Invoke((MethodInvoker) delegate {
                lblWaiting.Visible       = false;
                lblCurrentPlayer.Visible = true;
                label1.Visible           = true;



                string s = enginePipe.getEngineMessage();

                if (s.Length != (BOARD_SIZE * BOARD_SIZE + 1))
                {
                    MessageBox.Show("The length of the board's string is not according the PROTOCOL");
                    this.Close();
                }
                else
                {
                    isCurPlWhite = (s[s.Length - 1] == '0');
                    paintBoard(s);
                }
            });
        }
Exemple #3
0
        void changePipeHandler()
        {
            int            row = 0, col = 0;
            char           piece;
            string         won;
            PieceSelection choice;

            while (true)
            {
                try
                {
                    string m = changePipe.getEngineMessage();
                    if (m.StartsWith("change"))
                    {
                        row   = m[7] - '0';
                        col   = m[9] - '0';
                        piece = m[11];
                        Invoke((MethodInvoker) delegate
                        {
                            matBoard[row, col].BackgroundImage = getImageBySign(piece);
                            this.Refresh();
                        });
                    }
                    else if (m.StartsWith("choice"))
                    {
                        if (m.Substring(7) == "white")
                        {
                            choice = new PieceSelection();
                            choice.initForm(true, enginePipe);
                        }
                        else
                        {
                            choice = new PieceSelection();
                            choice.initForm(false, enginePipe);
                        }
                        Invoke((MethodInvoker) delegate
                        {
                            choice.Show();
                        });
                    }
                    else if (m.StartsWith("mate"))
                    {
                        won = m.Substring(5);
                        switch (won)
                        {
                        case "white":
                            won = "Black";
                            break;

                        case "black":
                            won = "White";
                            break;
                        }
                        Invoke((MethodInvoker) delegate
                        {
                            MessageBox.Show(won + " Won.", "Check Mate!");
                            this.Close();
                            return;
                        });
                    }
                    else if (m.StartsWith("chat"))
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            this.chatBox.AppendText("Opponent: " + m.Substring(10));
                            this.chatBox.AppendText(Environment.NewLine);
                        });
                    }
                    else if (m.StartsWith("wait"))
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            this.wait.Visible = true;
                        });
                    }
                    else if (m.StartsWith("connect"))
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            this.wait.Visible = false;
                        });
                    }
                    else if (m.StartsWith("turn"))
                    {
                        if (this.lblCurrentPlayer.Text == "White")
                        {
                            Invoke((MethodInvoker) delegate
                            {
                                this.lblCurrentPlayer.Text = "Black";
                            });
                        }
                        else if (this.lblCurrentPlayer.Text == "Black")
                        {
                            Invoke((MethodInvoker) delegate
                            {
                                this.lblCurrentPlayer.Text = "White";
                            });
                        }
                    }
                    else if (m.StartsWith("msg"))
                    {
                        Invoke((MethodInvoker) delegate
                        {
                            this.lblResult.Text = convertEngineToText(m[4].ToString());
                        });
                    }
                    else if (m.StartsWith("disconnect"))
                    {
                        Invoke((MethodInvoker) delegate {
                            MessageBox.Show("Opponent Disconnected!");
                            this.Close();
                        });
                    }
                }
                catch
                {
                }
            }
        }