Exemplo n.º 1
0
        void keyListener(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                if (isGameStarted)
                {
                    //TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.rotateCurrentShape();
                    //appendMatrixToDebug();
                    if (isConnectedAsClient) client.sendMsgToClient(blockLogic.objectToSend);
                    if (isConnectedAsServer) server.sendMsgToClient(blockLogic.objectToSend);
                    //TheGame.autodrop.Enabled = true;
                    if (isValid) { } // redrawMatrix(graphicsObj1);
                }
            }
            if (e.KeyCode == Keys.Left)
            {
                if (isGameStarted)
                {
                    //TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.moveCurrentShape(-1);
                    //appendMatrixToDebug();
                    if (isConnectedAsClient) client.sendMsgToClient(blockLogic.objectToSend);
                    if (isConnectedAsServer) server.sendMsgToClient(blockLogic.objectToSend);
                    //TheGame.autodrop.Enabled = true;
                    if (isValid) { } // redrawMatrix(graphicsObj1);
                }
            }
            if (e.KeyCode == Keys.Right)
            {
                if (isGameStarted)
                {
                    //TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.moveCurrentShape(1);
                    //appendMatrixToDebug();
                    if (isConnectedAsClient) client.sendMsgToClient(blockLogic.objectToSend);
                    if (isConnectedAsServer) server.sendMsgToClient(blockLogic.objectToSend);
                    //TheGame.autodrop.Enabled = true;
                    if (isValid) { } // redrawMatrix(graphicsObj1);
                }
            }
            if (e.KeyCode == Keys.Down)
            {
                //TheGame.autodrop.Enabled = false;
                bool isValid = blockLogic.moveCurrentShapeDown("STEP");
                //appendMatrixToDebug();
                if (isConnectedAsClient) client.sendMsgToClient(blockLogic.objectToSend);
                if (isConnectedAsServer) server.sendMsgToClient(blockLogic.objectToSend);
                //TheGame.autodrop.Enabled = true;
                if (isValid) { } // redrawMatrix(graphicsObj1);
            }
            if (e.KeyCode == Keys.NumPad0)
            {
                if (isGameStarted)
                {
                    TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.moveCurrentShapeDown("SNAP");
                    //appendMatrixToDebug();
                    if (isConnectedAsClient) client.sendMsgToClient(blockLogic.objectToSend);
                    if (isConnectedAsServer) server.sendMsgToClient(blockLogic.objectToSend);
                    TheGame.autodrop.Enabled = true;
                    if (isValid) { } //redrawMatrix(graphicsObj1);
                    else
                    {
                        isGameStarted = false;
                        TheGame.autodrop.Enabled = false;

                        drawMyMatrix(graphicsObj1);
                        graphicsObj1.DrawString("Game over, press ENTER to play again", new Font("Arial", 22), myBrush, new Point(10, WINHEIGHT / 2));

                    }

                }
            }
            if (e.KeyCode == Keys.F1)
            {
                if (!isGameStarted)
                    reloadGame();
            }

            if (e.KeyCode == Keys.F2)
            {
                if (!isGameStarted)
                {
                    isMultiplayer = true;
                    promptMultiplayer();
                }
            }
            if (e.KeyCode == Keys.F3)
            {
                if (!isGameStarted && isMultiplayer)
                {
                    server = new tet_network_s(this);
                    promptWaitingForPlayer();
                    isConnectedAsServer = true;
                }
            }
            if (e.KeyCode == Keys.F4)
            {
                if (!isGameStarted && isMultiplayer)
                {
                    try { client = new tet_network_c(this); }
                    catch
                    {
                        MessageBox.Show("Host not found, application will restart (dirty fix, needs a more elegant one) ", "Battle Tetrix", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        Application.Restart();
                    }
                    isConnectedAsClient = true;
                }
            }
            if (e.KeyCode == Keys.R)
            {
                TheGame.autodrop.Enabled = false;
                reloadGame();
            }
            if (e.KeyCode == Keys.Escape)
                Application.Exit();
        }
