コード例 #1
0
ファイル: Ship.cs プロジェクト: NikolaDXC/Space-Invaders
        public void KeyPressed()
        {
            var info = new ConsoleKeyInfo();

            while (Console.KeyAvailable)
            {
                info = Console.ReadKey();
            }

            switch (info.Key)
            {
            case ConsoleKey.LeftArrow:
                _currentMove = MoveType.LEFT;
                break;

            case ConsoleKey.RightArrow:
                _currentMove = MoveType.RIGHT;
                break;

            //case ConsoleKey.UpArrow:
            //    _currentMove = MoveType.UP;
            //    break;
            //case ConsoleKey.DownArrow:
            //    _currentMove = MoveType.DOWN;
            //    break;
            case ConsoleKey.Spacebar:
                _bullets.Add(_position.X, _position.Y);
                break;

            default:
                _currentMove = MoveType.NOMOVE;
                break;
            }
        }
コード例 #2
0
ファイル: Ship.cs プロジェクト: xShadoWalkeR/Space-Invaders
        /// <summary>
        /// Checks for the user input
        /// </summary>
        private void GetInput()
        {
            // Create a new ConsoleKeyInfo
            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();

            // Loop
            while (Console.KeyAvailable)
            {
                // Set the keyInfo to the read key
                keyInfo = Console.ReadKey(true);
            }

            // Check what key the user pressed
            switch (keyInfo.Key)
            {
            // If the user pressed the Left Arrow
            case ConsoleKey.LeftArrow:
                // Change the ship movement to go Left
                currentMove = MoveType.LEFT;
                break;

            // If the user pressed the Right Arrow
            case ConsoleKey.RightArrow:
                // Change the ship movement to go Right
                currentMove = MoveType.RIGHT;
                break;

            // If the user pressed the X key
            case ConsoleKey.X:
                // Stop the ship movement
                currentMove = MoveType.NONE;
                break;

            // If the user pressed space bar
            case ConsoleKey.Spacebar:
                ShipBullets.Add(coordinates.X + 3, coordinates.Y, MoveType.UP);
                break;
            }
        }