예제 #1
0
      private void PauseGame(bool isNotPaused)
      {
          isNotPaused = false;
          isNotPaused = ScreenController.PauseGame(this);
          int width  = Terrarium.Width + 1;
          int height = Terrarium.Height + 5;

          Console.SetWindowSize(width, height);
          Console.SetBufferSize(width, height);
          Console.Clear();
          Terrarium.CreateEmptyTerrarium();
          Terrarium.RenderAnimals();
          Terrarium.RenderPlants();
      }
예제 #2
0
      private void FirstDay()
      {
          // Clear the console
          Console.Clear();
          // Print the terrarium to the console using colors
          Terrarium.CreateEmptyTerrarium();

          if (!loadedGame)
          {
              // Add Organisms to List
              for (int i = 0; i < TerrariumSettings.Carnivores; i++)
              {
                  addIOrganism(new Carnivore());
              }
              for (int i = 0; i < TerrariumSettings.Herbivores; i++)
              {
                  addIOrganism(new Herbivore());
              }
              for (int i = 0; i < TerrariumSettings.Plants; i++)
              {
                  addIOrganism(new Plant());
              }
              for (int i = 0; i < TerrariumSettings.Humans; i++)
              {
                  addIOrganism(new Human());
              }
          }



          // Render the animals
          Terrarium.RenderAnimals();
          Terrarium.RenderPlants();

          // Update timestep according to n organisms (n / animals)
          // This way turns always last n ms
          TimeController.SetStepTimeout();

          // Wait for input
          Console.ForegroundColor = ConsoleColor.White;
          Console.SetCursorPosition(0, Terrarium.Height + 3);
          Console.Write("Press 'Enter' to start");


          string input = Console.ReadLine();

          Console.SetCursorPosition(0, Terrarium.Height + 3);
          Console.WriteLine("                       ");
      }
예제 #3
0
      public void Activate(Terrarium terrarium, TimeController timeController)
      {
          AudioController.PlayEarthquake();

          List <Position>  earthQuakePositions = new List <Position>();
          List <IOrganism> organismsToShuffle  = new List <IOrganism>();

          string quakeChar = StringManager.GetExtendedAsciiCodeAsString(176);

          Console.ForegroundColor = ConsoleColor.DarkYellow;
          Console.BackgroundColor = ConsoleColor.DarkRed;


          int size = 7;

          for (int i = 0; i < size; i++)
          {
              if (Position.X + i < terrarium.Width && Position.Y + i < terrarium.Height)
              {
                  Console.SetCursorPosition(Position.X + i, Position.Y + i);
                  earthQuakePositions.Add(new Position(Position.X + i, Position.Y + i));
                  Console.Write(quakeChar);
              }
              if (Position.X - i >= 0 && Position.Y + i < terrarium.Height)
              {
                  Console.SetCursorPosition(Position.X - i, Position.Y + i);
                  earthQuakePositions.Add(new Position(Position.X - i, Position.Y + i));
                  Console.Write(quakeChar);
              }
              if (Position.X - i >= 0 && Position.Y - i >= 0)
              {
                  Console.SetCursorPosition(Position.X - i, Position.Y - i);
                  earthQuakePositions.Add(new Position(Position.X - i, Position.Y - i));
                  Console.Write(quakeChar);
              }
              if (Position.X + i < terrarium.Width && Position.Y - i >= 0)
              {
                  Console.SetCursorPosition(Position.X + i, Position.Y - i);
                  earthQuakePositions.Add(new Position(Position.X + i, Position.Y - i));
                  Console.Write(quakeChar);
              }

              for (int j = 0; j < size - 2; j++)
              {
                  if (Position.X + i < terrarium.Width && Position.Y + j < terrarium.Height)
                  {
                      Console.SetCursorPosition(Position.X + i, Position.Y + j);
                      earthQuakePositions.Add(new Position(Position.X + i, Position.Y + j));
                      Console.Write(quakeChar);
                  }
                  if (Position.X - j >= 0 && Position.Y + i < terrarium.Height)
                  {
                      Console.SetCursorPosition(Position.X - j, Position.Y + i);
                      earthQuakePositions.Add(new Position(Position.X - j, Position.Y + i));
                      Console.Write(quakeChar);
                  }
                  if (Position.X - i >= 0 && Position.Y - j >= 0)
                  {
                      Console.SetCursorPosition(Position.X - i, Position.Y - j);
                      earthQuakePositions.Add(new Position(Position.X - i, Position.Y - j));
                      Console.Write(quakeChar);
                  }
                  if (Position.X + j < terrarium.Width && Position.Y - i >= 0)
                  {
                      Console.SetCursorPosition(Position.X + j, Position.Y - i);
                      earthQuakePositions.Add(new Position(Position.X + j, Position.Y - i));
                      Console.Write(quakeChar);
                  }
              }

              timeController.Step(50);
          }

          foreach (IOrganism organism in terrarium.Organisms)
          {
              foreach (Position pos in earthQuakePositions)
              {
                  if (organism.Position.Equals(pos) && !organismsToShuffle.Contains(organism))
                  {
                      organismsToShuffle.Add(organism);
                  }
              }
          }


          foreach (IOrganism organism in organismsToShuffle)
          {
              organism.LastPosition.X = organism.Position.X;
              organism.LastPosition.Y = organism.Position.Y;

              Position randomPositionInQuake = earthQuakePositions[random.Next(earthQuakePositions.Count)];
              organism.Position.X = randomPositionInQuake.X;
              organism.Position.Y = randomPositionInQuake.Y;
          }

          Console.ResetColor();

          terrarium.RenderPlants();
          terrarium.RenderAnimals();
      }