Beispiel #1
0
        //	Function
        //	Return false on exit command
        public bool Update()
        {
            //	Dont try to read the key unless there is a key available
            if (Console.KeyAvailable)
            {
                bool bInterceptKey = true;

                //	Store the current key pressed
                ConsoleKey KeyPressed = Console.ReadKey(bInterceptKey).Key;

                //	Escape Command
                if (KeyPressed == ConsoleKey.Escape)
                {
                    return(false);
                }

                //	Player Move
                if (KeyPressed == ConsoleKey.UpArrow)
                {
                    MyPlayer.Move(0, -1);
                }
                if (KeyPressed == ConsoleKey.DownArrow)
                {
                    MyPlayer.Move(0, 1);
                }
                if (KeyPressed == ConsoleKey.LeftArrow)
                {
                    MyPlayer.Move(-1, 0);
                }
                if (KeyPressed == ConsoleKey.RightArrow)
                {
                    MyPlayer.Move(1, 0);
                }
            }

            foreach (Enemy enemy in Enemies)
            {
                if (enemy.GetPosition() == MyPlayer.GetPosition())
                {
                    return(false);
                }
                enemy.Update();
            }

            //	return false to exit;
            return(true);
        }