예제 #1
0
        public bool ReceiveAnswer(string answer, ref string help)
        {
            Room currentRoom = GetCurrentRoom();

            help = "";

            if (currentRoom != null)
            {
                List <GraphTransition> outGoingTransitions = currentRoom.GetOutgoingTransitions();

                foreach (GraphTransition currentTransition in outGoingTransitions)
                {
                    if (!IsTransitionEventReady(currentTransition))
                    {
                        continue;
                    }
                    if (currentTransition.GetTransitionType() == TRANSITION_TYPE.SOLUTION_TYPE)
                    {
                        SolutionTransition currentSolutionTransition = (SolutionTransition)currentTransition;

                        List <string> solutions = currentSolutionTransition.GetSolutions();

                        var wrongAnswers = currentSolutionTransition.GetWrongAnswerToHelp();

                        foreach (KeyValuePair <string, string> wrongAnswerToHelp in wrongAnswers)
                        {
                            if (string.Equals(wrongAnswerToHelp.Key, answer, System.StringComparison.CurrentCultureIgnoreCase))
                            {
                                help = wrongAnswerToHelp.Value;
                                return(false);
                            }
                        }

                        foreach (string currentSolution in solutions)
                        {
                            //	if (currentSolution == answer) {
                            if (string.Equals(currentSolution, answer, System.StringComparison.CurrentCultureIgnoreCase))
                            {
                                FireTransition(currentTransition);
                                m_roomChangeShouldBeImmediate = currentSolutionTransition.IsImmediate();
                                return(true);
                            }
                        }

                        if (wrongAnswers.ContainsKey("__default__"))
                        {
                            help = wrongAnswers["__default__"];
                            return(false);
                        }
                    }
                }
            }

            return(false);
        }
예제 #2
0
        public int CreateSolutionTransition(int roomIDFrom, int roomIDTo, string question, List <string> solutions, Dictionary <string, string> wrongAnswers, bool isPassword, bool isImmediate, bool isUnique)
        {
            if (roomIDFrom >= m_rooms.Count || roomIDTo >= m_rooms.Count)
            {
                return(-1);
            }

            SolutionTransition transitionToAdd = new SolutionTransition(m_rooms[roomIDFrom], m_rooms[roomIDTo], question, solutions, wrongAnswers, isPassword, isImmediate, isUnique);

            transitionToAdd.SetTransitionID(m_transitions.Count);

            m_transitions.Add(transitionToAdd);

            return(transitionToAdd.GetTransitionID());
        }