Exemplo n.º 1
0
 //changed
 private void generateDefaultMapList(BlockList _blockList)
 {
     _blockList.list.Clear();
     float rectSizeX = this.Width / stageSize;    //What the size of each rectangle should be, depending on the form's size;
     float rectSizeY = this.Height / stageSize;    //What the size of each rectangle should be, depending on the form's size;
     Block BlockForList;    //No need to initialize it;
     for (float y = 0; y < stageSize; y++)    //500 is the size of the Form, 50 is the size of the X & Y of each rectangle;
         for (float x = 0; x < stageSize; x++)
         {
             BlockForList = new Block(pen, new RectangleF(x * rectSizeX, y * rectSizeY, rectSizeX, rectSizeY), false);    //Initializing the block each time to set different locations;
             _blockList.list.Add(BlockForList);    //Adding the blocks to the list to draw them all;
         }
 }
Exemplo n.º 2
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            g = this.CreateGraphics();
            Block clickBlock;
            /*PointF clickLocation = findNearest(e.Location, possibleLocations);
            clickBlock             = new Block(new Pen(new SolidBrush(Color.Maroon)), new RectangleF(clickLocation, new SizeF(500 / 10.0f, 500 / 10.0f)));*/
            clickBlock = findClickedBlock(e.Location, blockList.list);
            blockList.list.Remove(clickBlock);  //changes
            if (e.Button == MouseButtons.Left)
            {
                if (clickAction == 1)
                {
                    clickBlock._isMain = true;  //changes
                    clickBlock.Draw(g); //changes
                    //blockList.DrawBlocksInList(g);
                }
                else if (clickAction == 2)
                    if (clickBlock._Rectangle.Width > clickBlock._Rectangle.Height)    //Better to draw a line that splits the rectangle instead of drawing individual rectangles but then you'd have to think of another way to fill the rects;
                    {
                        Block firstHalfBlock = new Block(pen,
                            new RectangleF(clickBlock._Rectangle.Location,
                            new SizeF(clickBlock._Rectangle.Size.Width / 2, clickBlock._Rectangle.Size.Height)), false); //changed

                        Block secondHalfBlock = new Block(pen,
                            new RectangleF(
                                new PointF(clickBlock._Rectangle.X + clickBlock._Rectangle.Width / 2, clickBlock._Rectangle.Y),
                                clickBlock._Rectangle.Size), false); //changed

                        blockList.list.Add(firstHalfBlock); blockList.list.Add(secondHalfBlock);
                        firstHalfBlock.Draw(g); //changed
                        secondHalfBlock.Draw(g); //changed
                    }
                    else
                    {
                        Block firstHalfBlock = new Block(pen,
                            new RectangleF(clickBlock._Rectangle.Location,
                            new SizeF(clickBlock._Rectangle.Size.Width, clickBlock._Rectangle.Size.Height / 2)), false); //changed

                        Block secondHalfBlock = new Block(pen,
                            new RectangleF(
                                new PointF(clickBlock._Rectangle.X, clickBlock._Rectangle.Y + clickBlock._Rectangle.Height / 2),
                                new SizeF(clickBlock._Rectangle.Size.Width, clickBlock._Rectangle.Size.Height)), false); //changed

                        blockList.list.Add(firstHalfBlock); blockList.list.Add(secondHalfBlock);
                        firstHalfBlock.Draw(g); //changed
                        secondHalfBlock.Draw(g); //changed
                    }
            }
            else if (e.Button == MouseButtons.Right)
            {
                generateDefaultMapList(blockList); //changed
                g.Clear(Color.White);
                blockList.DrawBlocksInList(g); //changed
                this.Invalidate();
            }
        }