Beispiel #1
0
        /// <summary>
        /// Creates a new ActionsPack, which will be based on the ActionsPack given
        /// </summary>
        public ActionsPack(ActionsPack other)
        {
            this.resourcesPack    = new ResourcesPack(other.resourcesPack);
            this.stableCommands   = new List <Command>(other.stableCommands);
            this.unstableCommands = new List <Command>(other.unstableCommands);

            this.game = other.game;
        }
Beispiel #2
0
        //////////Methods//////////

        /// <summary>
        /// Creates a new ActionsPack, which will be executed by the given Game
        /// </summary>
        public ActionsPack(Game game)
        {
            this.resourcesPack    = new ResourcesPack(game);
            this.stableCommands   = new List <Command>();
            this.unstableCommands = new List <Command>();

            this.game = game;
        }
Beispiel #3
0
        /// <summary>
        /// Returns a new ResourcesPack, that contains the necessary resources for the command to run,
        ///     or null if the command cannot be executed in the current context.
        /// </summary>
        public override ResourcesPack CreateResourcesPack(Game game)
        {
            ResourcesPack rp = new ResourcesPack(game);

            bool success = rp.AddMyPirate(this.Pirate);

            success &= rp.AddTakenLocation(this.Pirate);

            // if the addition of the resources was not successful
            if (!success)
            {
                return(null);
            }
            // else, rp is ready!
            return(rp);
        }
Beispiel #4
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);
        }
Beispiel #5
0
 /// <summary>
 /// Returns wether the presence of the given ResourcesPack stabilizes this command.
 /// </summary>
 public override bool IsStabilized(ResourcesPack resourcesPack)
 {
     // will stabilize if the destination will be freed
     return(resourcesPack.IsFreed(this.ImmediateDestination));
 }
Beispiel #6
0
 /// <summary>
 /// Returns wether the presence of the given ResourcesPack stabilizes this command.
 /// Should be overrided in possibly-unstable commands.
 /// </summary>
 public virtual bool IsStabilized(ResourcesPack resourcesPack)
 {
     return(false); // won't stabilize ever
 }