Exemple #1
0
        private static void detectCommand(string command)
        {
            int whiteSpaces = countSpaces(command);

            switch (whiteSpaces)
            {
            case 0:
                //Movement
                Robot activeRobot = RobotRepository.getInstance().Get().First(r => r.isActive());
                IEnumerable <IMovement> robotAMovements = MovementParser.Parse(command);
                robotAMovements.ForEach(x => x.ExecuteOn(activeRobot));

                Console.WriteLine("{0} {1} {2}", activeRobot.getCoordinate().getX(), activeRobot.getCoordinate().getY(), activeRobot.getDirection());

                break;

            case 1:
                //Arena
                Arena arena = ArenaParser.Parse(command);
                Console.WriteLine(String.Format("Added new Arena: x - {0}, y - {1}", arena.getWidth(), arena.getHeight()));
                ArenaRepository.getInstance().Add(ArenaParser.Parse(command));
                break;

            case 2:
                //Robot
                RobotRepository.getInstance().Add(new RobotCoordinateParser().Parse(command));
                break;

            default:
                throw new Exception();
            }
        }
        public bool Execute(IGameEntity entity, string verb, string phrase)
        {
            Validation.IsNotNull(entity, "entity");
            Validation.IsNotNullOrEmpty(verb, "verb");

            if (!string.IsNullOrEmpty(phrase))
            {
                phrase = phrase.Trim('\'');
            }

            verb = verb.Replace(Environment.NewLine, string.Empty);

            var tuple = CommandManager.CommandRepository.Get(verb);

            if (tuple != null)
            {
                return(ExecuteVerb(tuple, entity, phrase));
            }

            var channel =
                CommandManager.GetParser("Channel").CastAs <PlayerChannelParser>().CheckChannelHandle(
                    entity as ICharacter, verb);

            if (channel != null)
            {
                channel.SendText(entity as ICharacter, phrase);
                return(true);
            }

            var social = CommandManager.GetParser("Social").CastAs <SocialCommandParser>().GetSocial(entity as IBiota,
                                                                                                     verb);

            if (social != null)
            {
                CommandManager.GetParser("Social").CastAs <SocialCommandParser>().ParseSocial(entity as IBiota, social,
                                                                                              phrase);
                return(true);
            }

            if (MovementParser.CheckMovementCommands(entity as IBiota, verb))
            {
                // TODO: How to handle a movement command

                /*var moveCmd = GetCommand("move");
                 * var args = PopulateCommandArgs(oUser.Characters.Character, null, null, verb, true);
                 * moveCmd.Execute(args);*/
                return(true);
            }

            Report(Globals.MessageScopeTypes.Character, Resources.MSG_NOT_UNDERSTAND, entity);
            return(false);
        }