Esempio n. 1
0
        /// <summary>
        /// keystroke tracking method
        /// </summary>
        public static void Play()
        {
            while (check)
            {
                ConsoleKeyInfo key = Console.ReadKey(true);
                Mutex.WaitOne();
                if (!check)
                {
                    break;
                }
                Figure figure = (Figure)Figure.Clone();
                switch (key.Key)
                {
                case (ConsoleKey.RightArrow):
                    figure.PosX += 1;
                    break;

                case (ConsoleKey.LeftArrow):
                    figure.PosX -= 1;
                    break;

                case (ConsoleKey.DownArrow):
                    figure.PosY += 1;
                    break;

                case (ConsoleKey.Spacebar):
                    figure = figure.Rotation();
                    break;

                case (ConsoleKey.Escape):
                    check = false;
                    break;

                default:
                    break;
                }
                //rollback changes if necessary
                if (Region.CheckFigure(figure))
                {
                    Figure.Clear();
                    Figure = figure;
                    Figure.Draw();
                }
                Mutex.ReleaseMutex();
            }
        }