Example #1
0
        private void GameForm_KeyPress(object sender, KeyPressEventArgs e) //watches for keys
        {
            switch (e.KeyChar)
            {
            case 'q':     //ends game
                gameOver = true;
                break;

            case 'w':     //next five move/fire tank 1
                tank1.Direction = 0;
                tank1.Move();
                break;

            case 'a':
                tank1.Direction = 3;
                tank1.Move();
                break;

            case 's':
                tank1.Direction = 2;
                tank1.Move();
                break;

            case 'd':
                tank1.Direction = 1;
                tank1.Move();
                break;

            case 'f':
                tank1.Fire();
                break;

            case 'i':     //next five move/fire tank 2
                tank2.Direction = 0;
                tank2.Move();
                break;

            case 'j':
                tank2.Direction = 3;
                tank2.Move();
                break;

            case 'k':
                tank2.Direction = 2;
                tank2.Move();
                break;

            case 'l':
                tank2.Direction = 1;
                tank2.Move();
                break;

            case 'h':
                tank2.Fire();
                break;
            }

            DetectCollisions(); //checks for intersection in between each key press
        }