static void Main(string[] args) { // General initializations to prevent magic numbers int mapwidth = 13; int mapheight = 13; int ystartpos = 2; int xstartpos = 2; // Welcome the player Console.WriteLine("Welcome to a textbased adventure"); Console.WriteLine("Before you can start your journey, you will have to enter your name."); string name = null; string input = null; // Check for the correct name // Refactored from do - while to improve readability by Michiel and Alex while (input != "Y") { if (input == null || input == "N") { do { Console.WriteLine("Please enter your name and press enter:"); name = Console.ReadLine(); }while (name == ""); } Console.WriteLine("Your name is {0}", name); Console.WriteLine("Is this correct? (y/n)"); input = Console.ReadLine(); input = input.ToUpper(); } // Make the player and monsters Player player = new Player(name, 100, 1, 1); Bandit bandit = new Bandit("Bandit"); Spider spider = new Spider("Giant spider"); Skeleton skeleton = new Skeleton("Skeleton"); Skeleton1 skeleton1 = new Skeleton1("Skeleton"); Skeleton2 skeleton2 = new Skeleton2("Skeleton"); Kraken kraken = new Kraken("Kraken"); Bchief bchief = new Bchief("Bandit chief"); DwarfKing dking = new DwarfKing("Ðurin"); Zealot zealot = new Zealot("Zealot"); Troll troll = new Troll("Troll"); Snake snake = new Snake("Snake"); //Welcome the player Welcome(ref player); // Initialize the map Map map = new Map(mapwidth, mapheight, xstartpos, ystartpos, ref player); // Put the locations with their items on the map InitMap(ref map); // Start the game Start(ref map, ref player, ref bandit, ref spider, ref skeleton, ref skeleton1, ref skeleton2, ref kraken, ref bchief, ref dking, ref zealot, ref troll, ref snake); // End the program Quit(); }
static void Start(ref Map map, ref Player player, ref Bandit bandit, ref Spider spider, ref Skeleton skeleton, ref Skeleton1 skeleton1, ref Skeleton2 skeleton2, ref Kraken kraken, ref Bchief bchief, ref DwarfKing dking, ref Zealot zealot, ref Troll troll, ref Snake snake) { List <string> menuItems = new List <string>(); int choice; // Refactored by Michiel and Alex do { Console.Clear(); map.GetLocation().Description(); choice = ShowMenu(map, ref menuItems, ref player); if (choice != menuItems.Count()) { if (validDirections.Contains(menuItems[choice])) { map.Move(menuItems[choice]); } switch (menuItems[choice]) { case ACTION_HEAL: player.HealPlayer(player); player.CheckHealth(player); break; case ACTION_TREASURE: Console.WriteLine("You return to Mana with your spoils and live a happy life"); Console.WriteLine("The game is now technically over, but feel free to wander around."); Console.WriteLine(""); Console.WriteLine("Thanks for playing!"); Console.WriteLine("Made by: Thom Martens, Kevin Rademacher and Bas Overvoorde"); Console.ReadKey(); break; case ACTION_STATS: player.ShowStats(player); Console.ReadKey(); break; case ACTION_INV: player.ShowInventory(); Console.ReadKey(); break; case ACTION_SEARCH: Console.Clear(); Dictionary <string, Objects> list = map.GetLocation().GetItems(); Objects[] obj = list.Values.ToArray(); for (int i = 0; i < obj.Count(); i++) { if (obj[i].GetAcquirable()) { player.PickupItem(obj[i]); } Console.ReadKey(); } player.HasStrBuff(player); player.HasArmBuff(player); break; case ACTION_FIGHT: map.GetLocation().hasEnemy = true; //church fight if (map.GetLocation().GetName() == "Church of Stendarr") { Console.WriteLine("You encounter a {0}!", zealot.GetName()); Console.WriteLine("Health:{0}/{1}", zealot.health, zealot.maxhealth); Console.WriteLine("Strenght:{0}", zealot.GetStr()); // Console.WriteLine("Thoughness: {0}", zealot.GetThough()); Console.WriteLine("Examine: {0}", zealot.Description()); Console.ReadKey(); if (zealot.health > 0) { Console.WriteLine("The {0} hits you with his sword!", zealot.GetName()); player.TakeHit(zealot.GetStr() - player.GetThough()); zealot.health = zealot.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", zealot.GetName()); Console.WriteLine("You deal {0} damage", player.GetStr()); if (zealot.health > 0) { Console.WriteLine("The {0} has {1} health left.", zealot.GetName(), zealot.health); } else if (zealot.health <= 0) { zealot.health = 0; Console.WriteLine("The {0} has {1} health left", zealot.GetName(), zealot.health); } Console.ReadKey(); } if (zealot.health <= 0) { Console.WriteLine("The {0} is dead.", zealot.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } if (map.GetLocation().GetName() == "Bog") { Console.WriteLine("You encounter a {0}!", snake.GetName()); Console.WriteLine("Health:{0}/{1}", snake.health, snake.maxhealth); Console.WriteLine("Strenght:{0}", snake.GetStr()); // Console.WriteLine("Thoughness: {0}", zealot.GetThough()); Console.WriteLine("Examine: {0}", snake.Description()); Console.ReadKey(); if (snake.health > 0) { Console.WriteLine("The {0} tries to bite you!", snake.GetName()); player.TakeHit(snake.GetStr() - player.GetThough()); snake.health = snake.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", snake.GetName()); Console.WriteLine("You deal {0} damage", player.GetStr()); if (snake.health > 0) { Console.WriteLine("The {0} has {1} health left.", snake.GetName(), snake.health); } else if (snake.health <= 0) { snake.health = 0; Console.WriteLine("The {0} has {1} health left", snake.GetName(), snake.health); } Console.ReadKey(); } if (snake.health <= 0) { Console.WriteLine("The {0} is dead.", snake.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } if (map.GetLocation().GetName() == "Dragonstar") { Console.WriteLine("You encounter a {0}!", bandit.GetName()); Console.WriteLine("Health:{0}/{1}", bandit.health, bandit.maxhealth); Console.WriteLine("Strenght:{0}", bandit.GetStr()); //Console.WriteLine("Thoughness: {0}", bandit.GetThough()); Console.WriteLine("Examine: {0}", bandit.Description()); Console.ReadKey(); if (bandit.health > 0) { Console.WriteLine("The {0} hits you with his sword!", bandit.GetName()); player.TakeHit(bandit.GetStr() - player.GetThough()); bandit.health = bandit.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", bandit.GetName()); if (bandit.health > 0) { Console.WriteLine("The {0} has {1} health left.", bandit.GetName(), bandit.health); } else if (bandit.health <= 0) { bandit.health = 0; Console.WriteLine("The {0} has {1} health left", bandit.GetName(), bandit.health); } Console.ReadKey(); } if (bandit.health <= 0) { Console.WriteLine("The {0} is dead.", bandit.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } //forest fight if (map.GetLocation().GetName() == "Woodhearth") { Console.WriteLine("You encounter a {0}!", spider.GetName()); Console.WriteLine("Health:{0}/{1}", spider.health, spider.maxhealth); Console.WriteLine("Strenght:{0}", spider.GetStr()); //Console.WriteLine("Thoughness: {0}", spider.GetThough()); Console.WriteLine("Examine: {0}", spider.Description()); Console.ReadKey(); if (spider.health > 0) { Console.WriteLine("The {0} hits you with his huge fangs!", spider.GetName()); player.TakeHit(spider.GetStr() - player.GetThough()); spider.health = spider.health - player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", spider.GetName()); if (spider.health > 0) { Console.WriteLine("The {0} has {1} health left.", spider.GetName(), spider.health); } else if (spider.health <= 0) { spider.health = 0; Console.WriteLine("The {0} has {1} health left", spider.GetName(), spider.health); } Console.ReadKey(); } if (spider.health <= 0) { spider.health = 0; Console.WriteLine("The {0} is dead.", spider.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } //tombroom fight if (map.GetLocation().GetName() == "Tombroom1") { Console.WriteLine("You encounter a {0}!", skeleton.GetName()); Console.WriteLine("Health:{0}/{1}", skeleton.health, skeleton.maxhealth); Console.WriteLine("Strenght:{0}", skeleton.GetStr()); //Console.WriteLine("Thoughness: {0}", skeleton.GetThough()); Console.WriteLine("Examine: {0}", skeleton.Description()); Console.ReadKey(); if (skeleton.health > 0) { Console.WriteLine("The {0} hits you with his Giant Axe!", skeleton.GetName()); player.TakeHit(skeleton.GetStr() - player.GetThough()); skeleton.health = skeleton.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", skeleton.GetName()); if (skeleton.health > 0) { Console.WriteLine("The {0} has {1} health left.", skeleton.GetName(), skeleton.health); } else if (skeleton.health <= 0) { skeleton.health = 0; Console.WriteLine("The {0} has {1} health left", skeleton.GetName(), skeleton.health); } Console.ReadKey(); } if (skeleton.health <= 0) { Console.WriteLine("The {0} is dead.", skeleton.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } //tombroom1 fight if (map.GetLocation().GetName() == "Tombroom2") { Console.WriteLine("You encounter a {0}!", skeleton1.GetName()); Console.WriteLine("Health:{0}/{1}", skeleton1.health, skeleton1.maxhealth); Console.WriteLine("Strenght:{0}", skeleton1.GetStr()); //Console.WriteLine("Thoughness: {0}", skeleton1.GetThough()); Console.WriteLine("Examine: {0}", skeleton1.Description()); Console.ReadKey(); if (skeleton1.health > 0) { Console.WriteLine("The {0} shoots at you with his bow!", skeleton1.GetName()); player.TakeHit(skeleton1.GetStr() - player.GetThough()); skeleton1.health = skeleton1.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", skeleton1.GetName()); if (skeleton1.health > 0) { Console.WriteLine("The {0} has {1} health left.", skeleton1.GetName(), skeleton1.health); } else if (skeleton1.health <= 0) { skeleton1.health = 0; Console.WriteLine("The {0} has {1} health left", skeleton1.GetName(), skeleton1.health); } Console.ReadKey(); } if (skeleton1.health <= 0) { Console.WriteLine("The {0} is dead.", skeleton1.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } //tombroom2 fight if (map.GetLocation().GetName() == "Tombroom3") { Console.WriteLine("You encounter a {0}!", skeleton2.GetName()); Console.WriteLine("Health:{0}/{1}", skeleton2.health, skeleton2.maxhealth); Console.WriteLine("Strenght:{0}", skeleton2.GetStr()); //Console.WriteLine("Thoughness: {0}", skeleton2.GetThough()); Console.WriteLine("Examine: {0}", skeleton2.Description()); Console.ReadKey(); if (skeleton2.health > 0) { Console.WriteLine("The {0} strikes you with his sword!", skeleton2.GetName()); player.TakeHit(skeleton2.GetStr() - player.GetThough()); skeleton2.health = skeleton2.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", skeleton2.GetName()); if (skeleton2.health > 0) { Console.WriteLine("The {0} has {1} health left.", skeleton2.GetName(), skeleton2.health); } else if (skeleton2.health <= 0) { skeleton2.health = 0; Console.WriteLine("The {0} has {1} health left", skeleton2.GetName(), skeleton2.health); } Console.ReadKey(); } if (skeleton2.health <= 0) { Console.WriteLine("The {0} is dead.", skeleton2.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } //tombroom 3 fight if (map.GetLocation().GetName() == "Tombroom4") { Console.WriteLine("You encounter a {0}!", skeleton.GetName()); Console.WriteLine("Health:{0}/{1}", skeleton.health, skeleton.maxhealth); Console.WriteLine("Strenght:{0}", skeleton.GetStr()); //Console.WriteLine("Thoughness: {0}", skeleton.GetThough()); Console.WriteLine("Examine: {0}", skeleton.Description()); Console.ReadKey(); if (skeleton.health > 0) { Console.WriteLine("The {0} hits you with his Giant Axe!", skeleton.GetName()); player.TakeHit(skeleton.GetStr() - player.GetThough()); skeleton.health = skeleton.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", skeleton.GetName()); if (skeleton.health > 0) { Console.WriteLine("The {0} has {1} health left.", skeleton.GetName(), skeleton.health); } else if (skeleton.health <= 0) { skeleton.health = 0; Console.WriteLine("The {0} has {1} health left", skeleton.GetName(), skeleton.health); } Console.ReadKey(); } if (skeleton.health <= 0) { Console.WriteLine("The {0} is dead.", skeleton.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } //troll fight if (map.GetLocation().GetName() == "The Hanger") { Console.WriteLine("You encounter a {0}!", troll.GetName()); Console.WriteLine("Health:{0}/{1}", troll.health, troll.maxhealth); Console.WriteLine("Strenght:{0}", troll.GetStr()); //Console.WriteLine("Thoughness: {0}", spider.GetThough()); Console.WriteLine("Examine: {0}", troll.Description()); Console.ReadKey(); if (troll.health > 0) { Console.WriteLine("The {0} hits you with his giant club!", troll.GetName()); player.TakeHit(troll.GetStr() - player.GetThough()); troll.health = troll.health - player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", troll.GetName()); if (troll.health > 0) { Console.WriteLine("The {0} has {1} health left.", troll.GetName(), troll.health); } else if (troll.health <= 0) { troll.health = 0; Console.WriteLine("The {0} has {1} health left", troll.GetName(), troll.health); } Console.ReadKey(); } if (troll.health <= 0) { troll.health = 0; Console.WriteLine("The {0} is dead.", troll.GetName()); map.GetLocation().hasEnemy = false; Console.ReadKey(); } } break; case ACTION_RUN: map.Run(); Console.WriteLine("You run away to {0}", map.GetLocation().GetName()); Console.ReadKey(); break; case ACTION_BOSS: map.GetLocation().hasBossEnemy = true; //kraken boss if (map.GetLocation().GetName() == "Black Lake") { Console.WriteLine("You encounter a {0}!", kraken.GetName()); Console.WriteLine("Health:{0}/{1}", kraken.health, kraken.maxhealth); Console.WriteLine("Strenght:{0}", kraken.GetStr()); //Console.WriteLine("Thoughness: {0}", kraken.GetThough()); Console.WriteLine("Examine: {0}", kraken.Description()); Console.ReadKey(); if (kraken.health > 0) { Console.WriteLine("The {0} strikes you with his tentacles!", kraken.GetName()); player.TakeHit(kraken.GetStr() - player.GetThough()); kraken.health = kraken.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", kraken.GetName()); if (kraken.health > 0) { Console.WriteLine("The {0} has {1} health left.", kraken.GetName(), kraken.health); } else if (kraken.health <= 0) { kraken.health = 0; Console.WriteLine("The {0} has {1} health left", kraken.GetName(), kraken.health); } Console.ReadKey(); } if (kraken.health <= 0) { Console.WriteLine("The {0} is dead.", kraken.GetName()); map.GetLocation().hasBossEnemy = false; Console.ReadKey(); } } //chief bandit if (map.GetLocation().GetName() == "Dragonstar armory") { Console.WriteLine("You encounter the {0}!", bchief.GetName()); Console.WriteLine("Health:{0}/{1}", bchief.health, bchief.maxhealth); Console.WriteLine("Strenght:{0}", bchief.GetStr()); //Console.WriteLine("Thoughness: {0}", bchief.GetThough()); Console.WriteLine("Examine: {0}", bchief.Description()); Console.ReadKey(); if (bchief.health > 0) { Console.WriteLine("The {0} strikes you with his basterdsword!", bchief.GetName()); player.TakeHit(bchief.GetStr() - player.GetThough()); bchief.health = bchief.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", bchief.GetName()); Console.WriteLine("The {0} has {1} health left.", bchief.GetName(), bchief.health); Console.ReadKey(); } if (bchief.health <= 0) { Console.WriteLine("The {0} is dead.", bchief.GetName()); map.GetLocation().hasBossEnemy = false; Console.ReadKey(); } } //dwarf king fight if (map.GetLocation().GetName() == "TombTreasureRoom") { Console.WriteLine("You encounter {0}!", dking.GetName()); Console.WriteLine("Health:{0}/{1}", dking.health, dking.maxhealth); Console.WriteLine("Strenght:{0}", dking.GetStr()); //Console.WriteLine("Thoughness: {0}", dking.GetThough()); Console.WriteLine("Examine: {0}", dking.Description()); Console.ReadKey(); if (dking.health > 0) { Console.WriteLine("The {0} strikes you with his Axe!", dking.GetName()); player.TakeHit(dking.GetStr() - player.GetThough()); dking.health = dking.health -= player.GetStr(); Console.WriteLine("You strike the {0} with your weapon.", dking.GetName()); Console.WriteLine("The {0} has {1} health left.", dking.GetName(), dking.health); Console.ReadKey(); } if (dking.health <= 0) { Console.WriteLine("The {0} is dead.", dking.GetName()); map.GetLocation().hasBossEnemy = false; Console.ReadKey(); } } break; case ACTION_INN: player.SetHealth(); Console.WriteLine("You have been healed!"); Console.ReadKey(); break; } } } // When the choice is equal to the total item it means exit has been chosen. while (choice < menuItems.Count() - 1); }