Delete a rectangle class

I create a breakthrough game in C #, I use booleans to tell the program whether to draw a brick or not, I used the rectangle classes to overlay the drawn rectangles to find out if the ball has hit bricks

This is the code I've used so far:

Rectangle brick4 = new Rectangle((490), (50), (50), (20));
bool hitBrick4 = brick4.Contains(x, y);
if (hitBrick4)
{
    brick4 = new Rectangle(0, 0, 0, 0);
    brick4draw = false;
    yChange = -yChange;
    bricksdestroyed = bricksdestroyed + 1;
   lblBricksDestroyed.Text = "Bricks Hit: " + bricksdestroyed;
}

I am trying to remove the rectangle class after the brick has been hit by setting it to zero, but the rectangle still exists and can still be hit by calling the brick code.

Any suggestions, sorry if I'm not very clear.

+3
source share
3 answers

This will not scale well, since you are introducing a new variable for each brick.

Rectangle List . , , . , .

+1

Rectangle, :

if (hitBrick4 && brick4 != Rectangle.Empty)
{
    brick4  = Rectangle.Empty;
    ...
}
0

OMG, , , ! VisualBasic PowerPacks, Visual Studio 2008

, TextBox, .. []

Dim x = TextBox1.Location.X
Dim y = TextBox1.Location.Y
Dim width = TextBox1.Width
Dim height = TextBox1.Height
Dim ShapeContainer1 As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
Me.Controls.Add(ShapeContainer1)
Dim RectangleShape1 As New Microsoft.VisualBasic.PowerPacks.RectangleShape
ShapeContainer1.Shapes.AddRange(New Microsoft.VisualBasic.PowerPacks.Shape() {RectangleShape1})
RectangleShape1.Location = New System.Drawing.Point(x - 1, y - 1)
RectangleShape1.Size = New System.Drawing.Size(width + 1, height + 1)
RectangleShape1.BorderColor = Color.MistyRose
ShapeContainer1.Refresh()

, , ... , , ( Rectangle, ShapeContainer ), , !

0

Source: https://habr.com/ru/post/1777182/


All Articles