示例#1
0
文件: Falling.cs 项目: mullikine/OT60
        public Falling(IGameUnit unit, int speed = 1000)
        {
            if (x == 0 && y == 0)
            {
                x = -Console.WindowWidth / 2;
                y = Console.WindowHeight / 2 - 10;
            }
            shaker = new Thread(() =>
            {
                var rnd = new Random(unit.GetHashCode());
                while (true)
                {
                    //          locker.Enter();
                    var x = -Console.WindowWidth / 2 + rnd.Next(Console.WindowWidth);
                    var y = -Console.WindowHeight / 2 + rnd.Next(Console.WindowHeight);
                    //          x += 4;
                    //          if (x > Console.WindowWidth / 2) {
                    //            x = -Console.WindowWidth / 2;
                    //          }
                    unit.Position(x, y, 0);
                    //          unit.Draw();
                    //          locker.Exit();
                    var end  = 1000 + rnd.NextDouble() * 1000;
                    var time = 0;
                    var d    = 30;
                    while (time < end && unit.Visible)
                    {
                        isActive.WaitOne();
                        //unit.Move((int) Math.Pow(-1, ++iter), 0);
                        //unit.Rotate(Math.PI / 120);
                        unit.Move(0, -0.2);
                        //Thread.Sleep(1 + rnd.Next(speed));
                        Thread.Sleep(d);
                        time += d;
                    }
//          if (!unit.Visible) {
//            int foo = 1;
//          }
                }
                //unit.Enable = false;
            })
            {
                IsBackground = true
            };
            shaker.Start();
        }
示例#2
0
        public Rotor(IGameUnit unit, double delta = Math.PI / 2, int speed = 1000)
        {
            this.speed = speed;

            rotor = new Thread(() =>
            {
                while (true)
                {
                    isActive.WaitOne();
                    unit.Rotate(delta);
                    unit.Move(0, -1);
                    Thread.Sleep(this.speed);
                }
            })
            {
                IsBackground = true
            };
            rotor.Start();

            ConsoleKeyboard.Get.Add(this);
        }
示例#3
0
        /// <summary>
        /// Draw!
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            Console.CursorVisible   = false;
            Console.BackgroundColor = ConsoleHelpers.Convert(background);

            new Thread(() =>
            {
                var height = Console.WindowHeight;
                var width  = Console.WindowWidth;
                while (true)
                {
                    if (height != Console.WindowHeight || width != Console.WindowWidth)
                    {
                        height = Console.WindowHeight;
                        width  = Console.WindowWidth;
                        ConsoleResizeEvent(height, width);
                    }
                    Thread.Sleep(100);
                }
            })
            {
                IsBackground = true
            }.Start();

            mesh  = CreateMesh();
            about = CreateAbout(Console.WindowWidth);
            help  = CreateHelp();
            ClearScreen();

            mesh.InvalidateEvent += Update;

            while (true)
            {
                info(step);
                if (toggleHelp)
                {
                    help.Draw();
                }
                if (toggleAbout)
                {
                    about.Draw();
                }
                var key = Console.ReadKey(false).Key;
                ConsoleHelpers.FillRect(Console.BackgroundColor);

                if (key == ConsoleKey.F1 || key == ConsoleKey.F)
                {
                    toggleAbout = !toggleAbout;
//          about.Clear();
                    mesh.Draw();
                }
                if (key == ConsoleKey.H)
                {
                    toggleHelp = !toggleHelp;
//          help.Clear();
                    mesh.Draw();
                }
                if (key == ConsoleKey.Escape)
                {
                    break;
                }
                else if (key == ConsoleKey.LeftArrow)
                {
                    mesh.Move(-step, 0);
                }
                else if (key == ConsoleKey.RightArrow)
                {
                    mesh.Move(step, 0);
                }
                else if (key == ConsoleKey.UpArrow)
                {
                    mesh.Move(0, step);
                }
                else if (key == ConsoleKey.DownArrow)
                {
                    mesh.Move(0, -step);
                }
                else if (key == ConsoleKey.E)
                {
                    mesh.Rotate(Math.PI / 12);
                }
                else if (key == ConsoleKey.W)
                {
                    mesh.Rotate(-Math.PI / 12);
                }
                else if (key == ConsoleKey.S)
                {
                    ang   = 0;
                    step  = 2;
                    mesh  = CreateMesh();
                    about = CreateAbout(Console.WindowWidth);
                    help  = CreateHelp();
                    ClearScreen();
                }
                else if (key == ConsoleKey.Subtract && step > 1)
                {
                    step--;
                    mesh.Draw();
                }
                else if (key == ConsoleKey.Add)
                {
                    step++;
                    mesh.Draw();
                }
                else
                {
                    mesh.Draw();
                }
            }
            Console.SetCursorPosition(0, 0);
        }