Exemple #1
0
        /// <summary>
        /// Loads the chest bonus descriptions from the given XML
        /// file and sets up the internal structures.
        /// </summary>
        static ChestBonusInfo()
        {
            try
            {
                // Get the manifest string
                Stream stream = typeof(ChestBonusInfo).Assembly
                    .GetManifestResourceStream("CuteGod.bonuses.xml");

                // Create an XML reader out of it
                XmlTextReader xml = new XmlTextReader(stream);
                ChestBonusInfo sp = null;
                ChestBonusType type = ChestBonusType.Maximum;

                // Loop through the file
                while (xml.Read())
                {
                    // See if we finished a node
                    if (xml.NodeType == XmlNodeType.EndElement &&
                        xml.LocalName == "bonus")
                    {
                        hash[type] = sp;
                        sp = null;
                    }

                    // Ignore all but start elements
                    if (xml.NodeType != XmlNodeType.Element)
                        continue;

                    // Check for name
                    if (xml.LocalName == "bonus")
                    {
                        sp = new ChestBonusInfo();
                        type = (ChestBonusType) Enum
                            .Parse(typeof(ChestBonusType), xml["type"]);
                        sp.type = type;
                    }
                    else if (xml.LocalName == "title")
                        sp.Title = xml.ReadString();
                    else if (xml.LocalName == "block")
                        sp.BlockKey = xml.ReadString();
                    else if (xml.LocalName == "description")
                        sp.Description = xml.ReadString();
                }
            }
            catch (Exception e)
            {
                Logger.Error(typeof(ChestBonusInfo),
                    "Cannot load penalties: {0}", e.Message);
                throw e;
            }
        }
        /// <summary>
        /// Triggers an update of the mode's state.
        /// </summary>
        /// <param name="args"></param>
        public override void Update(UpdateArgs args)
        {
            // See if we have any chests left
            if (chestInfo == null && ChestCounter == 0)
            {
                // We don't, so finish up
                Timeout();
                return;
            }

            // If the chest is null, we need to start up a new chest
            if (chestInfo == null)
            {
                // Create a new chest
                ChestCounter--;
                chestInfo = ChestBonusInfo.Random;

                // Give it a time to live
                chestSeconds = Constants.ChestOpenFadeSpeed;

                // Create the sprites and direction
                bonusSprite = AssetLoader.Instance
                    .CreateSprite(chestInfo.BlockKey);
                bonusSprite.Point = ChestSprite.Point;
                fadeIn = true;
                pause = false;

                // Set up the text
                Title = chestInfo.Title;
                Text = String.Format(chestInfo.Description,
                    Game.State.SecondsPerTurn,
                    Game.State.BugCount,
                    Game.State.GrabCost,
                    Game.State.Board.Columns);

                // Add it to the sprites
                Sprites.Add(bonusSprite);
            }
            else
            {
                // Increment the pointer
                chestSeconds -= args.SecondsSinceLastUpdate;

                // If we are negative, then we change mode
                if (chestSeconds < 0)
                {
                    // Switch mode
                    if (pause)
                    {
                        // Fade out
                        pause = false;
                        fadeIn = false;
                    }
                    else if (fadeIn)
                    {
                        // Pause it
                        pause = true;

                        // Apply the value
                        chestInfo.Apply(bonusSprite.Point);
                    }
                    else
                    {
                        // Remove it
                        Sprites.Remove(bonusSprite);
                        chestInfo = null;
                        bonusSprite = null;
                        return;
                    }

                    // Update the counter
                    chestSeconds = Constants.ChestOpenFadeSpeed;
                }
            }

            // Figure out the ratios (1 is just start, 0 is done)
            double timeRatio = chestSeconds / Constants.ChestOpenFadeSpeed;
            float positionRatio = (float) (timeRatio * BlockHeight);
            int alpha = (int) (255 * timeRatio);

            // Figure out the chest position
            if (pause)
            {
                // We aren't doing anything until the seconds change
                bonusSprite.Point = new PointF(
                    ChestSprite.Point.X,
                    ChestSprite.Point.Y - BlockHeight);
                tint = Color.White;
            }
            else if (fadeIn)
            {
                // Change the position based on the ratio
                bonusSprite.Point = new PointF(
                    ChestSprite.Point.X,
                    ChestSprite.Point.Y - BlockHeight + positionRatio);

                // Change the alpha based on the ratio
                tint = Color.FromArgb(255 - alpha, Color.White);
            }
            else
            {
                // Change the position based on the ratio
                bonusSprite.Point = new PointF(
                    ChestSprite.Point.X,
                    ChestSprite.Point.Y - 2 * BlockHeight + positionRatio);

                // Change the alpha based on the ratio
                tint = Color.FromArgb(alpha, Color.White);
            }

            // Move the sprite
            bonusSprite.Tint = tint;

            // Call the base
            base.Update(args);
        }
        /// <summary>
        /// Triggered when the mode times out. 
        /// </summary>
        protected override void Timeout()
        {
            // See if we need to finish up anything
            if (chestInfo != null)
            {
                // Just apply it where ever it is
                chestInfo.Apply(bonusSprite.Point);
            }

            // Loop through any remaining chests
            while (ChestCounter > 0)
            {
                chestInfo = ChestBonusInfo.Random;
                chestInfo.Apply(ChestSprite.Point);
                ChestCounter--;
            }

            // Change the mini mode to the new stage
            (Game.GameMode as PlayMode).MinorMode =
                new NewStageMinorMode();
        }