Пример #1
0
        /// <summary>
        /// Returns wether this command is executable in the given Game context
        /// </summary>
        public override ActionsPackState IsExecutable(Game game)
        {
            ActionsPackState state       = base.IsExecutable(game);
            Pirate           pirateOnMap = game.GetPirateOn(base.ImmediateDestination);

            // if the state is unstable, and the immediate destination is the drunk pirate, then we're stable
            if (state == ActionsPackState.Unstable && pirateOnMap != null && pirateOnMap == this.DrunkPirate)
            {
                return(ActionsPackState.Stable);
            }
            // else, return the normal state
            return(state);
        }
Пример #2
0
        /// <summary>
        /// Tries to add the given command to this ActionsPack, and returns wether the addition succeeded
        /// </summary>
        public bool AddCommand(Command cmd)
        {
            // cannot execute a null object
            if (cmd == null)
            {
                return(false);
            }

            ActionsPackState cmdState = cmd.IsExecutable(this.game);

            // if the command is not executable in the current context
            if (cmdState == ActionsPackState.NotPossible)
            {
                return(false);
            }

            ResourcesPack rp = cmd.CreateResourcesPack(this.game);

            // fatal error
            if (rp == null)
            {
                return(false);
            }

            // tries to add rp to the resources, but continue only if the addition succeeded (the two ResourcesPack do not overlap)
            if (!this.resourcesPack.AddResources(rp))
            {
                return(false);
            }

            // add the command
            // if the command is stable
            if (cmdState == ActionsPackState.Stable)
            {
                this.stableCommands.Add(cmd);
            }
            // else, the command is unstable
            else
            {
                this.unstableCommands.Add(cmd);
            }

            return(true);
        }