public void GUI(Command command) { Console.WriteLine("What would you like to do next? \n1) Move to a node. \n2) Use a healing potion. \n3) Do nothing."); char info = UI.ReadKey(); Console.WriteLine(""); int choice; switch (info) { case '1': // display neighbour nodes DisplayPaths(player); info = UI.ReadKey(); Console.WriteLine(); choice = int.Parse(info.ToString()); Node destination = player.location.neighbors[choice - 1]; // Using 1-9, not 0-9 command.Move(player, destination); break; case '2': // display inventory int bag = player.DisplayInventory(); Console.WriteLine("1) Use Healingpotion."); info = UI.ReadKey(); Console.WriteLine(); choice = int.Parse(info.ToString()); if (choice == 1 && (bag == 1 || bag == 3)) // use command item { command.UseItem(player, choice); } else if (choice != 1 && choice != 2) { Console.WriteLine("Wrong input."); goto case '2'; // Repeating } else { Console.WriteLine("You have no potions in your inventory."); Console.WriteLine("1) Move to a node. \n2) Do nothing."); choice = int.Parse(UI.ReadKey().ToString()); Console.WriteLine(); if (choice == 1) { goto case '1'; } else if (choice == 2) { goto case '3'; } else { goto default; } } break; case '3': command.DoNothing(player, player.location); break; case 'x': // previous menu always break; default: command.DoNothing(player, player.location); break; } }
/* Execute a fight between the player and the packs in this node. * Such a fight can take multiple rounds as describe in the Project Document. * A fight terminates when either the node has no more monster-pack, or when * the player's HP is reduced to 0. */ public void fight(Player player, Command commands) { while (player.location == this && packs.Count != 0) // Contested { Dungeon.alert = player.level; foreach (Pack pack in packs) { pack.fled = false; } // Choice Console.WriteLine("A foe stands infront of you!"); Console.WriteLine("You have {0} health.", player.HP); Console.WriteLine("1) Flee. \n2) Use item in your inventory and attack. \n3) Attack a monster."); // Flee, item > attack, attack char c = UI.ReadKey(); int choice = int.Parse(c.ToString()); switch (choice) { // Flee case 1: // Choice Game.DisplayPaths(player); choice = int.Parse(UI.ReadKey().ToString()); Node destination = neighbors[choice - 1]; commands.Move(player, destination); break; // Use item case 2: // Choice int bag = player.DisplayInventory(); Console.WriteLine("1) Healingpotion \n2) Crystal"); choice = int.Parse(UI.ReadKey().ToString()); if (choice == 1 && (bag == 1 || bag == 3)) { commands.UseItem(player, choice); } else if (choice == 2 && (bag == 2 || bag == 3)) { player.crystalUsed = true; commands.UseItem(player, choice); } else if (choice != 1 && choice != 2) { Console.WriteLine("Wrong input."); goto case 2; // Repeater } else // No items in inventory { Console.WriteLine("You don't have the item in your inventory!"); Console.WriteLine("1) Flee \n2) Attack"); choice = int.Parse(UI.ReadKey().ToString()); if (choice == 1) { goto case 1; } } goto case 3; // Continue to Attack // Attack case 3: // GUI Monster choice Console.WriteLine("Choose the pack and monster you want to attack."); Game.DisplayPacks(packs); int pack_choice = int.Parse(UI.ReadKey().ToString()) - 1; // 0 indexed Game.DisplayMonsters(packs[pack_choice].members); int monster_choice = int.Parse(UI.ReadKey().ToString()) - 1; Monster monster = packs[pack_choice].members[monster_choice]; commands.AttackMonster(player, monster); if (packs[pack_choice].members.Count == 0) // Pack died { packs.RemoveAt(pack_choice); } if (packs.Count != 0) // Monster Turn; Still Contested { int rand_pack = RandomGenerator.rnd.Next(packs.Count); Pack selectedpack = packs[rand_pack]; int HP = 0; int totalHP = 0; foreach (Monster monst in packs[rand_pack].members) { HP += monst.HP; totalHP += monst.totalHP; } double flee_chance = (1 - HP / totalHP) / 2; bool flee = RandomGenerator.rnd.NextDouble() < flee_chance; if (flee) // Fleeing { bool fled = false; int tried = 0; List <Node> temp_neighbours = new List <Node>(neighbors); // while (!fled && tried != neighbors.Count) // Randomly chooses neighbours and tries to move { int rand_neighbour = RandomGenerator.rnd.Next(temp_neighbours.Count); if (Game.RZone(packs[rand_pack], temp_neighbours[rand_neighbour])) // Check to stay in zone { fled = packs[rand_pack].move(temp_neighbours[rand_neighbour]); } temp_neighbours.RemoveAt(rand_neighbour); tried++; } // fled pack set to true if (fled) { selectedpack.fled = true; } if (!fled) // Not succesfully fled { packs[rand_pack].Attack(player); } else { if (packs.Count != 0) // Still contested { rand_pack = RandomGenerator.rnd.Next(packs.Count); packs[rand_pack].Attack(player); } } } else // Originally not fleeing { packs[rand_pack].Attack(player); } } break; } } }