static void Main(string[] args) { Tamagotchi tama = new Tamagotchi(); tama.LoadState(); while(true) { Console.Clear(); Console.WriteLine("Age: " + tama.Age.ToString()); Console.WriteLine("Health: " + tama.Health.ToString()); Console.WriteLine("Energy: " + tama.Energy.ToString()); Console.WriteLine("Hunger: " + tama.Hunger.ToString()); Console.WriteLine("Sleeping?: " + tama.IsSleeping.ToString()); Console.WriteLine("Dead?: " + tama.IsDead.ToString()); if (Console.KeyAvailable) { ConsoleKeyInfo keyPressed = Console.ReadKey(); if (keyPressed.Key == ConsoleKey.F) tama.Feed(25); if (keyPressed.Key == ConsoleKey.S) tama.SaveState(); if (keyPressed.Key == ConsoleKey.L) tama.LoadState(); } } }
// Threading public static void CheckTicks(Tamagotchi tama) { while (tama.GetAlive()) { tama.Tick(); Thread.Sleep(1000); } }
public static void TotalTimer(Tamagotchi tamagotchi, ElapsedEventArgs e) { ForegroundColor = ConsoleColor.DarkRed; WriteLine("\nЧас гри закінчився!"); ResetColor(); timer.AutoReset = false; End(tamagotchi.Failures); }
public static Tamagotchi TamagotchiGenerator() { Tamagotchi tamagotchi = new Tamagotchi(); // ny instans av Tamagotchi Player.tamagotchiList.Add(tamagotchi); // instansen läggs i en lista tamagotchi.name = NameTamagotchi(); // metod som tar input till namn för tamagotchin return(tamagotchi); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Tamagotchi t = new Tamagotchi(); Console.WriteLine("Give your new tamagotchi a name"); t.name = Console.ReadLine(); }
static void Main(string[] args) { Tamagotchi myTama = new Tamagotchi(); Thread ticker = new Thread(() => CheckTicks(myTama)); ticker.Start(); Console.WriteLine("Name your tamagotchi"); myTama.name = Console.ReadLine(); }
static void Main(string[] args) { Tamagotchi tama = new Tamagotchi(); while (tama.GetAlive()) { } TimeDelta(); Console.ReadLine(); }
public static void TamagotchiCheck() { if (Player.tamagotchiList.Count == 0) // om alla tamagotchis är döda eller spelet nyss startats { Console.WriteLine("You don't own a Tamagotchi, let's create one!"); Console.WriteLine(); Tamagotchi tamagotchi = TamagotchiGenerator(); // den aktiva tamagotchin aktiveras automatiskt i detta fall } else // om man har en eller fler levande tamagotchis { return; } }
private void Buy(Tamagotchi tam) //Den här metoden har som uppgift att ge valet till användaren om den vill köpa objektet eller //inte. Om spelaren väljer att köpa det läggs det in i spelarens inventory som sedan kan användas. Metoden är igentligen en del av //Shopchoises metoden, men jag gjord eden separat eftersom den focuserade på ett eget område. Genom att dela upp det i två var det //mindre kod per metod vilket dessutom gjorde det lättare att få en god överblick över koden. Metoden tar även in en paramter. //Eftersom inventory finns i tamagutchii klassen behöver vi skapa en instans för att komma åt inventory. Eftersom en ny tamagutchi //inte ska skapas behövs en redan befintliga tamagutchin refereras till. Anars skulle objektet som användaren köppte läggas in i ett //Separat inventory i en annan tamagutchi, och man skulle därför inte kunna använda objektert. Metoden är en void eftersom ingenting //behövs retuneras. Metoden har som uppgift att bekräfta valet av köpet och lägga in obejtet i inventoryt. Desutom är den Privet då //metoden bara används inom klassen "Shop" och inte behövs nå utanför. Denna metod ger användaren även valet att hoppa av köpet ifall //användaren ångrade sig eller tryckte fel. { if (money - prizes[answerInt] > 0) //Om pengarna - saken som man köper kostar, är högre än 0, har man råd med föremålet. //Om man har råd kan man gå vidare och köpa. Detta har som syfte att förebygga att användaren köper massa saker även om användaren //inte har råd. { System.Console.WriteLine("Vill du köpa? [Y/N]"); answerString = Console.ReadLine(); answerString = ValidAnswer(answerString, "Y", "N"); //Den anropar metoden valid answer för att säkerställa att spelaren inte skriver //In ett ogilltigt svar. Den skickar in tre parametrar. answerString = svaret som sanvändaren skriver in, och de två giltiga svaren //Y och N if (answerString.ToUpper() == "Y") { money = money - prizes[answerInt]; System.Console.WriteLine("Pengar kvar: " + money); tam.inventory.Add(shopShelf[answerInt]); System.Console.WriteLine("Antal saker i ditt inventory: " + tam.inventory.Count); } else if (answerString.ToUpper() == "N") { System.Console.WriteLine("Oki"); } } else //Om pengarna man har - vad föremålet kostar inte är större än ett komenterar programmet på det och //köpet avbryts. Detta är för att användaren ska veta varför köpet avbröts. { System.Console.WriteLine("Ledsen, du har inte råd... dina pengar är:"); System.Console.WriteLine(money + " kr"); Console.ReadLine(); } }
static void Main(string[] args) { //Tamagotchi t = new Tamagotchi("Bob", "Male", 100, 100); //while (t.GetFullness() > 0 && t.GetHappiness() > 0) //{ // Console.WriteLine("Would you like to feed or pet {0}?", t.GetName()); // String action = Console.ReadLine(); // if (action == "feed") // { // t.Feed(); // } // else if (action == "pet") // { // t.Pet(); // } // else // { // Console.WriteLine("You can't do that with " + t.GetName() + ". Please try again!"); // } // t.DoStuff(); // Console.WriteLine("Bob's new stats are:"); // Console.WriteLine("Fullness: {0} | Happiness: {1}", t.GetFullness(), t.GetHappiness()); //} //Console.WriteLine("Oops you killed {0}", t.GetName()); Tamagotchi[] ts = new Tamagotchi[10]; for (int i = 0; i < ts.Length; i++) { ts[i] = new Tamagotchi("test" + i, "M", 100, 100); } for (int i = 0; i < ts.Length; i++) { Console.WriteLine(ts[i].GetName()); } }
static void Main(string[] args) { OutputEncoding = Encoding.Unicode; InputEncoding = Encoding.Unicode; Title = "Tamagotchi"; WriteLine("Вітаємо! Ця програма імітує роботу Тамагочі!\n"); Tamagotchi tamagotchi = new Tamagotchi(); Action action = new Action(tamagotchi.NewAction()); WriteLine("\nПривіт! Давай дружити!"); tamagotchi.Show(); timer.Start(); totalTime.Start(); timer.Elapsed += (sender, e) => OnTimer(action, e, tamagotchi); totalTime.Elapsed += (sender, e) => TotalTimer(tamagotchi, e); timer.AutoReset = true; totalTime.AutoReset = false; ReadKey(true); }
void ChooseTamagotchi() { Console.WriteLine("Which tamagotchi do you want to play with?"); Tamagotchi.ViewList(); ConsoleKeyInfo uInput = Console.ReadKey(); int uInputInt; bool parse = int.TryParse(uInput.ToString(), out uInputInt); if (parse == true && uInputInt - 1 <= Tamagotchi.list.Count) { Console.WriteLine($"You chose {uInputInt - 1}: {Tamagotchi.list[uInputInt - 1].name}"); ContinueButton(); PlayingWithTamaGotchi(Tamagotchi.list[uInputInt - 1]); } else { Console.WriteLine("No tamagotchi found"); ContinueButton(); } }
static void Action(int input, Tamagotchi newGotchi) { if ((input - 1) == 0) // lära ord { Console.Clear(); newGotchi.Teach(EnterWord()); } if ((input - 1) == 1) // hälsa { Console.Clear(); newGotchi.Hi(); } if ((input - 1) == 2) // mata { Console.Clear(); newGotchi.Feed(); } if ((input - 1) == 3) // gör ingenting { Console.Clear(); Console.WriteLine("You do nothing"); } if ((input - 1) == 4) // gör en ny gotchi { TamagotchiGenerator(); Console.Clear(); } if ((input - 1) == 5) // byter aktiv gotchi { Console.Clear(); Start(); } if ((input - 1) == 6) // byter aktiv gotchi { Environment.Exit(0); } }
static void Main(string[] args) { Tamagotchi tama = new Tamagotchi(); tama.LoadState(); while (true) { Console.Clear(); Console.WriteLine("Age: " + tama.Age.ToString()); Console.WriteLine("Health: " + tama.Health.ToString()); Console.WriteLine("Energy: " + tama.Energy.ToString()); Console.WriteLine("Hunger: " + tama.Hunger.ToString()); Console.WriteLine("Sleeping?: " + tama.IsSleeping.ToString()); Console.WriteLine("Dead?: " + tama.IsDead.ToString()); if (Console.KeyAvailable) { ConsoleKeyInfo keyPressed = Console.ReadKey(); if (keyPressed.Key == ConsoleKey.F) { tama.Feed(25); } if (keyPressed.Key == ConsoleKey.S) { tama.SaveState(); } if (keyPressed.Key == ConsoleKey.L) { tama.LoadState(); } } } }
static void Main(string[] args) { string playMore = "yes"; while (playMore == "yes") { Tamagotchi tamagotchi = new Tamagotchi(); bool carryOn = true; while (carryOn == true) { Console.WriteLine("What will you name your tamagotchi?"); tamagotchi.name = Console.ReadLine(); Console.WriteLine(tamagotchi.name + ", what a lovley name!"); sleep(); while (tamagotchi.GetAlive() == true) { tamagotchi.PrintStats(); sleep(); Console.WriteLine("please choosewhat you want to do with " + tamagotchi.name + "\n[Teach]" + "\n[Feed]" + "\n[Speak]" + "\n[Nothing]"); // + "\n[Kill it!]" // + "\n[add another]"); string answer = Console.ReadLine().ToLower(); while (answer != "teach" && answer != "feed" && answer != "speak" && answer != "nothing") { Console.WriteLine("Only accepting any of the four choices"); answer = Console.ReadLine(); } if (answer.ToLower() == "teach") { Console.WriteLine("Word to teach"); string learnWord = Console.ReadLine(); tamagotchi.Teach(learnWord); } else if (answer.ToLower() == "feed") { Console.WriteLine("You feed your tamagotchi"); tamagotchi.Feed(); } else if (answer.ToLower() == "speak") { tamagotchi.Hi(); } if (answer.ToLower() == "nothing") { Console.WriteLine("You did nothing."); } tamagotchi.Tick(); sleep(); Console.Clear(); } Console.WriteLine("Do you want to create a new tamagotchi?" + "\n[Yes]" + "\n[No]"); playMore = Console.ReadLine().ToLower(); } Console.ReadLine(); //if( carryOn != yes) {Shutdown();} } }
static void Main(string[] args) { Tamagotchi tamagotchi = new Tamagotchi(); Console.ReadLine(); }
static void Main(string[] args) { System.Console.WriteLine("Du kör nu Tamagotchi game"); Tamagotchi t1 = new Tamagotchi(); System.Console.WriteLine("Vad vill du döpa din Tamagotchi till?"); t1.name = Console.ReadLine(); System.Console.WriteLine("Din tamagotchi heter nu " + t1.name); Thread.Sleep(2000); // boolar game is running bool gameIsRunning = true; while (gameIsRunning) { Console.Clear(); t1.PrintStats(); System.Console.WriteLine(); t1.GetAlive(); if (t1.GetAlive() == false) { gameIsRunning = false; } else { // boolar correctInput så man skriver A-D bool correctInput = false; while (!correctInput) { System.Console.WriteLine("Vad vill du att din tamagotchi ska göra?:"); System.Console.WriteLine(@" [A] Lära den ett nytt ord [B] Hälsa på den [C] Mata den [D] Göra ingenting "); string input = Console.ReadLine(); input = input.ToUpper(); if (input == "A") { t1.Teach(); correctInput = true; } else if (input == "B") { t1.Hi(); Thread.Sleep(1750); correctInput = true; } else if (input == "C") { t1.Feed(); System.Console.WriteLine("Du matade din tamagotchi"); correctInput = true; } else if (input == "D") { correctInput = true; } else { Console.Clear(); System.Console.WriteLine("\n Vänligen skriv en riktig input"); } } // kör en tick efter att spelaren gjort ett accepterat val (A-D) t1.Tick(); } } System.Console.WriteLine("GAME OVER"); Console.ReadLine(); }
static void Main(string[] args) { bool alive = true; bool understood = false; string answer; Tamagotchi newTamagotchi = new Tamagotchi(); Console.WriteLine("Name your tomagatchi:"); newTamagotchi.name = Console.ReadLine(); while (alive == true) { Console.Clear(); understood = false; newTamagotchi.Tick(); alive = newTamagotchi.GetAlive(); System.Console.WriteLine("What would you like to do?"); System.Console.WriteLine("1: Say hi to your tamagotchi"); System.Console.WriteLine("2: See your tamagotchi's stats"); System.Console.WriteLine("3: Feed your tamagotchi"); System.Console.WriteLine("4: Teach your tamagotchi a new word"); System.Console.WriteLine("5: Nothing"); while (understood == false) { answer = Console.ReadLine(); switch (answer.ToLower()) { case "1": understood = true; newTamagotchi.Hi(); break; case "2": understood = true; newTamagotchi.PrintStats(); break; case "3": understood = true; newTamagotchi.Feed(); break; case "4": understood = true; System.Console.WriteLine("What word would you like to teach " + newTamagotchi.name + "?"); string word = Console.ReadLine(); newTamagotchi.Teach(word); break; case "5": understood = true; break; default: System.Console.WriteLine("Sorry, I didn't understand that."); break; } Console.ReadLine(); } } System.Console.WriteLine(newTamagotchi.name + " has died."); Console.ReadLine(); }
void WhenDead(Tamagotchi myTama) { Console.Clear(); System.Console.WriteLine($"{myTama.name} died..."); Console.ReadLine(); }
public static void TamagotchiDied(Tamagotchi gotchi) { Console.Clear(); Console.WriteLine(gotchi.name + " died"); Player.tamagotchiList.Remove(gotchi); // tar bort den döda tamagotchin från spelarens lista av tamagotchis }
public void PrintStats(Tamagotchi activeTamagotchi) { Console.WriteLine("Active Tamagotchi: " + activeTamagotchi.name); Console.WriteLine("Hunger: " + hunger); Console.WriteLine("Boredom: " + boredom); }
void PlayingWithTamaGotchi(Tamagotchi myTama) { while (myTama.GetAlive()) { Console.Clear(); System.Console.WriteLine($"1. Teach {myTama.name} a new word"); System.Console.WriteLine($"2. Say hi to {myTama.name}"); System.Console.WriteLine($"3. Give {myTama.name} food"); Console.WriteLine("4. Make a new Tamagotchi."); Console.WriteLine("5. View list of Tamagotchis"); System.Console.WriteLine("6. Don't do anything"); ConsoleKeyInfo uInput = Console.ReadKey(); switch (uInput.Key) { case ConsoleKey.D1: Console.Clear(); System.Console.WriteLine("The word you want to teach"); string newWord = Console.ReadLine(); myTama.Teach(newWord); System.Console.WriteLine($"You teached her {newWord}"); ContinueButton(); break; case ConsoleKey.D2: Console.Clear(); System.Console.WriteLine("Hi!"); myTama.Hi(); ContinueButton(); break; case ConsoleKey.D3: Console.Clear(); System.Console.WriteLine($"You fed {myTama.name}"); myTama.Feed(); ContinueButton(); break; case ConsoleKey.D4: Console.Clear(); Console.WriteLine("What do you want to name your new Tamagotchi?"); Tamagotchi tama2 = new Tamagotchi(); tama2.name = Console.ReadLine(); Console.WriteLine($"added {tama2.name} to your Tamagotchi list."); ContinueButton(); break; case ConsoleKey.D5: Console.Clear(); Console.WriteLine("List of your tamagotchis"); Tamagotchi.ViewList(); ContinueButton(); break; case ConsoleKey.D6: Console.Clear(); System.Console.WriteLine("You did nothing..."); ContinueButton(); break; default: Console.Clear(); System.Console.WriteLine("bRuh"); ContinueButton(); break; } } WhenDead(myTama); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.White; RestClient client = new RestClient("https://pokeapi.co/api/v2/"); string userinput; //Skapar en lista med currys, där alla currys som spelaren skapar skulle lagras (cancelled) List <Curry> currys; //Skapar tamagotchi instansen Tamagotchi tamagotchi1 = new Tamagotchi(); Console.WriteLine("Welcome to Pokemon x Tamagotchi 2019! " + "Which starter do you want?"); Console.WriteLine("A: Chikorita"); Console.WriteLine("B: Cyndaquil"); Console.WriteLine("C: Totodile"); //Bestämmer att så länge tamagotchin inte fått sin namn så körs loopen tamagotchi1.name = "none"; while (tamagotchi1.name == "none") { userinput = Console.ReadLine(); userinput = userinput.ToLower(); if (userinput == "a") { //Requestar en pokemon beroende på användarens val av pokemon, med detta bestäms namnet på // tamagotchin RestRequest request = new RestRequest("pokemon/chikorita"); IRestResponse response = client.Get(request); Pokemon p = JsonConvert.DeserializeObject <Pokemon>(response.Content); tamagotchi1.name = p.name; tamagotchi1.requiredExp = p.base_experience; } else if (userinput == "b") { RestRequest request = new RestRequest("pokemon/cyndaquil"); IRestResponse response = client.Get(request); Pokemon p = JsonConvert.DeserializeObject <Pokemon>(response.Content); tamagotchi1.name = p.name; tamagotchi1.requiredExp = p.base_experience; } else if (userinput == "c") { RestRequest request = new RestRequest("pokemon/totodile"); IRestResponse response = client.Get(request); Pokemon p = JsonConvert.DeserializeObject <Pokemon>(response.Content); tamagotchi1.name = p.name; tamagotchi1.requiredExp = p.base_experience; } //en else som körs ifall användar inputen inte är något av alternativen else { Console.WriteLine("Enter a valid input"); } } //En kort loadingscreen som körs för att användaren ska se att det händer något och inte blir förvirrad //medans requesten görs Loading(); //En loop som körs så länge tamagotchin är vid liv while (tamagotchi1.GetAlive() == true) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Caution! Don't let your pokemon's hunger or boredom get over 10!"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); Console.WriteLine("Stats:"); tamagotchi1.PrintStats(); Console.WriteLine(); Console.WriteLine("What would you like to do?"); Console.WriteLine(); Console.WriteLine("A: Feed " + tamagotchi1.name + " (reduce hunger)"); Console.WriteLine("B: Train " + tamagotchi1.name + " (gain exp)"); Console.WriteLine("C: Cook curry with " + tamagotchi1.name + " (reduce boredom)"); userinput = Console.ReadLine(); userinput = userinput.ToLower(); if (userinput == "a") { tamagotchi1.Tick(); tamagotchi1.Feed(); } else if (userinput == "b") { tamagotchi1.Tick(); tamagotchi1.Train(); if (tamagotchi1.experiencePoints >= tamagotchi1.requiredExp * tamagotchi1.GetLevel()) { tamagotchi1.LevelUp(); } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Press enter to continue:"); Console.ForegroundColor = ConsoleColor.White; Console.ReadLine(); Console.Clear(); } else if (userinput == "c") { Console.WriteLine("What should the main ingredient be?"); string ingredient = Console.ReadLine(); tamagotchi1.Tick(); tamagotchi1.CookCurry(ingredient); } else { Console.Clear(); Console.WriteLine("Please enter a valid action!"); Console.WriteLine(); } } Gameover(); }
static void Main(string[] args) { Tamagotchi tam = new Tamagotchi(); tam.Feed(); }