Russian square (2)

xiaoxiao2021-03-06  101

I have never had some things, I haven't learned for a few days, and I have to enter the right track from today.

Here is VB to implement a small square to simulate the Russian square, except that it is still not deformed

Option ExplicitConst MAX_X = 9Const MAX_Y = 14__________________________________________________________________Sub new_block () 'to generate a new block block.Top = 0 block.Left = 5 * block.Width block.Visible = TrueEnd Sub

__________________________________________________________________Function can_move (fx As Integer) As Boolean 'determines whether the block can move Dim x, y As Integer x = block.Left / block.Width y = block.Top / block.Height can_move = True Select Case fx Case 0' left x = x - 1 case 1 'up y = y - 1 case 2' right x = x 1 case 3 'down y = y 1 End select if x <0 or y> max_x or y> max_y kil CAN_MOVE = FALSE EXIT FUNCTION END IF DIM I as INTEGER for i = 0 to deadblock.ubound if deadblock (i) .visible = true and _ x = deadblock (i) .wid / deadblock (i) .width and _ y = deadblock (i) .top / deadblock (i) .height the can_move = false exit function end if nextend function

Moving direction __________________________________________________________________Sub block_move (fx As Integer) 'determined block of If Not can_move (fx) Then Exit Sub End If Dim x, y As Integer x = block.Left / block.Width y = block.Top / block.Height Select Case FX case 0 'Left x = x - 1 case 1' up 'y = y - 1 case 2' right x = x 1 Case 3 'down y = y 1 End Select Block.move X * block.width, y * block.HeightEnd Sub__________________________________________________________________Sub finish_down () 'block has stopped falling Dim i As Integer For i = 0 To deadblock.UBound if deadblock (i) .Visible = False Then deadblock (i) .Top = block.Top deadblock (i). Left = block.Left deadblock (i) .Visible = True block.Visible = False Exit Sub End If Next Load deadblock (i) deadblock (i) .Top = block.Top deadblock (i) .Left = block.Left deadblock ( i) .visible = true block block.v isible = FalseEnd Sub__________________________________________________________________Function can_clear_line () As Boolean 'determines whether or eliminate line Dim i As Integer Dim count As Integer For i = 0 To deadblock.UBound If deadblock (i) .Visible = True And _ deadblock (i) .Top = block. TOP THEN Count = Count 1 End if Next if Count> max_x kil_clear_line = true else can_clear_line = false end ifend function

__________________________________________________________________Sub clear_line () 'line elimination Dim i As Integer Dim count As Integer For i = 0 To deadblock.UBound If deadblock (i) .Visible = True And _ deadblock (i) .Top = block.Top Then deadblock (i). Visible = False End If Next For i = 0 To deadblock.UBound If deadblock (i) .Visible = True Then deadblock (i) .Top = deadblock (i) .Top deadblock (i) .Height End If NextEnd Sub__________________________________________________________________Private Sub back_Click () Timer1.enabled = not timer1.enabledend Sub

_________________________________________________________________Private subatch_keydown (Keycode As INTEGER, SHIFT AS INTEGER) BLOCK_MOVE Keycode - 37nd Sub

__________________________________________________________________Private Sub Timer1_Timer () If block.Visible = True Then If can_move (3) = True Then block_move 3 Else finish_down If can_clear_line = True Then clear_line End If End If Else new_block End IfEnd Sub

转载请注明原文地址:https://www.9cbs.com/read-124505.html

New Post(0)