{}
run-icon
Main.cs
using System; using System.Collections.Generic; using System.Timers; public class HelloWorld { private static Timer timer; private static double coins = 0; public static double coinsMultiplier = 1; public static void Main(string[] args) { Random random = new Random(); List<Pet> equippedPets = new List<Pet>(); Pet dog = new Pet("Dog", 1.1, 50, 5, 1.5); Pet bird = new Pet("Bird", 1.3, 25, 10, 2); Pet lizard = new Pet("Lizard", 1.4, 15, 20, 3); Pet snake = new Pet("Snake", 1.6, 5, 50, 5); Pet lion = new Pet("Lion", 1.8, 4, 75, 8); Pet dinosaur = new Pet("Dinosaur", 2, 1, 100, 10); Pet gnome = new Pet("gnome", 1.1, 40, 20, 2); Pet minotaur = new Pet("minotaur", 1.3, 25, 50, 5); Pet chimera = new Pet("chimera", 1.4, 15, 100, 9); Pet phoenix = new Pet("Phoenix", 1.6, 10, 150, 12); Pet hydra = new Pet("Hydra", 1.8, 9.8, 200, 15); Pet titan = new Pet("Titan", 3, 0.2, 500, 25); Egg commonEgg = new Egg(10, new Pet[] { dog, bird, lizard, snake, lion, dinosaur }); Egg mythologicalEgg = new Egg(50, new Pet[] { gnome, minotaur, chimera, phoenix, hydra, titan }); Egg[] eggs = { commonEgg, mythologicalEgg }; int hatchCount = 0; float luckBoost = 1; int chosenEgg = 0; Pet mostRecentPet = null; timer = new Timer(1000); timer.Elapsed += IncrementCoins; timer.AutoReset = true; timer.Enabled = true; Console.WriteLine("Welcome to Hatching Egg Simulator!"); Console.WriteLine("In this simulation, you can hatch eggs to roll different pets."); Console.WriteLine("rolling pets costs money. You make money every second."); Console.WriteLine("The pets you roll can boost your money and luck if equipped."); Console.WriteLine("You can only equip 3 pets."); Console.WriteLine("You can also sell pets for money."); Console.WriteLine("!!!IF YOU ROLL PAST A PET WITHOUT SELLING OR EQUIPPING YOU WON'T GAIN ANYTHING!!!"); Console.WriteLine("Type 'instructions' for a list of all commands, and to start playing."); while (true) { double RNG = random.NextDouble() * (100 / luckBoost); string input = Console.ReadLine(); if (input.ToLower() == "exit") { break; } else if (input.ToLower() == "equip") { if (mostRecentPet != null && equippedPets.Count<3) { equippedPets.Add(mostRecentPet); luckBoost += (float)mostRecentPet.luckMultiplier; coinsMultiplier += (float)mostRecentPet.moneyMultiplier; Console.WriteLine(mostRecentPet.name + " has been equipped."); mostRecentPet = null; } else { Console.WriteLine("No pet has been hatched yet to equip, or equip storage ran out."); } continue; } else if (input.ToLower() == "equipped pets") { if (equippedPets.Count > 0) { Console.WriteLine("Equipped pets:"); foreach (Pet item in equippedPets) { Console.WriteLine(item.name + " (Luck Multiplier: " + item.luckMultiplier + ")" + " (Coins Multiplier:" + item.moneyMultiplier + ")"); } } else { Console.WriteLine("No pets have been equipped yet."); } continue; } else if (input.ToLower() == "unequip") { if (equippedPets.Count > 0) { Console.WriteLine("Equipped pets:"); for (int i = 0; i < equippedPets.Count; i++) { Console.WriteLine(i + ": " + equippedPets[i].name + " (Luck Multiplier: " + equippedPets[i].luckMultiplier + ")"); } Console.WriteLine("Select index of pet to unequip:"); string userInput = Console.ReadLine(); int petIndex; if (int.TryParse(userInput, out petIndex) && petIndex >= 0 && petIndex < equippedPets.Count) { Pet petToUnequip = equippedPets[petIndex]; equippedPets.RemoveAt(petIndex); luckBoost -= (float)petToUnequip.luckMultiplier; coinsMultiplier -= (float)petToUnequip.moneyMultiplier; coins += (float)petToUnequip.sellValue; Console.WriteLine(petToUnequip.name + " has been unequipped/sold for: " + petToUnequip.sellValue + " coins."); } else { Console.WriteLine("Invalid index."); } } else { Console.WriteLine("No pets are currently equipped."); } continue; } else if (input.ToLower() == "new egg") { Console.WriteLine("Enter index (number) of new egg to switch to:"); Console.WriteLine("0: Common Egg (default if mispelling occurs) (Cost: 10 coins per roll)"); Console.WriteLine("1: Mythological Egg (Cost: 50 coins per roll)"); chosenEgg = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Egg Switched Successfully! Enter to roll."); continue; } else if (input.ToLower() == "instructions") { instructions(); } else if (input.ToLower() == "sell") { coins += (mostRecentPet.sellValue) * coinsMultiplier; Console.WriteLine (mostRecentPet.name + " has been sold for " + ((mostRecentPet.sellValue) * coinsMultiplier) + " coins!"); mostRecentPet = null; } else if (input.ToLower() == "stats") { Console.WriteLine("Total Luck Multiplier: " + luckBoost); Console.WriteLine("Total Coins Multiplier: " + coinsMultiplier); Console.WriteLine("Total amount of eggs hatched: " + hatchCount); Console.WriteLine("Coins: " + coins); } else { if (coins >= eggs[chosenEgg].cost) { mostRecentPet = (Pet)hatchEgg(RNG, eggs[chosenEgg].pets); Console.WriteLine(mostRecentPet.name + ", with a " + mostRecentPet.percentage + "% Chance."); hatchCount++; coins -= eggs[chosenEgg].cost; continue; } else { Console.WriteLine("Insufficent Funds. Current amount of coins: " + coins); Console.WriteLine("Amount of coins needed: " + eggs[chosenEgg].cost); } } } } static object hatchEgg(double RNG, Pet[] egg) { float cumulativeChance = 100; for (int i = 0; i < egg.Length; i++) { cumulativeChance -= (float)egg[i].percentage; if (RNG >= cumulativeChance) { return egg[i]; } } return egg[0]; } static void instructions() { Console.WriteLine("Instructions (READ ALL OF THEM!):"); Console.WriteLine("---------------------------------------------------"); Console.WriteLine("Press Enter to roll."); Console.WriteLine("Type 'exit' to quit."); Console.WriteLine("Type 'stats' to see your statistics."); Console.WriteLine("Type 'equip' to equip the most recent pet rolled."); Console.WriteLine("Type 'equipped pets' to view all equipped pets."); Console.WriteLine("Type 'unequip' to unequip a pet by index. (NOTE: UNEQUIPPED PETS CANNOT BE REQUIPPED!)"); Console.WriteLine("Type 'new egg' to start hatching pets from a new egg (default egg is called 'Common Egg'"); Console.WriteLine("TYPE 'INSTRUCTIONS' TO RECIEVE THIS MESSAGE AGAIN!!!"); Console.WriteLine("Type 'sell' to sell most recently rolled pet."); Console.WriteLine("---------------------------------------------------"); } public class Pet { public string name; public double luckMultiplier; public double percentage; public double sellValue; public double moneyMultiplier; public Pet(string value1, double value2, double value3, double value4, double value5) { this.name = value1; this.luckMultiplier = value2; this.percentage = value3; this.sellValue = value4; this.moneyMultiplier = value5; } } public class Egg { public double cost; public Pet[] pets; public Egg(double cost, Pet[] pets) { this.cost = cost; this.pets = pets; } } private static void IncrementCoins(Object source, ElapsedEventArgs e) { coins+= 1 * coinsMultiplier; } }
Output