Exemplo n.º 1
0
 public bool DecreaseLives()
 {
     if (dwarfLives > 1)
     {
         this.dwarfLives--;
         this.ShowLives();
         return(true);
     }
     else
     {
         FallingRocks.GameOver(); // needs to be redone properly
         return(false);
     }
 }
Exemplo n.º 2
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.º 3
0
        public void Quit()
        {
            ConsoleKeyInfo readKey;
            int            x = fieldWidth / 2;
            int            y = fieldHeight / 2;

            lock (FallingRocks.syncObject)
            {
                this.Print(x - 22, y - 2, x + 22, y + 2);
                WriteAt(x - 20, y, "Do you really want to leave the game Y/N? ", 12);
                do
                {
                    readKey = Console.ReadKey(true);
                } while (!(readKey.KeyChar == 'y' || readKey.KeyChar == 'Y' || readKey.KeyChar == 'n' || readKey.KeyChar == 'N'));
                if (readKey.KeyChar == 'n' || readKey.KeyChar == 'N')
                {
                    this.Clear(x - 22, y - 2, x + 22, y + 2);
                }
                else
                {
                    FallingRocks.GameOver();
                }
            }
        }
Exemplo n.º 4
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;
                }
            }
        }