// Create empty terrarium string filled with ground public void CreateEmptyTerrarium() { // Create empty string array StringBuilder s = new StringBuilder(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { // Fill string with ground tile ascii character (code 176) s.Append(StringManager.GetExtendedAsciiCodeAsString(176)); } s.Append('\n'); } // Set color of ground Console.ForegroundColor = ConsoleColor.DarkYellow; // Print the terrarium Console.WriteLine(s.ToString()); }
/* Methods */ public void RenderAnimals() { // Get animals from organisms list var animalList = Organisms.Where(o => o is Animal); foreach (Animal animal in animalList) { // Set previous position to ground tile Console.SetCursorPosition( animal.LastPosition.X, animal.LastPosition.Y ); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write(StringManager.GetExtendedAsciiCodeAsString(176)); // Update current position Console.SetCursorPosition( animal.Position.X, animal.Position.Y ); Console.ForegroundColor = animal.DisplayColor; Console.Write(animal.DisplayLetter); } }
public void Activate(Terrarium terrarium, TimeController timeController) { AudioController.PlayVulcano(); List <Position> vulcanoPositions = new List <Position>(); List <IOrganism> organismsToDelete = new List <IOrganism>(); string vulcChar = StringManager.GetExtendedAsciiCodeAsString(176); Console.ForegroundColor = ConsoleColor.Yellow; Console.BackgroundColor = ConsoleColor.Red; int size = 5; 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); vulcanoPositions.Add(new Position(Position.X + i, Position.Y + i)); Console.Write(vulcChar); } if (Position.X - i >= 0 && Position.Y + i < terrarium.Height) { Console.SetCursorPosition(Position.X - i, Position.Y + i); vulcanoPositions.Add(new Position(Position.X - i, Position.Y + i)); Console.Write(vulcChar); } if (Position.X - i >= 0 && Position.Y - i >= 0) { Console.SetCursorPosition(Position.X - i, Position.Y - i); vulcanoPositions.Add(new Position(Position.X - i, Position.Y - i)); Console.Write(vulcChar); } if (Position.X + i < terrarium.Width && Position.Y - i >= 0) { Console.SetCursorPosition(Position.X + i, Position.Y - i); vulcanoPositions.Add(new Position(Position.X + i, Position.Y - i)); Console.Write(vulcChar); } for (int j = 0; j < size - 3; j++) { if (Position.X + i < terrarium.Width && Position.Y + j < terrarium.Height) { Console.SetCursorPosition(Position.X + i, Position.Y + j); vulcanoPositions.Add(new Position(Position.X + i, Position.Y + j)); Console.Write(vulcChar); } if (Position.X - j >= 0 && Position.Y + i < terrarium.Height) { Console.SetCursorPosition(Position.X - j, Position.Y + i); vulcanoPositions.Add(new Position(Position.X - j, Position.Y + i)); Console.Write(vulcChar); } if (Position.X - i >= 0 && Position.Y - j >= 0) { Console.SetCursorPosition(Position.X - i, Position.Y - j); vulcanoPositions.Add(new Position(Position.X - i, Position.Y - j)); Console.Write(vulcChar); } if (Position.X + j < terrarium.Width && Position.Y - i >= 0) { Console.SetCursorPosition(Position.X + j, Position.Y - i); vulcanoPositions.Add(new Position(Position.X + j, Position.Y - i)); Console.Write(vulcChar); } } timeController.Step(50); } foreach (IOrganism organism in terrarium.Organisms) { foreach (Position pos in vulcanoPositions) { if (organism.Position.Equals(pos) && !organismsToDelete.Contains(organism)) { organismsToDelete.Add(organism); } } } foreach (IOrganism organism in organismsToDelete) { terrarium.Organisms.Remove(organism); } Console.ResetColor(); }
// Print HowTo public void printHowTo(int x, int y) { var output = new StringBuilder(); var herbivore = StringManager.GetExtendedAsciiCodeAsString(20); var carnivore = StringManager.GetExtendedAsciiCodeAsString(206); var human = StringManager.GetExtendedAsciiCodeAsString(219); var plant = StringManager.GetExtendedAsciiCodeAsString(157); Console.SetCursorPosition(x, y); Console.ForegroundColor = ConsoleColor.DarkBlue; Console.Write(herbivore + " "); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.Write(herbivore + " "); Console.ForegroundColor = ConsoleColor.Blue; Console.Write(herbivore + " "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(herbivore + " "); Console.ForegroundColor = ConsoleColor.White; Console.Write(": Icon for herbivores with color for health"); y++; Console.SetCursorPosition(x, y); Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write(carnivore + " "); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.Write(carnivore + " "); Console.ForegroundColor = ConsoleColor.Red; Console.Write(carnivore + " "); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(carnivore + " "); Console.ForegroundColor = ConsoleColor.White; Console.Write(": Icon for carnivores with color for health"); y++; Console.SetCursorPosition(x, y); Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write(human + " "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(human + " "); Console.ForegroundColor = ConsoleColor.White; Console.Write(human + " "); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(human + " "); Console.ForegroundColor = ConsoleColor.White; Console.Write(": Icon for humans with color for health"); y++; Console.SetCursorPosition(x, y); Console.ForegroundColor = ConsoleColor.Green; Console.Write(plant + " "); Console.ForegroundColor = ConsoleColor.White; Console.Write(": Icon for plants"); y++; y++; y++; Console.SetCursorPosition(x, y); Console.Write("Press "); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("V"); Console.ForegroundColor = ConsoleColor.White; Console.Write(" to spawn a volcano eruptions at a random position"); y++; Console.SetCursorPosition(x, y); Console.Write("Press "); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("E"); Console.ForegroundColor = ConsoleColor.White; Console.Write(" to create an earthquake at a random position"); y++; Console.SetCursorPosition(x, y); Console.Write("Press "); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("ESC"); Console.ForegroundColor = ConsoleColor.White; Console.Write(" to pause and save the game"); }
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(); }