private static void ChooseClass() { Dictionary <string, string> classInfo = new Dictionary <string, string>() { { "Mage", "The Mage class gives 2 extra Defence value. Starting weapon: Magic staff" }, { "Ranged", "The Ranged class Gives 2 extra Attack value. Starting weapon: Bow" }, { "Warrior", "The Warrior class Gives 2 extra Health value. Starting weapon: Sword" }, }; int chosenClass; bool parseSuccessful; Console.WriteLine("Choose a class for your character by picking the number next to the class you want to play as: \n"); do { PrintDesign.PrintFrameWithClassInfo(classInfo); Console.Write("choose number: "); parseSuccessful = int.TryParse(Console.ReadLine(), out chosenClass); if (chosenClass > 3 || chosenClass <= 0 || parseSuccessful == false) { Console.Clear(); PrintDesign.WriteLineInRed("Class doesnt exists. Choose the number next to one of the classes below:\n"); } } while (chosenClass > 3 || chosenClass <= 0 || parseSuccessful == false); List <string> classes = classInfo.Keys.ToList(); Console.Clear(); Console.WriteLine($"You chose the {classes[chosenClass - 1].ToUpper()} class\n"); NameCharacter(classes[chosenClass - 1]); }
private void MenuAction(int choice, Player customer) { Console.ForegroundColor = ConsoleColor.Yellow; switch (choice) { case 1: WeaponAvailableForSell(customer); break; case 2: ArmorsAvaliableForSell(customer); break; case 3: SpecialItemsAvaliableForSell(customer); break; case 4: SellItems(customer); break; case 5: Console.Clear(); PrintDesign.WriteLineInYellow("Thank you for visiting the shop! Welcome back anytime."); break; default: break; } }
public static void MenuAction(int choice) { switch (choice) { case 1: if (rnd.Next(1, 11) == 10) { Console.WriteLine("You walk by without seeing any enemies!"); Console.Clear(); } else { Battle.StartFight(player, enemies[rnd.Next(enemies.Count)]); // skickar med spelaren och en random vald fiende i listan } break; case 2: player.PlayerInfo(); break; case 3: if (Player.backpack.Count == 0) { Console.Clear(); PrintDesign.WriteLineInRed("Backpack is currently empty!"); } else { PrintDesign.PrintBackpack(Player.backpack); } break; case 4: shop.ShopMenu(player); break; case 5: player.GodMode(); break; case 6: Exit(); break; default: break; } }
public void GodMode() { if (PlayGodMode == true) { Console.Clear(); PrintDesign.WriteLineInRed("You already play with godmode!"); } else { Console.Clear(); Console.WriteLine("Have fun with Godmode!"); MaxBlock += 1000; MaxDmg += 80; Gold = 9999999; PlayGodMode = true; } }
private void SellItems(Player customer) { var backpackItemsName = Player.backpack.Keys.ToList(); // hämmtar namnet på sakerna i backpacken var backpackItemsValue = Player.backpack.Values.ToList(); // hämtar värdet på sakerna i backpacken int choice; bool parseSuccessfull; if (Player.backpack.Count == 0) { Console.Clear(); PrintDesign.WriteLineInRed("You have nothing to sell!"); } else { do { PrintDesign.PrintShop(Player.backpack); Console.WriteLine("Select the number next to the item that you want to sell: "); Console.Write("Number: "); parseSuccessfull = int.TryParse(Console.ReadLine(), out choice); if (choice > Player.backpack.Count + 1) { Console.Clear(); PrintDesign.WriteLineInRed("Number to high. Choose one of the numbers infront of the items"); } else if (choice <= 0) { Console.Clear(); PrintDesign.WriteLineInRed("Number to low. Choose one of the numbers infront of the items"); } else if (parseSuccessfull == false) { Console.Clear(); PrintDesign.WriteLineInRed("Something went wrong! Try again"); } } while (choice > Player.backpack.Count + 1 || choice <= 0 || parseSuccessfull == false); Console.Clear(); PrintDesign.WriteLineInGreen($"\nSold {backpackItemsName[choice - 1]} for {backpackItemsValue[choice - 1]} gold"); customer.Gold += backpackItemsValue[choice - 1]; // adderar guldet för den sålda varan till spelaren Player.backpack.Remove(backpackItemsName[choice - 1]); // tar bort sålda varan från ryggsäcken } }
/// <summary> /// Hämtar loot ifall det finns och ifall spelaren vill plocka upp det. /// </summary> public static void GetLoot(EnemyModel enemy, PlayerModel player) { string answer; int lootValue; string loot = enemy.droppedLoot(out lootValue); if (loot == null) { PrintDesign.WriteLineInGreen($"You search dead {enemy.Name} and find {enemy.Gold} gold, but no additional loot."); player.Gold += enemy.Gold; } else { PrintDesign.WriteLineInGreen($"You search dead {enemy.Name} and find {enemy.Gold} gold, and {loot} (worth: {lootValue} coins)."); player.Gold += enemy.Gold; do { Console.WriteLine($"Do you want to pick up {loot}? Y/N"); answer = Console.ReadLine().ToLower().Replace(" ", ""); if (answer == "y") { Console.Clear(); if (Player.backpack.ContainsKey(loot)) { PrintDesign.WriteLineInRed("You already own this item!"); } else { Player.backpack.Add(loot, lootValue); PrintDesign.WriteLineInGreen($"{loot} added to backpack!"); } } if (answer != "y" && answer != "n") { Console.Clear(); PrintDesign.WriteLineInRed("Invalid input! Try again."); } } while (answer != "y" && answer != "n"); } }
public static void StartFight(PlayerModel player, EnemyModel enemy) { Console.Clear(); int expToGive = enemy.Exp; Console.WriteLine($"{player.Name} VS {enemy.Name}"); Console.WriteLine(); while (true) { Console.WriteLine($"{player.Name} health: {player.Health}"); Console.WriteLine($"{enemy.Name} health: {enemy.Health}\n"); if (GetAttackResult(player, enemy) == "Fight Over") // skickar in spelaren först (dvs spelaren attackerar) returneras stringen Fight Over så ges exp och loot. { Console.Clear(); player.GainExp(expToGive); PrintDesign.WriteLineInGreen($"\nYou won the fight! you gain {expToGive} Exp"); if (player.Level >= 10) { Program.WonGame(); } GetLoot(enemy, player); enemy.Health = 100; // full health inför varje ny fight. player.Health = 100; if (player.FightClass == "warrior") { player.Health = 102; } break; } Console.WriteLine($"{player.Name} health: {player.Health}"); Console.WriteLine($"{enemy.Name} health: {enemy.Health}\n"); if (GetAttackResult(enemy, player) == "Fight Over") // skickar in fienden först (dvs fienden attackerar) { Console.Clear(); PrintDesign.WriteLineInRed("\nYou lost!"); Program.Exit(); break; } } }
public void ShopMenu(Player customer) { int choice; bool parseSuccessfull; Console.Clear(); PrintDesign.WriteLineInYellow("Welcome to the shop!"); do { PrintDesign.WriteLineInYellow("1. Show weapons for sale"); PrintDesign.WriteLineInYellow("2. Show armor for sale"); PrintDesign.WriteLineInYellow("3. Show special items for sale"); PrintDesign.WriteLineInYellow("4. Sell items"); PrintDesign.WriteLineInYellow("5. Back to main menu"); parseSuccessfull = int.TryParse(Console.ReadLine(), out choice); if (parseSuccessfull == false) { Console.Clear(); PrintDesign.WriteLineInRed("Something went wrong! Try again."); } if (choice > 5) { Console.Clear(); PrintDesign.WriteLineInRed("Number to high, choose a number between 1 and 5."); } else if (choice <= 0) { Console.Clear(); PrintDesign.WriteLineInRed("Number to low, choose a number between 1 and 5."); } MenuAction(choice, customer); } while (choice != 5); Console.ForegroundColor = ConsoleColor.White; }
public static void MainMenu(Player player) { int userChoice; bool parseSuccessful; do { Console.WriteLine("\nSelect an action from the menu: "); Console.WriteLine($"1. take {player.Name} adventuring"); Console.WriteLine($"2. show details about {player.Name}"); Console.WriteLine("3. Open backpack"); Console.WriteLine("4. Visit shop"); PrintDesign.WriteLineInRed("5. Play with GodMode"); PrintDesign.WriteLineInRed("6. Exit game"); Console.Write("\nChoice: "); parseSuccessful = int.TryParse(Console.ReadLine(), out userChoice); if (userChoice <= 0) { Console.Clear(); PrintDesign.WriteLineInRed("Chosen number to small, pick a number between 1 and 4 in the menu"); } else if (userChoice > 4) { Console.Clear(); PrintDesign.WriteLineInRed("Chosen number to big, pick a number between 1 and 4 in the menu"); } else if (parseSuccessful == false) // denna behövs egentligen inte då ints default är 0, men varför inte :) { Console.Clear(); PrintDesign.WriteLineInRed("Something went wrong with your input. Pick a number between 1 and 4 in the menu"); } MenuAction(userChoice); } while (userChoice < 0 || userChoice > 6 || parseSuccessful == false); }
private static void NameCharacter(string classOfCharacter) { string characterName; Console.WriteLine("Pick a name for your character:(max 25 characters)"); do { Console.Write("Character name: "); characterName = Console.ReadLine(); if (characterName.Length > 25) { Console.Clear(); PrintDesign.WriteLineInRed("Name contains to many characters\n"); } else if (!characterName.Any(char.IsLetter)) { Console.Clear(); PrintDesign.WriteLineInRed("Name must contain at least one letter!\n"); } } while (characterName.Length > 25 || !characterName.Any(char.IsLetter)); Console.Clear(); InitiliazePlayer(characterName, classOfCharacter); }
public static void Exit() { Console.Clear(); PrintDesign.WriteLineInGreen("Thank you for playing! See you next time"); Environment.Exit(0); }
public void PlayerInfo() { Console.Clear(); PrintDesign.PrintFrameWithPlayerInfo(Name, Level, FightClass, Health, MaxDmg, MaxBlock, Weapon, Armor, SpecialItem, ExpLeftUntilLevelUp, Gold); }
private void SpecialItemsAvaliableForSell(Player customer) { var listOfItemNames = specialItemsToSell.Keys.ToList(); // hämmtar namnet på special item till salu var listOfItemPrices = specialItemsToSell.Values.ToList(); // hämtar värdet på special item till salu. int choice; bool parseSuccessfull; do { PrintDesign.WriteLineInGreen($"\nGold in wallet: {customer.Gold}"); PrintDesign.PrintShop(specialItemsToSell); Console.Write("Number: "); parseSuccessfull = int.TryParse(Console.ReadLine(), out choice); if (choice < 0) { PrintDesign.WriteLineInRed("Chosen number to small!"); } else if (parseSuccessfull == false) { PrintDesign.WriteLineInRed("Something went wrong!"); } else if (choice > 4) { PrintDesign.WriteLineInRed("Chosen number to high!"); } } while (choice >= 4 || choice <= 0 || parseSuccessfull == false); if (listOfItemPrices[choice - 1] > customer.Gold) { Console.Clear(); PrintDesign.WriteLineInRed($"You dont have enough money to buy {listOfItemNames[choice - 1]}!"); } else if (customer.SpecialItem == listOfItemNames[choice - 1]) { Console.Clear(); PrintDesign.WriteLineInRed($"You already own {listOfItemNames[choice - 1]}!"); } else { Console.Clear(); PrintDesign.WriteLineInGreen($"\n{listOfItemNames[choice - 1]} bought and equipped!"); customer.SpecialItem = listOfItemNames[choice - 1]; // adderar special item till spelaren customer.Gold -= listOfItemPrices[choice - 1]; // tar bort det antal guld från spelaren som den köpta varan kostar. if (choice == 1) { customer.Health -= ExtraHealthFromItems; ExtraHealthFromItems = 1; customer.Health += ExtraHealthFromItems; } if (choice == 2) { customer.Health -= ExtraHealthFromItems; ExtraHealthFromItems = 2; customer.Health += ExtraHealthFromItems; } if (choice == 3) { customer.Health -= ExtraHealthFromItems; ExtraHealthFromItems = 3; customer.Health += ExtraHealthFromItems; } } }
private void ArmorsAvaliableForSell(Player customer) { var listOfArmorNames = armorsToSell.Keys.ToList(); var listOfArmorPrices = armorsToSell.Values.ToList(); int choice; bool parseSuccessfull; do { ; PrintDesign.WriteLineInGreen($"\nGold in wallet: {customer.Gold}"); PrintDesign.PrintShop(armorsToSell); Console.Write("Number: "); parseSuccessfull = int.TryParse(Console.ReadLine(), out choice); if (choice <= 0) { Console.Clear(); PrintDesign.WriteLineInRed("Chosen number to small!"); } else if (parseSuccessfull == false) { Console.Clear(); PrintDesign.WriteLineInRed("Something went wrong!"); } else if (choice >= 4) { Console.Clear(); PrintDesign.WriteLineInRed("Chosen number to high!"); } } while (choice >= 4 || choice <= 0 || parseSuccessfull == false); if (listOfArmorPrices[choice - 1] > customer.Gold) { Console.Clear(); PrintDesign.WriteLineInRed($"You dont have enough money to buy {listOfArmorNames[choice - 1]}!"); } else if (customer.Armor.Contains(listOfArmorNames[choice - 1])) { Console.Clear(); PrintDesign.WriteLineInRed($"You already {listOfArmorNames[choice - 1]}!"); } else { PrintDesign.WriteLineInGreen($"\n{listOfArmorNames[choice - 1]} bought and equipped!"); customer.Armor = listOfArmorNames[choice - 1]; customer.Gold -= listOfArmorPrices[choice - 1]; if (choice == 1) { customer.MaxBlock -= ExtraDefenceFromArmor; // tar bort nuvarande bonusen från armor ExtraDefenceFromArmor = 3; customer.MaxBlock += ExtraDefenceFromArmor; // addrar bonusen från den nyköpta armor } if (choice == 2) { customer.MaxBlock -= ExtraDefenceFromArmor; ExtraDefenceFromArmor = 5; customer.MaxBlock += ExtraDefenceFromArmor; } if (choice == 3) { customer.MaxBlock -= ExtraDefenceFromArmor; ExtraDefenceFromArmor = 7; customer.MaxBlock += ExtraDefenceFromArmor; } } }
private void WeaponAvailableForSell(Player customer) { var listOfWeaponNames = weaponsToSell.Keys.ToList(); var listOfWeaponPrices = weaponsToSell.Values.ToList(); int choice; bool parseSuccessfull; Console.Clear(); Console.WriteLine($"Weapons avaliable for the {customer.FightClass}:"); do { PrintDesign.WriteLineInGreen($"\nGold in wallet: {customer.Gold}"); PrintDesign.PrintShop(weaponsToSell); Console.Write("Number: "); parseSuccessfull = int.TryParse(Console.ReadLine(), out choice); if (choice <= 0) { Console.Clear(); PrintDesign.WriteLineInRed("Chosen number to small!"); } else if (parseSuccessfull == false) { Console.Clear(); PrintDesign.WriteLineInRed("Something went wrong!"); } else if (choice >= 4) { Console.Clear(); PrintDesign.WriteLineInRed("Chosen number to high!"); } } while (choice >= 4 || choice <= 0 || parseSuccessfull == false); if (listOfWeaponPrices[choice - 1] > customer.Gold) { Console.Clear(); PrintDesign.WriteLineInRed($"You dont have enough money to buy {listOfWeaponNames[choice - 1]}!"); } else if (customer.Weapon == listOfWeaponNames[choice - 1]) { Console.Clear(); PrintDesign.WriteLineInRed($"You already own {listOfWeaponNames[choice - 1]}!"); } else { Console.Clear(); PrintDesign.WriteLineInGreen($"\n{listOfWeaponNames[choice - 1]} bought and equipped!"); customer.Weapon = listOfWeaponNames[choice - 1]; customer.Gold -= listOfWeaponPrices[choice - 1]; if (choice == 1) { customer.MaxDmg -= ExtraDamageFromWeapons; ExtraDamageFromWeapons = 3; customer.MaxDmg += ExtraDamageFromWeapons; } if (choice == 2) { customer.MaxDmg -= ExtraDamageFromWeapons; ExtraDamageFromWeapons = 5; customer.MaxDmg += ExtraDamageFromWeapons; } if (choice == 3) { customer.MaxDmg -= ExtraDamageFromWeapons; ExtraDamageFromWeapons = 7; customer.MaxDmg += ExtraDamageFromWeapons; } } }