Exemplo n.º 1
0
        private void ParseInput(string cmd)
        {
            Variables.cmdCount++;

            // if any BeforeCommand present, then use it
            HandleResult res = (CArea != null) ?
                               CArea.BeforeCommand(CArea, Variables, cmd) : HandleResult.Continue;

            if (res != HandleResult.Continue)
            {
                return;
            }
            res = CRoom.BeforeCommand(CRoom, Variables, cmd);
            if (res != HandleResult.Continue)
            {
                return;
            }

            // as direction ...
            Direction?dir = null;

            if (cmd == "上" || cmd == "上去" || cmd == "上楼")
            {
                dir = Direction.Up;
            }
            else if (cmd == "下" || cmd == "下去" || cmd == "下楼")
            {
                dir = Direction.Down;
            }
            else
            {
                string[] dirs = new[] { "东", "南", "西", "北", "东北", "西北", "东南", "西南" };
                for (int i = 0; i < 8; i++)
                {
                    if (dirs[i] == cmd)
                    {
                        dir = (Direction)i;
                    }
                }
            }
            if (dir != null)
            {
                if (!GoDirection((Direction)dir))
                {
                    return;
                }
                // only look at PostCommand if succeeded
                res = (CArea != null) ?
                      CArea.PostCommand(CArea, Variables, cmd) : HandleResult.Continue;
                if (res != HandleResult.Continue)
                {
                    return;
                }
                CRoom.PostCommand(CRoom, Variables, cmd);
                return;
            }

            // as command ...
            foreach (var x in SingleObjVerbs)
            {
                // FIXME: what System.StringComparison should be used?
                if (cmd.StartsWith(x.Key, System.StringComparison.Ordinal))
                {
                    x.Value.Invoke(cmd.Substring(x.Key.Length));

                    res = (CArea != null) ?
                          CArea.PostCommand(CArea, Variables, cmd) : HandleResult.Continue;
                    if (res != HandleResult.Continue)
                    {
                        return;
                    }
                    res = CRoom.PostCommand(CRoom, Variables, cmd);
                    if (res != HandleResult.Continue)
                    {
                        return;
                    }
                    return;
                }
            }

            Print("我不理解这个,请尝试不同的表达方法。\n\n");
        }