コード例 #1
0
        public void StartGame(int consoleHeight, int consoleWidth)
        {
            this._colors = new ConsoleColor[consoleHeight][];
            for (int a = 0; a < this._colors.Length; a++)
            {
                this._colors[a] = new ConsoleColor[consoleWidth];
            }

            this._engineToConsoleMultiplier = Math.Max(this._game.Width / consoleWidth, this._game.Height / consoleHeight);

            this._cd.DrawLevelBackground(consoleHeight, consoleWidth, (int)(this._game.RectHeight / this._engineToConsoleMultiplier),
                                         (int)(this._game.RectWidth / this._engineToConsoleMultiplier), this._colors);


            this._square = this.TransformEngineRectangle(this._square);
            for (int a = 0; a < this._barriers.Length; a++)
            {
                this._barriers[a] = this.TransformEngineRectangle(this._barriers[a]);
                this._cd.DrawRectangle(this._barriers[a], ConsoleColor.Blue);
            }

            this._cd.DrawRectangle(this._square, ConsoleColor.Red);

            Console.ResetColor();
            Console.SetWindowPosition(0, 0);
            Console.SetCursorPosition(0, consoleHeight - 1);

            this._timer.Start();

            for (;;)
            {
                ConsoleKeyInfo cki = Console.ReadKey();

                if (cki.Key == ConsoleKey.Q)
                {
                    lock (Syncronization.SyncObj)
                    {
                        Console.ResetColor();
                        Console.SetCursorPosition(0, Console.WindowHeight);
                    }
                    break;
                }
                else if (cki.Key == ConsoleKey.UpArrow)
                {
                    this.MoveRectangle(ref this._square, ConsoleColor.Red, Directions.Up, 1);
                }
                else if (cki.Key == ConsoleKey.DownArrow)
                {
                    this.MoveRectangle(ref this._square, ConsoleColor.Red, Directions.Down, 1);
                }

                else if (cki.Key == ConsoleKey.LeftArrow)
                {
                    this.MoveRectangle(ref this._square, ConsoleColor.Red, Directions.Left, 1);
                }

                else if (cki.Key == ConsoleKey.RightArrow)
                {
                    this.MoveRectangle(ref this._square, ConsoleColor.Red, Directions.Right, 1);
                }

                lock (Syncronization.SyncObj)
                {
                    EngineRectangle   temp  = this.TransformConsoleRectangle(this._square);
                    EngineRectangle[] barrs = new EngineRectangle[this._barriers.Length];
                    for (int s = 0; s < barrs.Length; s++)
                    {
                        barrs[s] = this.TransformConsoleRectangle(this._barriers[s]);
                    }
                    this._game.CheckDeath(temp, barrs);
                }

                lock (Syncronization.SyncObj)
                {
                    Console.BackgroundColor = ConsoleColor.DarkGreen;
                    Console.SetCursorPosition(0, Console.WindowHeight - 1);
                }
            }
        }
コード例 #2
0
 public EngineRectangle TransformEngineRectangle(EngineRectangle er)
 {
     return(new EngineRectangle((int)(er.X / this._engineToConsoleMultiplier), (int)(er.Y / this._engineToConsoleMultiplier), (int)(er.Height / this._engineToConsoleMultiplier), (int)(er.Width / this._engineToConsoleMultiplier), er.Direction, er.IsBarrier));
 }
コード例 #3
0
 public EngineRectangle TransformConsoleRectangle(EngineRectangle er)
 {
     return(new EngineRectangle(er.X * this._engineToConsoleMultiplier, er.Y * this._engineToConsoleMultiplier, er.Height * this._engineToConsoleMultiplier, er.Width * this._engineToConsoleMultiplier, er.Direction, er.IsBarrier));
 }
コード例 #4
0
 private RectangleF TransformToRectangleF(EngineRectangle er)
 {
     return(new RectangleF(Convert.ToSingle(er.X), Convert.ToSingle(er.Y), Convert.ToSingle(er.Width), Convert.ToSingle(er.Height)));
 }