Пример #1
0
 /// <summary>
 /// Load the image associated with this page.
 /// </summary>
 /// <param name="graphics">Graphics instance</param>
 public void LoadImage(IGraphics graphics)
 {
     bmp = graphics.CreateBitmap(GameMain.GetFullPath(fileName),
                                 false);
     Debug.Assert(bmp != null,
                  "Page.LoadImage: Failed to load bitmap");
 }
Пример #2
0
            /// <summary>
            /// Initialize a panel with the data contained in the DataRow.
            /// </summary>
            /// <param name="dr">DataRow that defines the panel</param>
            /// <param name="graphics">Graphics instance</param>
            public UIPanel(DataRow dr, IGraphics graphics)
            {
                Debug.Assert(dr != null,
                             "UIPanel.UIPanel: Invalid DataTable");

                x = int.Parse((string)dr["X"], CultureInfo.InvariantCulture);
                y = int.Parse((string)dr["Y"], CultureInfo.InvariantCulture);

                string fullName = GameMain.GetFullPath(
                    @"Data\UI\" + (string)dr["FileName"]);

                bmp = graphics.CreateBitmap(fullName, false);
                Debug.Assert(bmp != null,
                             "UIPanel.UIPanel: Failed to initialize UI panel bitmap");
            }
Пример #3
0
        /// <summary>
        /// Initialize UI from the specified DataSet.
        /// </summary>
        /// <param name="ds">DataSet containing UI definition</param>
        /// <param name="graphics">Graphics instance</param>
        /// <param name="lev">Current level</param>
        public UserInterface(DataSet ds, IGraphics graphics, Level lev)
        {
            DataTable dt = ds.Tables["General"];

            Debug.Assert(dt != null && dt.Rows != null,
                         "UI.UI: Invalid General DataTable");


            string fontName = (string)dt.Rows[0]["Font"];

            fontValue = graphics.CreateFont(GameMain.GetFullPath(fontName));
            Debug.Assert(fontValue != null,
                         "UI.UI: Failed to initialize UI font");

            shotBarOutline.X = int.Parse((string)dt.Rows[0]["ShotBarX"],
                                         CultureInfo.InvariantCulture);
            shotBarOutline.Y = int.Parse((string)dt.Rows[0]["ShotBarY"],
                                         CultureInfo.InvariantCulture);
            shotBarOutline.Width = int.Parse(
                (string)dt.Rows[0]["ShotBarWidth"],
                CultureInfo.InvariantCulture);
            shotBarOutline.Height = int.Parse(
                (string)dt.Rows[0]["ShotBarHeight"],
                CultureInfo.InvariantCulture);

            misfireX = int.Parse((string)dt.Rows[0]["MisFireX"],
                                 CultureInfo.InvariantCulture);
            misfireY = int.Parse((string)dt.Rows[0]["MisFireY"],
                                 CultureInfo.InvariantCulture);

            dt = ds.Tables["Panel"];
            Debug.Assert(dt != null && dt.Rows != null,
                         "UI.UI: Invalid Panel DataTable");

            foreach (DataRow dr in dt.Rows)
            {
                UIPanel p = new UIPanel(dr, graphics);
                Debug.Assert(p != null,
                             "UI.UI: Failed to initialize UIPanel");

                panels.Add(p);
            }

            shotBarGreen.X      = shotBarOutline.X + 1;
            shotBarGreen.Y      = shotBarOutline.Y + 1;
            shotBarGreen.Height = shotBarOutline.Height - 2;
        }
Пример #4
0
        /// <summary>
        /// Initialize the level.
        /// </summary>
        /// <param name="ds">DataSet containing level data</param>
        /// <param name="graphics">Valid Graphics object</param>
        public Level(DataSet ds, IGraphics graphics)
        {
            // Store graphics
            Debug.Assert(graphics != null,
                         "Level.Level: Invalid Graphics object");

            this.graphics = graphics;

            // Validate the DataSet
            Debug.Assert(ds != null && ds.Tables != null,
                         "Level.Level: Invalid DataSet");

            // General
            DataTable dt    = ds.Tables["General"];
            DataRow   drGen = dt.Rows[0];

            screenEdgeBufferValue = float.Parse(
                (string)(drGen["ScreenEdgeBuffer"]),
                CultureInfo.InvariantCulture);
            FrameRateCheckRateValue = float.Parse(
                (string)(drGen["FrameRateCheckRate"]),
                CultureInfo.InvariantCulture);
            gravityValue = float.Parse((string)(drGen["Gravity"]),
                                       CultureInfo.InvariantCulture);

            // Images
            Debug.Assert(ds.Tables["Image"] != null &&
                         ds.Tables["Image"].Rows != null,
                         "Level.Level: No images specified in level data");

            dt = ds.Tables["Image"];
            foreach (DataRow dr in dt.Rows)
            {
                IBitmap bmp = graphics.CreateBitmap(GameMain.GetFullPath(
                                                        @"Data\Level\" + (string)dr["FileName"]),
                                                    bool.Parse((string)dr["Transparency"]));
                Debug.Assert(bmp != null,
                             string.Format(CultureInfo.InvariantCulture,
                                           "Failed to initialize bitmap {0}",
                                           @"Data\Level\" + (string)dr["FileName"]));

                images.Add(bmp);
            }

            // Layers
            dt = ds.Tables["Layer"];
            foreach (DataRow dr in dt.Rows)
            {
                layers.Add(new Layer(dr, images));
            }

            Debug.Assert(layers.Count >= 1,
                         "Level does not contain 2 or more layers");

            ds = null;

            // AI
            DataSet dsAI = new DataSet();

            Debug.Assert(dsAI != null && dsAI.Tables != null,
                         "Level.Level: Failed to initialize AI DataSet");

            dsAI.Locale = CultureInfo.InvariantCulture;
            dsAI.ReadXml(GameMain.GetFullPath(@"Data\AI\ai.xml"));
            dt = dsAI.Tables["Definition"];
            Debug.Assert(dt != null && dt.Rows != null,
                         "Level.Level: Failed to load AI DataTable");

            foreach (DataRow dr in dt.Rows)
            {
                AI ai = AIHandler.Create(dr);
                Debug.Assert(ai != null,
                             "Level.Level: Failed to initialize AI");
                this.ai.Add(ai);
            }
            dsAI = null;

            DataSet dsAnimations = new DataSet();

            Debug.Assert(dsAnimations != null && dsAnimations.Tables != null,
                         "Level.Level: Failed to initialize animation DataSet");

            dsAnimations.Locale = CultureInfo.InvariantCulture;

            // Animations
            dsAnimations.ReadXml(GameMain.GetFullPath(@"Data\Animations\animations.xml"));
            dt = dsAnimations.Tables["Definition"];
            Debug.Assert(dt != null && dt.Rows != null,
                         "Level.Level: Failed to load animation DataTable");

            foreach (DataRow dr in dt.Rows)
            {
                int numberRows = int.Parse((string)dr["Rows"],
                                           CultureInfo.InvariantCulture);
                int numberColumns = int.Parse((string)dr["Columns"],
                                              CultureInfo.InvariantCulture);
                int cellWidth = int.Parse((string)dr["CellWidth"],
                                          CultureInfo.InvariantCulture);
                int cellHeight = int.Parse((string)dr["CellHeight"],
                                           CultureInfo.InvariantCulture);

                Animation animation = new Animation(GameMain.GetFullPath(
                                                        @"Data\Animations\" + (string)dr["FileName"]),
                                                    graphics, numberRows, numberColumns, 0, cellWidth,
                                                    cellHeight, 0);
                Debug.Assert(animation != null && animation.Init,
                             "Level.Level: Failed to load animation");

                animations.Add(animation);
            }
            dsAnimations = null;

            // Player
            DataSet dsPlayer = new DataSet();

            Debug.Assert(dsPlayer != null,
                         "Level.Level: Failed to initialize player DataSet");

            dsPlayer.Locale = CultureInfo.InvariantCulture;
            dsPlayer.ReadXml(GameMain.GetFullPath(@"Data\Player\player.xml"));
            Player p = new Player(dsPlayer, graphics, animations);

            Debug.Assert(p != null,
                         "Level.Level: Failed to initialize player");
            worldObjectsValue.Add(p);
            dsPlayer = null;

            // World Objects
            DataSet dsWorldObjects = new DataSet();

            Debug.Assert(dsWorldObjects != null && dsWorldObjects.Tables !=
                         null,
                         "Level.Level: Failed to initialize world object DataSet");

            dsWorldObjects.Locale = CultureInfo.InvariantCulture;
            dsWorldObjects.ReadXml(GameMain.GetFullPath(@"Data\WorldObjects\worldobjects.xml"));
            dt = dsWorldObjects.Tables["Instance"];
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    WorldObject wo = new WorldObject(dr, this);
                    Debug.Assert(wo != null,
                                 "Level.Level: Failed to initialize world object");

                    worldObjectsValue.Add(wo);
                }
            }
        }