Exemple #1
0
        /// <summary>
        ///  <para>
        ///   Use this function to command your creature to reproduce.  There are many
        ///   conditions on whether your creature can reproduce.  If these conditions
        ///   are not met, an exception will be thrown.  The easiest way to make
        ///   sure all pre-existing conditions have been met is to check the CanReproduce
        ///   property.
        ///  </para>
        ///  <para>
        ///   If you call this method multiple times in the same turn, then the last call
        ///   will be used, and all previous calls will be ignored.  This method is also
        ///   asynchronous, and a ReproduceCompletedEvent will be fired when your creature
        ///   has actually given birth.  The time between start and completion is 10 ticks.
        ///  </para>
        /// </summary>
        /// <param name="dna">
        ///  A byte array that gets passed to the child.  This can be any information you
        ///  want to pass to the child creature.  The byte array is truncated at 8000 bytes.
        /// </param>
        /// <exception cref="AlreadyReproducingException">
        ///  Thrown when your creature is already in the process of reproduction.
        /// </exception>
        /// <exception cref="NotMatureException">
        ///  Thrown when your creature is not yet mature and you try to reproduce.
        /// </exception>
        /// <exception cref="NotEnoughEnergyException">
        ///  Thrown when your creature does not have enough energy to start reproduction.
        /// </exception>
        /// <exception cref="NotReadyToReproduceException">
        ///  Thrown when your creature is not yet ready to reproduce because the appropriate number of ticks has not elapsed.
        /// </exception>
        public void BeginReproduction(byte[] dna)
        {
            if (IsReproducing)
            {
                throw new AlreadyReproducingException();
            }

            if (!State.IsMature)
            {
                throw new NotMatureException();
            }

            if (State.EnergyState < EnergyState.Normal)
            {
                throw new NotEnoughEnergyException();
            }

            if (!State.ReadyToReproduce)
            {
                throw new NotReadyToReproduceException();
            }

            var actionID = GetNextActionID();
            var action   = new ReproduceAction(ID, actionID, dna);

            lock (PendingActions)
            {
                PendingActions.SetReproduceAction(action);
                InProgressActions.SetReproduceAction(action);
            }
        }
        ///<summary>
        ///</summary>
        ///<param name="reproduceAction"></param>
        ///<exception cref="ApplicationException"></exception>
        public void SetReproduceAction(ReproduceAction reproduceAction)
        {
            if (IsImmutable)
            {
                throw new ApplicationException("PendingActions must be mutable to modify actions.");
            }

            ReproduceAction = reproduceAction;
        }
 /// <internal/>
 public ReproduceCompletedEventArgs(int actionID, ReproduceAction action)
     : base(actionID, action)
 {
 }
Exemple #4
0
        ///<summary>
        ///</summary>
        ///<param name="reproduceAction"></param>
        ///<exception cref="ApplicationException"></exception>
        public void SetReproduceAction(ReproduceAction reproduceAction)
        {
            if (IsImmutable)
            {
                throw new ApplicationException("PendingActions must be mutable to modify actions.");
            }

            ReproduceAction = reproduceAction;
        }
        /// <summary>
        ///  <para>
        ///   Use this function to command your creature to reproduce.  There are many
        ///   conditions on whether your creature can reproduce.  If these conditions
        ///   are not met, an exception will be thrown.  The easiest way to make
        ///   sure all pre-existing conditions have been met is to check the CanReproduce
        ///   property.
        ///  </para>
        ///  <para>
        ///   If you call this method multiple times in the same turn, then the last call
        ///   will be used, and all previous calls will be ignored.  This method is also
        ///   asynchronous, and a ReproduceCompletedEvent will be fired when your creature
        ///   has actually given birth.  The time between start and completion is 10 ticks.
        ///  </para>
        /// </summary>
        /// <param name="dna">
        ///  A byte array that gets passed to the child.  This can be any information you
        ///  want to pass to the child creature.  The byte array is truncated at 8000 bytes.
        /// </param>
        /// <exception cref="AlreadyReproducingException">
        ///  Thrown when your creature is already in the process of reproduction.
        /// </exception>
        /// <exception cref="NotMatureException">
        ///  Thrown when your creature is not yet mature and you try to reproduce.
        /// </exception>
        /// <exception cref="NotEnoughEnergyException">
        ///  Thrown when your creature does not have enough energy to start reproduction.
        /// </exception>
        /// <exception cref="NotReadyToReproduceException">
        ///  Thrown when your creature is not yet ready to reproduce because the appropriate number of ticks has not elapsed.
        /// </exception>
        public void BeginReproduction(byte[] dna)
        {
            if (IsReproducing)
            {
                throw new AlreadyReproducingException();
            }

            if (!State.IsMature)
            {
                throw new NotMatureException();
            }

            if (State.EnergyState < EnergyState.Normal)
            {
                throw new NotEnoughEnergyException();
            }

            if (!State.ReadyToReproduce)
            {
                throw new NotReadyToReproduceException();
            }

            var actionID = GetNextActionID();
            var action = new ReproduceAction(ID, actionID, dna);
            lock (PendingActions)
            {
                PendingActions.SetReproduceAction(action);
                InProgressActions.SetReproduceAction(action);
            }
        }