示例#1
0
 private void Form1_KeyUp(object sender, KeyEventArgs e)
 {
     KeyInputManager.setKeyState(e.KeyCode, false);
 }
示例#2
0
        public void KeysPressed()
        {
            try
            {
                if (KeyInputManager.getKeyState(Keys.Escape))
                {
                    if (player1)
                    {
                        sendToClient = Encoding.ASCII.GetBytes("" + 1000);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                        Environment.Exit(0);
                    }
                    else
                    {
                        sendToServer = Encoding.ASCII.GetBytes("" + 1000);
                        client.Send(sendToServer, sendToServer.Length);
                        Environment.Exit(0);
                    }
                }
                if (KeyInputManager.getKeyState(Keys.Space))
                {
                    if (player1)
                    {
                        sendToClient = Encoding.ASCII.GetBytes("" + 1001);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                        bp.restart();
                    }
                    else
                    {
                        sendToServer = Encoding.ASCII.GetBytes("" + 1001);
                        client.Send(sendToServer, sendToServer.Length);
                        bp.restart();
                    }
                }

                if (KeyInputManager.getKeyState(Keys.P))
                {
                    if (player1)
                    {
                        sendToClient = Encoding.ASCII.GetBytes("" + 1002);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                        bp.start = false;
                    }
                    else
                    {
                        sendToServer = Encoding.ASCII.GetBytes("" + 1002);
                        client.Send(sendToServer, sendToServer.Length);
                        bp.start = false;
                    }
                }
                if (KeyInputManager.getKeyState(Keys.S))
                {
                    if (player1)
                    {
                        sendToClient = Encoding.ASCII.GetBytes("" + 1003);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                        bp.start = true;
                    }
                    else
                    {
                        sendToServer = Encoding.ASCII.GetBytes("" + 1003);
                        client.Send(sendToServer, sendToServer.Length);
                        bp.start = true;
                    }
                }

                if (KeyInputManager.getKeyState(Keys.ControlKey))
                {
                    if (player1)
                    {
                        sendToClient = Encoding.ASCII.GetBytes("" + 1004);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                        if (bp.lvl < 10)
                        {
                            bp.nextlvl();
                        }
                    }
                    else
                    {
                        sendToServer = Encoding.ASCII.GetBytes("" + 1004);
                        client.Send(sendToServer, sendToServer.Length);
                        if (bp.lvl < 10)
                        {
                            bp.nextlvl();
                        }
                    }
                }
                if (KeyInputManager.getKeyState(Keys.Enter) && bp.lvl < 10)
                {
                    if (player1)
                    {
                        sendToClient = Encoding.ASCII.GetBytes("" + 1005);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                        bp.start = true;
                        if (bp.nbricks == 0)
                        {
                            bp.nextlvl();
                        }
                    }
                    else
                    {
                        sendToServer = Encoding.ASCII.GetBytes("" + 1005);
                        client.Send(sendToServer, sendToServer.Length);
                        bp.start = true;
                        if (bp.nbricks == 0)
                        {
                            bp.nextlvl();
                        }
                    }
                }

                if (KeyInputManager.getKeyState(Keys.Right))
                {
                    if (player1)
                    {
                        if (bp.player < 561)
                        {
                            bp.player += 20;
                        }
                        sendToClient = Encoding.ASCII.GetBytes("" + bp.player);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                    }
                    else
                    {
                        if (bp.player2 < 561)
                        {
                            bp.player2 += 20;
                        }
                        sendToServer = Encoding.ASCII.GetBytes("" + bp.player2);
                        client.Send(sendToServer, sendToServer.Length);
                    }
                }
                if (KeyInputManager.getKeyState(Keys.Left))
                {
                    if (player1)
                    {
                        if (bp.player > 0)
                        {
                            bp.player -= 20;
                        }
                        sendToClient = Encoding.ASCII.GetBytes("" + bp.player);
                        server.Send(sendToClient, sendToClient.Length, RemoteIpEndPoint);
                    }
                    else
                    {
                        if (bp.player2 > 0)
                        {
                            bp.player2 -= 20;
                        }
                        sendToServer = Encoding.ASCII.GetBytes("" + bp.player2);
                        client.Send(sendToServer, sendToServer.Length);
                    }
                }
            }
            catch (Exception e) { }
        }