Tetris (1)

Source: Internet
Author: User

The construction of Tetris in the past two days is a complicated one. It is implemented in several steps.

HereSeveral types of deformation of blocks are implemented using VB, and the movement of blocks is controlled using the direction keys.

Sub new_block (inttype as integer)
Select case inttype
Case 1
Block (0). Left = block (0). Width * 0
Block (0). Top = block (0). Height * 0
Block (1). Left = block (0). Width * 1
Block (1). Top = block (0). Height * 0
Block (2). Left = block (0). Width * 2
Block (2). Top = block (0). Height * 0
Block (3). Left = block (0). Width * 3
Block (3). Top = block (0). Height * 0
Case 2
Block (0). Left = block (0). Width * 0
Block (0). Top = block (0). Height * 0
Block (1). Left = block (0). Width * 1
Block (1). Top = block (0). Height * 0
Block (2). Left = block (0). Width * 0
Block (2). Top = block (0). Height * 1
Block (3). Left = block (0). Width * 1
Block (3). Top = block (0). Height * 1
Case 3
Block (0). Left = block (0). Width * 1
Block (0). Top = block (0). Height * 0
Block (1). Left = block (0). Width * 0
Block (1). Top = block (0). Height * 1
Block (2). Left = block (0). Width * 1
Block (2). Top = block (0). Height * 1
Block (3). Left = block (0). Width * 2
Block (3). Top = block (0). Height * 1
Case else
Block (0). Left = block (0). Width * 0
Block (0). Top = block (0). Height * 0
Block (1). Left = block (0). Width * 1
Block (1). Top = block (0). Height * 0
Block (2). Left = block (0). Width * 2
Block (2). Top = block (0). Height * 0
Block (3). Left = block (0). Width * 3
Block (3). Top = block (0). Height * 0
End select
Dim I as integer
For I = 0 to 3
Block (I). Visible = true
Next
End sub
_________________________________________________
Sub block_move (FX as integer)
Dim I as integer
Dim X as integer
Dim y as integer
If can_move (FX) = false then
Exit sub
End if
For I = 0 to 3
X = block (I). Left/block (I). Width
Y = block (I). Top/block (I). Height
Select case FX
Case 1
X = x-1
Case 2
Y = Y-1
Case 3
X = x + 1
Case 4
Y = Y + 1
End select
Block (I). Left = block (I). Width * x
Block (I). Top = block (I). Height * y
Next
End sub
_________________________________________________
Private sub commandementclick ()
If isnumeric (text1.text) then
New_block CINT (text1.text)
End if
End sub
_________________________________________________
Private sub file_keydown (keycode as integer, shift as integer)
Block_move keycode-36
End sub
_________________________________________________
Function can_move (FX as integer) as Boolean
Dim I as integer
Dim X as integer
Dim y as integer
Can_move = true
For I = 0 to 3
X = block (I). Left/block (I). Width
Y = block (I). Top/block (I). Height
Select case FX
Case 1
X = x-1
Case 2
Y = Y-1
Case 3
X = x + 1
Case 4
Y = Y + 1
End select
If x <0 or x> 9 or Y <0 or Y> 14 then
Can_move = false
Exit Function
End if
Next
End Function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.