Esempio n. 1
0
        private void Form_PingPong_KeyDown(object sender, KeyEventArgs e)
        {
                if (e.KeyCode == Keys.F1)
                {
                    if (!flagCreateServer)
                    {
                        form2 = new SettingsForm2(this);
                        form2.Show();
                        form2.TopMost = true;

                        form2.FormClosing += (obj, arg) =>
                        {
                            this.TopMost = true; //форму на передний план
                            if (Form1_IPClient_1 != null && Form1_IPClient_2 != null && Form1_PortClient_1 != null && Form1_PortClient_2 != null)
                            {
                                InitializeSocket();

                                ball.Top = 50;
                                ball.Left = 50;
                                speedLeft = 4;
                                speedTop = 4;
                                pointPlayer1 = 0;
                                pointPlayer2 = 0;
                                pointPlayer1_lbl.Text = "0";
                                pointPlayer2_lbl.Text = "0";
                                GameOver.Text = "Ожидаем противника...";
                            }
                        };
                        flagCreateServer = true;
                    }
                    else if (flagCreateServer)
                    {
                        MessageBox.Show("Вы уже создали сервер!\r\nОжидайте начала игры!", "", MessageBoxButtons.OK);
                    }
                }
            
            if (e.KeyCode == Keys.F2)
            {
                
            }

            if (!flagGame)
            {
                if (e.KeyCode == Keys.Y)
                {
                    flagNewGamePlayer2 = true;
                    GameOver.Text = "";
                    if (flagNewGamePlayer2 && flagNewGamePlayer1)
                    {
                        Send("newGame", 1, 1);
                        ball.Top = 50;
                        ball.Left = 50;
                        speedLeft = 4;
                        speedTop = 4;
                        pointPlayer1 = 0;
                        pointPlayer2 = 0;
                        pointPlayer1_lbl.Text = "0";
                        pointPlayer2_lbl.Text = "0";
                        GameOver.Text = "";

                        timer1.Enabled = true;
                        flagGame = true;
                        Information_lbl.Visible = false;
                        flagNewGamePlayer1 = false;
                        flagNewGamePlayer2 = false;
                    }
                }
                if (e.KeyCode == Keys.N)
                {
                    Send("newGame", 0, 0);
                }
            }

            if (e.KeyCode == Keys.F4)
            {
                Information_lbl.Visible = true;
                timer1.Enabled = false;
                flagGame = false;
            }

            if (!flagGame && form2 != null)
            {
                if (e.KeyCode == Keys.F5)
                {
                    Send("chat", 0, 0);
                    ((Control)form2.tabPage1).Enabled = false;
                    form2.tabControlSettings.SelectedTab = form2.tabPage2;
                    form2.Show();
                    form2.TopMost = true;
                    form2.FormClosing += (obj, arg) =>
                    {
                        GameOver.Text = "\r\nеще играем? Y - да N - нет";
                    };
                }
            }

            if (e.KeyCode == Keys.Escape)
            {
                if (MessageBox.Show("Вы уверены, что хотите выйти из игры?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    this.Close();
                }
            }
            if (flagGame)
            {
                //--------------------------Player2----------------------//
                if (e.KeyCode == Keys.Up)
                {
                    if (racketPlayer2.Top > 0)
                    {
                        racketPlayer2.Top -= 7;
                        Send("racketPlayer2", racketPlayer2.Top, racketPlayer2.Left);
                    }
                }
                if (e.KeyCode == Keys.Down)
                {
                    if (racketPlayer2.Bottom < playGraund.Bottom)
                    {
                        racketPlayer2.Top += 7;
                        Send("racketPlayer2", racketPlayer2.Top, racketPlayer2.Left);
                    }
                }
                //--------------------------Player1----------------------//
                /*if (e.KeyCode == Keys.A)
                    racketPlayer1.Top -= 7;
                if (e.KeyCode == Keys.Z)
                    racketPlayer1.Top += 7;*/
            }
        }
Esempio n. 2
0
        private void Form_PingPong_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1) //есть глюк
            {
                    Send("ready", 0, 0);
                    if (!flagSendReady)
                    {
                        flagGame = true;
                        Information_lbl.Visible = false;
                        flagSendReady = true;
                    }
                    else if (flagSendReady)
                    {
                        MessageBox.Show("Игра запущена", "", MessageBoxButtons.OK);
                    }
            }

            if (e.KeyCode == Keys.F2)
            {
                if (!flagCreateConnect)
                {
                    form2 = new SettingsForm2(this);
                    form2.Show();
                    form2.TopMost = true;

                    form2.FormClosing += (obj, arg) =>
                    {
                        this.TopMost = true; //форму на передний план
                        if (Form1_IPClient_1 != null && Form1_IPClient_2 != null && Form1_PortClient_1 != null && Form1_PortClient_2 != null)
                        {
                            InitializeSocket();
                        }
                    };
                    flagCreateConnect = true;
                }
                else if (flagCreateConnect)
                {
                    MessageBox.Show("Вы уже дали команду на подключение к серверу", "", MessageBoxButtons.OK);
                }
            }

            if (!flagGame)
            {
                if (e.KeyCode == Keys.Y)
                {
                    Send("newGame", 1, 1);
                    GameOver.Text = "";
                    Information_lbl.Visible = false;
                    flagGame = true;
                }
                if (e.KeyCode == Keys.N)
                {
                    Send("newGame", 0, 0);
                    GameOver.Text = "";
                    Information_lbl.Visible = true;
                }
            }

            if (!flagGame && form2!=null)
            {
                if (e.KeyCode == Keys.F5)
                {
                    Send("chat", 0, 0);
                    ((Control)form2.tabPage1).Enabled = false;
                    form2.tabControlSettings.SelectedTab = form2.tabPage2;
                    form2.Show();
                    form2.TopMost = true;
                    form2.FormClosing += (obj, arg) =>
                    {
                        GameOver.Text = "\r\nеще играем? Y - да N - нет";
                    };
                }
            }

            if (e.KeyCode == Keys.Escape)
            {
                if (MessageBox.Show("Вы уверены, что хотите выйти из игры?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    this.Close();
                }
            }
            if (flagGame)
            {
                //--------------------------Player2----------------------//
                /*if (e.KeyCode == Keys.Up)
                {
                    racketPlayer2.Top -= 7;
                    Send("racketPlayer2", racketPlayer2.Top, racketPlayer2.Left);
                }
                if (e.KeyCode == Keys.Down)
                {
                    racketPlayer2.Top += 7;
                    Send("racketPlayer2", racketPlayer2.Top, racketPlayer2.Left);
                }*/
                //--------------------------Player1----------------------//
                if (e.KeyCode == Keys.A)
                {
                    if (racketPlayer1.Top > 0)
                    {
                        racketPlayer1.Top -= 7;
                        Send("racketPlayer1", racketPlayer1.Top, racketPlayer1.Left);
                    }
                }
                if (e.KeyCode == Keys.Z)
                {
                    if (racketPlayer1.Bottom < playGraund.Bottom)
                    {
                        racketPlayer1.Top += 7;
                        Send("racketPlayer1", racketPlayer1.Top, racketPlayer1.Left);
                    }
                }
            }
        }