Exemplo n.º 2
0
        void keyListener(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                if (isGameStarted)
                {
                    //TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.rotateCurrentShape();
                    //appendMatrixToDebug();
                    if (isConnectedAsClient)
                    {
                        client.sendMsgToClient(blockLogic.objectToSend);
                    }
                    if (isConnectedAsServer)
                    {
                        server.sendMsgToClient(blockLogic.objectToSend);
                    }
                    //TheGame.autodrop.Enabled = true;
                    if (isValid)
                    {
                    }                // redrawMatrix(graphicsObj1);
                }
            }
            if (e.KeyCode == Keys.Left)
            {
                if (isGameStarted)
                {
                    //TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.moveCurrentShape(-1);
                    //appendMatrixToDebug();
                    if (isConnectedAsClient)
                    {
                        client.sendMsgToClient(blockLogic.objectToSend);
                    }
                    if (isConnectedAsServer)
                    {
                        server.sendMsgToClient(blockLogic.objectToSend);
                    }
                    //TheGame.autodrop.Enabled = true;
                    if (isValid)
                    {
                    }                // redrawMatrix(graphicsObj1);
                }
            }
            if (e.KeyCode == Keys.Right)
            {
                if (isGameStarted)
                {
                    //TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.moveCurrentShape(1);
                    //appendMatrixToDebug();
                    if (isConnectedAsClient)
                    {
                        client.sendMsgToClient(blockLogic.objectToSend);
                    }
                    if (isConnectedAsServer)
                    {
                        server.sendMsgToClient(blockLogic.objectToSend);
                    }
                    //TheGame.autodrop.Enabled = true;
                    if (isValid)
                    {
                    }                // redrawMatrix(graphicsObj1);
                }
            }
            if (e.KeyCode == Keys.Down)
            {
                //TheGame.autodrop.Enabled = false;
                bool isValid = blockLogic.moveCurrentShapeDown("STEP");
                //appendMatrixToDebug();
                if (isConnectedAsClient)
                {
                    client.sendMsgToClient(blockLogic.objectToSend);
                }
                if (isConnectedAsServer)
                {
                    server.sendMsgToClient(blockLogic.objectToSend);
                }
                //TheGame.autodrop.Enabled = true;
                if (isValid)
                {
                }                // redrawMatrix(graphicsObj1);
            }
            if (e.KeyCode == Keys.NumPad0)
            {
                if (isGameStarted)
                {
                    TheGame.autodrop.Enabled = false;
                    bool isValid = blockLogic.moveCurrentShapeDown("SNAP");
                    //appendMatrixToDebug();
                    if (isConnectedAsClient)
                    {
                        client.sendMsgToClient(blockLogic.objectToSend);
                    }
                    if (isConnectedAsServer)
                    {
                        server.sendMsgToClient(blockLogic.objectToSend);
                    }
                    TheGame.autodrop.Enabled = true;
                    if (isValid)
                    {
                    }                //redrawMatrix(graphicsObj1);
                    else
                    {
                        isGameStarted            = false;
                        TheGame.autodrop.Enabled = false;

                        drawMyMatrix(graphicsObj1);
                        graphicsObj1.DrawString("Game over, press ENTER to play again", new Font("Arial", 22), myBrush, new Point(10, WINHEIGHT / 2));
                    }
                }
            }
            if (e.KeyCode == Keys.F1)
            {
                if (!isGameStarted)
                {
                    reloadGame();
                }
            }

            if (e.KeyCode == Keys.F2)
            {
                if (!isGameStarted)
                {
                    isMultiplayer = true;
                    promptMultiplayer();
                }
            }
            if (e.KeyCode == Keys.F3)
            {
                if (!isGameStarted && isMultiplayer)
                {
                    server = new tet_network_s(this);
                    promptWaitingForPlayer();
                    isConnectedAsServer = true;
                }
            }
            if (e.KeyCode == Keys.F4)
            {
                if (!isGameStarted && isMultiplayer)
                {
                    try { client = new tet_network_c(this); }
                    catch
                    {
                        MessageBox.Show("Host not found, application will restart (dirty fix, needs a more elegant one) ", "Battle Tetrix", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        Application.Restart();
                    }
                    isConnectedAsClient = true;
                }
            }
            if (e.KeyCode == Keys.R)
            {
                TheGame.autodrop.Enabled = false;
                reloadGame();
            }
            if (e.KeyCode == Keys.Escape)
            {
                Application.Exit();
            }
        }