示例#1
0
        // add a new level to this project
        protected void AddNewLevel()
        {
            // create and add the level
            LevelData level = new LevelData();
            m_Levels.Add(level);

            // update the navigation tree and select the new level
            RebuildTree();
            SelectNode(level);
        }
示例#2
0
        // add a new level to this project, as a copy of another level
        protected void CopyLevel()
        {
            // get a reference to the current tree node
            TreeNode node = treeView1.SelectedNode;

            // is it a valid level?
            if (IsLevelNode(node))
            {
                // create a copy of the level
                LevelData levelSrc = (LevelData)node.Tag;
                LevelData levelNew = new LevelData(levelSrc.ToString());

                // insert the new level just after its source
                int index = m_Levels.IndexOf(levelSrc);
                m_Levels.Insert(index + 1, levelNew);

                // update the navigation tree and select the new level
                RebuildTree();
                SelectNode(levelNew);
            }
        }
 // draw the bricks
 protected void DrawLevelData(Graphics g, LevelData level)
 {
     foreach (Brick b in level.Bricks)
     {
         g.FillRectangle( // fill brick
             m_BrickBrushes[b.HitsToClear - 1],
             m_GameRect.Left + b.X,
             m_GameRect.Top + b.Y,
             level.BrickWidth,
             level.BrickHeight);
         g.DrawRectangle( // outline brick
             Pens.Black,
             m_GameRect.Left + b.X,
             m_GameRect.Top + b.Y,
             level.BrickWidth,
             level.BrickHeight);
     }
 }
 // draw "ghosted" brick where the new brick would be located
 protected void DrawGhostBrick(Graphics g, LevelData level)
 {
     if (m_NewBrickX >= 0 && m_NewBrickY >= 0)
     {
         g.FillRectangle( // fill brick
             m_GhostBrush,
             m_GameRect.Left + m_NewBrickX,
             m_GameRect.Top + m_NewBrickY,
             level.BrickWidth,
             level.BrickHeight);
         g.DrawRectangle( // outline brick
             Pens.Black,
             m_GameRect.Left + m_NewBrickX,
             m_GameRect.Top + m_NewBrickY,
             level.BrickWidth,
             level.BrickHeight);
     }
 }
示例#5
0
        // locate the tree node that refers to the given level
        // and select it in our navigation tree control
        protected void SelectNode(LevelData level)
        {
            // locate root node, clear selection
            TreeNode root = treeView1.Nodes[0];
            treeView1.SelectedNode = null;

            // reset editor control's level data reference
            brickBreakerEditorControl1.LevelData = null;

            // scan the navigation tree, looking for the given level
            foreach (TreeNode node in root.Nodes)
            {
                if (node.Tag == level)
                {
                    // simply selecting the node will trigger the
                    // selection events on the navigation tree control
                    // which will call our handler for AfterSelect
                    // and tell the editor control to display the level
                    // data for the newly-selected node
                    treeView1.SelectedNode = node;

                    // stop looking, we found it
                    break;
                }
            }
        }