示例#1
0
        public void CanvasDemo()
        {
            cHandler.Reset();
            bool exit = false;

            IntXYPair canvasPosition  = new IntXYPair(5, 5);
            IntXYPair pikachuPosition = new IntXYPair(5, 5);

            cHandler.SetCanvas("BaseCanvas", new IntXYPair(20, 20), canvasPosition);


            while (!exit)
            {
                cHandler.ClearCanvas("BaseCanvas");
                cHandler.MoveCanvas("BaseCanvas", canvasPosition);
                cHandler.DrawToCanvas("BaseCanvas", "Pikachu", pikachuPosition);
                Console.Clear();
                cHandler.PrintCanvas("BaseCanvas");
                var input = Console.ReadKey(true);
                switch (input.Key)
                {
                case ConsoleKey.Escape:
                    exit = true;
                    break;

                case ConsoleKey.LeftArrow:
                    pikachuPosition.x--;
                    break;

                case ConsoleKey.UpArrow:
                    pikachuPosition.y--;
                    break;

                case ConsoleKey.RightArrow:
                    pikachuPosition.x++;
                    break;

                case ConsoleKey.DownArrow:
                    pikachuPosition.y++;
                    break;

                case ConsoleKey.A:
                    canvasPosition.x--;
                    break;

                case ConsoleKey.D:
                    canvasPosition.x++;
                    break;

                case ConsoleKey.S:
                    canvasPosition.y++;
                    break;

                case ConsoleKey.W:
                    canvasPosition.y--;
                    break;

                default:
                    break;
                }
            }
        }