// Used to create a new instance of a SnappingRegion using the state of another SnappingRegion
 public SnappingRegion(SnappingRegion snapRegion)
 {
     xStart = snapRegion.xStart; // Values are copied across from the supplied SnappingRegion
     xEnd = snapRegion.xEnd;
     yStart = snapRegion.yStart;
     yEnd = snapRegion.yEnd;
     occupyingPBs = snapRegion.occupyingPBs;
 }
Example #2
0
 // Used to change the range that the grid will be drawn and the snapping region
 public void SetGridRange(int x, int y, int sizeX, int sizeY)
 {
     startX = x; // change the top left X coordinate to the supplied value
     startY = y; // change the top left Y coordinate to the supplied value
     endX = x + sizeX; // calculate the bottom right X coordinate to the supplied value
     endY = y + sizeY; // calculate the bottom right Y coordinate to the supplied value
     Refresh(); // Redraw the grid with it's new values
     snappingRegion = new SnappingRegion(startX * 20, startY * 20, endX * 20, endY * 20); // Update the snapping region to comply with the new values
 }
Example #3
0
        private void objectPlaced(object sender, DragEventArgs e)
        {
            DragPictureBox dragPictureBox = (sender as DropGrid).activeDragPB;
            SnappingRegion snappingRegion = new SnappingRegion((sender as DropGrid).GetSnappingRegion());
            snappingRegion.AddImageOffsets(dragPictureBox);
            if (!snappingRegion.IsSnappingRegion(dragPictureBox.Location.X, dragPictureBox.Location.Y) || snappingRegion.CheckIfOccupied(dragPictureBox.Location.X, dragPictureBox.Location.Y, dragPictureBox.Width, dragPictureBox.Height))
            {
                return;
            }
            points -= dragPictureBox.getHeldValue("cost");
            PointsLabel.Text = "Points: " + points;
            (sender as DropGrid).AddOccupyingPB(dragPictureBox);
            dragPictureBox.Parent = tabControl1.TabPages[0];
            dragPictureBox.Location = new Point(dragPictureBox.Location.X - tabControl1.Location.X - 4, dragPictureBox.Location.Y - tabControl1.Location.Y - 22);
            dragPictureBox.BringToFront();

            switch (dragPictureBox.Tag + "")
            {
                case "Plant" :
                    PlantPurchased();
                    break;
                case "Tap" :
                    TapPurchased();
                    break;
                case "FoodMachine":
                    FoodMachinePurchased();
                    break;
                case "Torch":
                    TorchPurchased();
                    break;
            }
        }
 // Used to update the snapping region held by this DragPictureBox
 public void UpdateSnappingRegion(DropGrid dropGrid)
 {
     currentSnapRegion = new SnappingRegion(dropGrid.GetSnappingRegion()); // Update the snapping region to the current state of the supplied DropGrid's snapping region
     currentSnapRegion.snapMode = (int)SnapMode; // Update the snap mode of our snapping region to the SnapMode of this DragPictureBox
     currentSnapRegion.AddImageOffsets(this); // Add the image offsets to our snapping region using this DragPictureBox
 }
Example #5
0
        // When an object purchased from the shop is placed on the DropGrid
        private void objectPlaced(object sender, DragEventArgs e)
        {
            DragPictureBox dragPictureBox = (sender as DropGrid).activeDragPB; // Store the dropped DragPictureBox
            SnappingRegion snappingRegion = new SnappingRegion((sender as DropGrid).GetSnappingRegion()); // Store the snapping region of the DropGrid
            snappingRegion.AddImageOffsets(dragPictureBox); // Add Image offsets to the snapping region for interrogation purposes
            if (!snappingRegion.IsSnappingRegion(dragPictureBox.Location.X, dragPictureBox.Location.Y) || snappingRegion.CheckIfOccupied(dragPictureBox.Location.X, dragPictureBox.Location.Y, dragPictureBox.Width, dragPictureBox.Height)) // If the DragPictureBox cannot be placed here
            {
                return; // Stop this method here
            }
            points -= dragPictureBox.getHeldValue("cost"); // Reduce the player's points by the cost of the item
            PointsLabel.Text = "Points: " + points; // Update the text of the points label
            (sender as DropGrid).AddOccupyingPB(dragPictureBox); // Add this DragPictureBox as an occupying PictureBox on the DropGrid that no other DragPictureBox can be dropped on
            dragPictureBox.Parent = ViewTabControl.TabPages[0]; // Set the parent of the newly dropped DragPictureBox to the TabControl Mars view TabPage
            dragPictureBox.Location = new Point(dragPictureBox.Location.X - ViewTabControl.Location.X - 4, dragPictureBox.Location.Y - ViewTabControl.Location.Y - 22); // Correct the location of the dropped DragPictureBox
            dragPictureBox.BringToFront(); // Ensure that the DragPictureBox is at the front of the TapControl's page

            switch (dragPictureBox.Tag + "") // Inspect the tag of the DragPictureBox
            {
                case "Plant": // If the tag is Plant
                    PlantPurchased(); // Carry out the PlantPurchased functionality
                    break;
                case "Tap": // If the tag is Tap
                    TapPurchased(); // Carry out the TapPurchased functionality
                    break;
                case "FoodMachine": // If the tag is FoodMachine
                    FoodMachinePurchased(); // Carry out the FoodMachinePurchased functionality
                    break;
                case "Torch": // If the tag is Torch
                    TorchPurchased(); // Carry out the TorchPurchased functionality
                    break;
            }
        }
Example #6
0
 // When a DragPictureBox is dropped on this DropGrid
 private void DropGrid_DragDrop(object sender, DragEventArgs e)
 {
     Point dragPBlocation = activeDragPB.Location; // Store the location of the Dropped (active) DragPictureBox
     SetGridVisibility(false); // Set the visibility of the grid to false
     activeDragPB.followMouse.Stop(); // Stop the following timer on the Dropped DragPictureBox
     SnappingRegion tempSnappingRegion = new SnappingRegion(snappingRegion); // Temporarily store the state the current DropGrid
     tempSnappingRegion.AddImageOffsets(activeDragPB); // Add the image offsets of the Dropped DragPictureBox to the Snapping Region for reading purposes
     if (!tempSnappingRegion.IsSnappingRegion(dragPBlocation.X, dragPBlocation.Y) || tempSnappingRegion.CheckIfOccupied(dragPBlocation.X, dragPBlocation.Y, activeDragPB.Width, activeDragPB.Height)) // If the DragPictureBox cannot be placed here becasue there is another component in it's way
     {
         activeDragPB.Dispose(); // Dispose of the Dropped DragPictureBox
     }
 }