private void setCommandEvents() { foreach (var command in Commands.Where(c => c is INavigationCommand)) { command.Action = () => { Navigated?.Invoke(this, new NavigationEventArgs(this, (command as NavigationCommand).Direction)); }; } foreach (var command in Commands.Where(c => c is IGameCommand)) { command.Action = () => { GameMenuSelected?.Invoke(this, new GameEventArgs(this, command.Keys)); }; } foreach (var command in Commands.Where(c => c is IAttackCommand)) { command.Action = () => { Attacked?.Invoke(this, new AttackEventArgs(this)); }; } }
protected virtual void display() { UserInterface.Clear(); UserInterface.Display(""); UserInterface.Display(Title); UserInterface.Display(new String('-', Title.Length)); UserInterface.Display(Description); var monsters = GetItems("Monsters"); if (monsters.Count > 0) { var zombieCount = monsters.Count(m => m.Name == "Zombie"); var orcCount = monsters.Count(m => m.Name == "Orc"); var trollCount = monsters.Count(m => m.Name == "Troll"); var dragonCount = monsters.Count(m => m.Name == "Dragon"); var zombieText = zombieCount > 0 ? zombieCount > 1 ? $"{zombieCount} zombies" : "1 zombie" : ""; var orcText = orcCount > 0 ? orcCount > 1 ? $"{orcCount} orcs" : "1 orc" : ""; var trollText = trollCount > 0 ? trollCount > 1 ? $"{trollCount} trolls" : "1 troll" : ""; var dragonText = dragonCount > 0 ? dragonCount > 1 ? $"{dragonCount} dragons" : "1 dragon" : ""; var monsterText = zombieText; monsterText += orcText.Length > 0 ? monsterText.Length > 0 ? $" and {orcText}" : orcText : ""; monsterText += trollText.Length > 0 ? monsterText.Length > 0 ? $" and {trollText}" : trollText : ""; monsterText += dragonText.Length > 0 ? monsterText.Length > 0 ? $" and {dragonText}" : dragonText : ""; var isAre = monsters.Count > 1 ? "are" : "is"; UserInterface.Display($"There {isAre} {monsterText} in the room."); } else { Commands = Commands.Where(c => !(c is IAttackCommand)).ToList(); } var treasures = GetItems("Treasures"); var pickUpCommand = Commands.FirstOrDefault(c => c.Keys.ToLower() == "p"); if (treasures.Count > 0 && monsters.Count == 0) { var treasureText = ""; foreach (var item in treasures) { var treasure = (ITreasure)item; treasureText += $"{treasure.Name} ({treasure.Value})\n"; } UserInterface.Display($"The room contains the following treasure:\n{treasureText}"); if (pickUpCommand == null) { pickUpCommand = new AttackCommand { Keys = "P", Description = "Pickup Treasure" }; pickUpCommand.Action = () => { GameMenuSelected?.Invoke(this, new GameEventArgs(this, pickUpCommand.Keys)); }; Commands.Add(pickUpCommand); } } else { if (pickUpCommand != null) { Commands = Commands.Where(c => c.Keys.ToLower() != "p").ToList(); } } if (!String.IsNullOrEmpty(Feedback)) { UserInterface.Display(""); UserInterface.Display(Feedback); Feedback = ""; } UserInterface.Display(""); UserInterface.Display($"Your health: {player.Health}"); var playerTreasure = player.GetItems("Treasures"); var playerTreasureText = ""; if (playerTreasure.Count > 0) { foreach (var item in playerTreasure) { var treasure = (ITreasure)item; playerTreasureText += $"{treasure.Name}({treasure.Value})\n"; } UserInterface.Display($"Your Treasures:\n\n{playerTreasureText}"); } UserInterface.Display(""); UserInterface.Display("Actions"); UserInterface.Display(new String('-', "Actions".Length)); if (Commands != null && Commands.Count > 0) { foreach (var command in Commands.OrderBy(c => c.Keys)) { UserInterface.Display($"{command.Keys} = {command.Description}"); } } UserInterface.Display(""); }