private IList <Interaction> GetRespondingInteractions(ActionVerb actionVerb) { var interactionsFilteredByType = _interactions.Where(p => p.Action.Verb == actionVerb).ToList(); if (!interactionsFilteredByType.Any()) { var invalidInteractions = _interactions.Where(p => p.Action.Verb == ActionVerb.BlanksOut).ToList(); return(invalidInteractions); } return(interactionsFilteredByType); }
public IList <ActionVerb> GetResponseVerbs(ActionVerb verb) { switch (verb) { case ActionVerb.Greet: return(new List <ActionVerb> { ActionVerb.GreetBack }); case ActionVerb.GetToKnow: return(new List <ActionVerb> { ActionVerb.Introduce }); case ActionVerb.RequestItemType: return(new List <ActionVerb> { ActionVerb.GiveItemType, ActionVerb.RefuseItemType, ActionVerb.DontHaveItemType }); default: return(new List <ActionVerb>()); } }
static void Main(string[] args) { RandomSeedGenerator.InitializeRandom(4); IGameDataReader gameDataReader = new GameDataJsonFileReader(new ActionParser(), new List <string> { "Data" }); var interactionGenerator = new InteractionGenerator( gameDataReader.GetInteractions().ToList(), new CriteriaParser(), new StringTemplateReplacer()); Character player = CreatePlayer(interactionGenerator); Character npc = CreateNpc(interactionGenerator); string npcResponse = "You are standing in front of a villager. She is standing there, looking bored."; WriteResponse(npcResponse); char playerInput = AskInput(); while (playerInput != 'e' && playerInput != 'q') { if (playerInput == 'h') { WriteResponse(@"Press the numbers to choose an interaction. e - exit. h - help. m - info about you. q - exit. y - info about the one you're talking to.", npcResponse); playerInput = AskInput(); continue; } if (playerInput == 'm') { WriteResponse($"You are:\n{player}", npcResponse); playerInput = AskInput(); continue; } if (playerInput == 'y') { WriteResponse($"The one you are speaking to is:\n{npc}", npcResponse); playerInput = AskInput(); continue; } int playerChoice = 0; var interactionTypeMaxValue = (int)Enum.GetValues(typeof(ActionVerb)).Cast <ActionVerb>().Last(); bool isGood = int.TryParse(playerInput.ToString(), out playerChoice); isGood = isGood && playerChoice > 0 && playerChoice <= interactionTypeMaxValue; if (isGood) { ActionVerb playerChoiceType = (ActionVerb)playerChoice; string objectText = string.Empty; if (playerChoiceType == ActionVerb.RequestItemType) { objectText = "Sword"; } var interaction = interactionGenerator.GetInteraction( player, new ParsedAction { Adverb = ActionAdverb.Neutrally, Verb = playerChoiceType }, npc); if (interaction != null) { interaction.Action.Object = objectText; var interactionResult = player.InteractWith(interaction, npc); if (interactionResult != null) { npcResponse = $"{interactionResult.BodyLanguage}\n\n{npc.Name}: {interactionResult.Dialogue}"; } else { npcResponse = GetInvalidResponse(interactionGenerator, player, npc); } } else { npcResponse = GetInvalidResponse(interactionGenerator, player, npc); } } else { npcResponse = GetInvalidResponse(interactionGenerator, player, npc); } WriteResponse(npcResponse); playerInput = AskInput(); } }