示例#1
0
        private static bool DinoJump(Dino dino, bool inJump, int startRow, ref int jumpCounter)
        {
            if (Console.KeyAvailable)
            {
                var pressedKey = Console.ReadKey();

                if (pressedKey.Key == ConsoleKey.Spacebar)
                {
                    dino.Y--;
                    inJump = true;
                }
            }

            if (inJump)
            {
                jumpCounter++;

                if (jumpCounter < 3)
                {
                    dino.Y -= jumpCounter;
                }
                else
                {
                    dino.Y += 5 - jumpCounter;
                }
            }

            if (jumpCounter == 6)
            {
                inJump = false;
                jumpCounter = 0;
                dino.Y = startRow;
            }
            return inJump;
        }
示例#2
0
 private static void DisplayDino(Dino dino)
 {
     Console.SetCursorPosition(dino.X, dino.Y);
     Console.WriteLine(dino.dinoBody);
 }
示例#3
0
 private static void DisplayDino(Dino dino)
 {
     Console.SetCursorPosition(dino.X, dino.Y);
     Console.WriteLine(dino.dinoBody);
 }
示例#4
0
        private static void Main()
        {
            var gameOver = false;
            var level = 5;
            var randomGenerator = new Random();
            char[] arrayCactuses = {'^', '@', '*', '&', '+', '%', '$', '#', '!', '.', ';'};
            var obstacles = new Queue<Obstacle>();
            var inJump = false;
            var jumpCounter = 0;

            var watch = new Stopwatch();
            watch.Start();

            Console.BufferHeight = Console.WindowHeight;
            Console.BufferWidth = Console.WindowWidth;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.CursorVisible = false;

            var startCol = 15;
            var startRow = Console.BufferWidth/5;

            var dino = new Dino();
            dino.X = startCol;
            dino.Y = startRow;
            dino.dinoBody = "/\\";

            while (true)
            {
                inJump = DinoJump(dino, inJump, startRow, ref jumpCounter);

                DisplayDino(dino);

                DisplayWatch(watch);

                MoveObstacles(obstacles);

                if (obstacles.Any())
                {
                    if (obstacles.Peek().X == dino.X && obstacles.Peek().Y == dino.Y)
                    {
                        gameOver = true;
                    }
                }

                if (gameOver)
                {
                    watch.Stop();
                    break;
                }

                Thread.Sleep(100);
                Console.Clear();

                GenerateNewObstacle(randomGenerator, level, obstacles, startRow, arrayCactuses);
            }
        }