Current location - Education and Training Encyclopedia - Graduation thesis - Who has vb spelling games and test papers?
Who has vb spelling games and test papers?
1. First, prepare a picture with a moderate size.

2. Click Project → Parts, and then find "Microsoft PictureClip Control 6.0". When selected, the PictureClip control will appear in the toolbox.

Medium.

3. Drag the PictureClip control onto the form and set its properties in the Properties window: click the Picture property to add the picture you just prepared.

Set the Cols and Rows properties to 3 to divide the picture into 9 cells with 3 rows and 3 columns. These cells are numbered using the GraphicCell property, starting with 0.

The order is from left to right and from top to bottom. For example, we access these cells by adding the following statement to the From_load procedure:

Form 1. Image =PictureClip 1. Graphic cell (0)

As soon as it runs, you will find that the form shows a piece in the upper left corner of the picture in PictureClip 1.

4. Place nine image controls on the form. In order to simplify the program code, we use the image control array. So how do you build a control array?

First place a control Image 1 on the form, then click the copy button, and then click the paste button, and you will be asked if you want to create a control array.

Just click "Yes". Click "Paste" button continuously to add array members, so that there are Image 1(0), Image 1( 1), ... on the form.

Wait for nine image controls. These controls are nine units for displaying pictures, that is, each tile displays a control.

That's all, plus a command button Command 1 and two label controls Label 1 and label2, respectively.

Set to Start, Step and 0. The design of the interface is completed.

The program code is as follows:

Option explicit

"Dim i As Integer" defines a loop variable.

Dim j is an integer

Set the step size to an integer.

Dim x(8) As Integer' defines an array for storing random numbers.

Private subcommand 1_Click ()?

Initialize the game.

Command 1. "Enabled = False" disables the start button.

End joint

Private sub-form _Load ()?

Randomize the initial random number generator

End joint

Sub init ()' Initializes the game subroutine.

For i = 0 to 7' randomly generates 8 non-repeating numbers (from 0 to 7).

a0: x(i)=Int(Rnd*8)

For j = 0 to i-1

If x(i)=x(j), go to a0.

then

then

For i = 0 to 7

Image 1(i)。 Enabled = True' makes image 1 respond to mouse events.

Image 1 (x (i)). Image = PictureClip 1. "Graphic Unit (I)" allows eight units of a picture to be given eight image controls respectively.

then

Picture 1 (8). Picture = loadpicture ("") space is used to move pictures.

End joint

Private subimage1_ click (index as integer)' Pay attention to the use of index values.

Select Case Index Mod 3' divides nine image controls into three columns.

When the mouse clicks on the 1 column,

If the image 1 (index+1). Picture = loadpicture ("") and then' judge whether the right side is empty.

Image 1 (index+1). Picture = picture 1 (index). Pictures' Exchange pictures.

Image 1 (index). Picture=LoadPicture(" ")

Don't test whether the puzzle is successful.

If ... it will be over.

Case 1' When the mouse clicks on the second column,

If the image 1 (index-1). Picture = loadpicture ("") and then' judge whether the left side is empty.

Image 1 (index-1). Image = Image 1 (index). draw

Image 1 (index). Picture=LoadPicture(" ")

win

If ... it will be over.

If the image 1 (index+1). Picture = loadpicture ("") and then' judge whether the right side is empty.

Image 1(Index + 1)。 Image = Image 1 (index). draw

Image 1 (index). Picture=LoadPicture(" ")

win

If ... it will be over.

Example 2' When the mouse clicks on the third column.

If the image 1 (index-1). Picture = loadpicture ("") and then' judge whether the left side is empty.

Image 1 (index-1). Image = Image 1 (index). draw

Image 1 (index). Picture=LoadPicture(" ")

win

If ... it will be over.

End selection

Select Case Index\ 3' divides nine image controls into three rows.

Case 0' When the mouse clicks 1 line,

If the image 1 (index +3). Picture = loadpicture ("") and then' judge whether the bottom is empty.

Image 1 (index+3). Image = Image 1 (index). draw

Image 1 (index). Picture=LoadPicture(" ")

win

If ... it will be over.

Case 1' When the mouse clicks on line 2,

If the image 1 (index -3). Picture = loadpicture ("") and then' judge whether the top is empty.

Image 1 (index-3). Image = Image 1 (index). draw

Image 1 (index). Picture=LoadPicture(" ")

win

If ... it will be over.

If the image 1 (index +3). Picture = loadpicture ("") and then' judge whether the bottom is empty.

Image 1 (index+3). Image = Image 1 (index). draw

Image 1 (index). Picture=LoadPicture(" ")

win

If ... it will be over.

Situation 2' When mouse clicks on line 3.

If the image 1 (index -3). Picture = loadpicture ("") and then' judge whether the top is empty.

Image 1 (index-3). Image = Image 1 (index). draw

Image 1 (index). Picture=LoadPicture(" ")

win

If ... it will be over.

End selection

End joint

Sub win ()' subroutine, used to test whether the puzzle is successful.

Dim num is an integer.

Step = Step+1' Step plus 1.

Label 2. Title = Step

For i = 0 to 8, it is judged whether all the blocks are in proper positions.

If Image 1(i). Image = PictureClip 1. graphic cell(I)Then num = num+ 1

then

If num? Then =8

MsgBox "You are great!"

For i=0 to 8

Image 1 (i)。 "Enabled=False" makes it not respond to mouse events.

then

Command 1. "Enabled=True" resume command button

If ... it will be over.

End joint

There must be a mistake in it, that is, punctuation should be converted into English.

If not, find it yourself. If not, leave me a message and I'll help you.