Exemplo n.º 1
0
        private static Rock MoveRock(Rock rockToMove)
        {
            Console.SetCursorPosition(rockToMove.X, rockToMove.Y);
            Console.Write(" ");

            int newY = rockToMove.Y + 1;

            if (newY > Console.WindowHeight - 1)
            {
                rockToMove = FallingRocks.InitializeNewRock();
            }
            else
            {
                Console.SetCursorPosition(rockToMove.X, newY);
                Console.ForegroundColor = rockToMove.Color;
                Console.Write(rockToMove.TypeOfRock);
                Console.ResetColor();
                rockToMove.Y++;
            }

            return(rockToMove);
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            Console.WindowHeight = FallingRocks.WindowHeight;
            Console.WindowWidth  = FallingRocks.WindowWidth;
            int oldscore  = 0;
            int score     = 0;
            int gamespeed = 200;

            List <Rock> newRock = new List <Rock>();

            for (int i = 0; i < FallingRocks.maxCurrentRock; i++)
            {
                newRock.Add(FallingRocks.InitializeNewRock());
            }

            int dwarfXPosition = (Console.WindowWidth / 2) - 2;
            int dwarfYPosition = Console.WindowHeight - 1;

            WriteDwarf(dwarfXPosition, dwarfYPosition);

            while (true)
            {
                Thread.Sleep(gamespeed);

                Console.SetCursorPosition(0, 0);
                Console.Write("Score: {0:F0}", score);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo userInput = Console.ReadKey();
                    if (userInput.Key == ConsoleKey.RightArrow)
                    {
                        if (dwarfXPosition + 6 < Console.WindowWidth)
                        {
                            dwarfXPosition++;
                            WriteDwarf(dwarfXPosition, dwarfYPosition);
                        }
                    }

                    if (userInput.Key == ConsoleKey.LeftArrow)
                    {
                        if (dwarfXPosition > 0)
                        {
                            dwarfXPosition--;
                            WriteDwarf(dwarfXPosition, dwarfYPosition);
                        }
                    }
                }

                for (int i = 0; i < maxCurrentRock; i++)
                {
                    if (newRock[i].Y == Console.WindowHeight - 1)
                    {
                        if ((newRock[i].X > dwarfXPosition) && (newRock[i].X < (dwarfXPosition + 4)))
                        {
                            WriteDeadDwarf(dwarfXPosition, dwarfYPosition);
                            Console.SetCursorPosition(0, 0);
                            Console.WriteLine("\aGame over");
                            Thread.Sleep(250);
                            Console.WriteLine("\aYour score is {0}", score);
                            Console.ReadKey();
                            return;
                        }
                    }
                }

                for (int i = 0; i < maxCurrentRock; i++)
                {
                    newRock[i] = MoveRock(newRock[i]);
                }

                score = (int)(DateTime.Now - startGameTime).TotalSeconds;
                if ((score - oldscore) > 10)
                {
                    oldscore = score;
                    maxCurrentRock++;
                    newRock.Add(InitializeNewRock());
                }

                if ((score - oldscore) > 25)
                {
                    gamespeed -= 20;
                }
            }
        }