Game Name: Five Supions
Author: Lin Wei
Email: ray530@21cn.com
game instructions:
I believe this game has no unattended. But many friends want this game code. Just today I have time. I tried to write, this game is a single board, 2 people turn control. You can do some modifications according to your needs.
So let's introduce the concept of the game.
Game concept:
First of all, we know that the top of the five-child chess is 15 * 2 lines. So when we play chess, we must put the game to the intersection of a two line. Second, we must judge whether there is a piece of point to be under, if there is already existing, then this task must be interrupted. Once again, it is a key thing, how is it judged whether the five chess pieces have become a string? They are horizontal, vertical, joy, and four directions. If the chess we put down is just a condition in these four directions. Then the game is over.
Next, you will introduce how to implement the above functions.
We first use a picture box Picture1 as a container (chessboard) for storing the chess pieces. The chess piece uses the Shape Control BtnBlack () control array to put in Picture1. In the picture box, we draw one (15 * 2) line array with the line method.
So let's take a look at this code:
Code 1,
Private sub flow_load ()
Const start = 14
Picture1.scale (0, 0) - (Start, Start)
For i = 0 to start
Picture1.Line (i, 0) - (i, start)
Next i
For j = 0 to start
Picture1.Line (0, j) - (Start, J)
NEXT J
Call init
End Sub
We use form_load () event to initialize the line array, in which we see the following code:
Code 2,
Const start = 14
Picture1.scale (0, 0) - (Start, Start)
The code means that Picture1 is divided into 15 * 15 points. The values of each two points represent each position. The starting point is (0,0)
Next, we must find a way to convert two points into values because we declare a 1-dimensional array. We can customize a function. Switch, this function name is; Conventtonumber
Code 3,
Private Function Conventtonumber (X as integer, y as integer, optional opt as boolean = false) AS integer '// convert coordinates into array elements
DIM NUM AS INTEGER
For i = 0 TO 14
For j = 0 to 14
Num = NUM 1
IF x = i and y = j Then
If OPT THEN ISWHO (NUM) = who '// Opt Representative When adding a chess
Conventtonumber = NUM
Redim Preserve History (btnblack.ubound 1)
History (btnblack.ubound) = NUM
END IF
NEXT J
Next i
END FUNCTION
Then look at the following code:
Code 4,
Private Sub Picture1_MouseDown (Button As Integer, Shift As Integer, x as single, y as single) IF arr (consisting (x)), int (round (y))))) = TRUE TEN 'If there is a chess piece Interrupt task
EXIT SUB
Else
Arr (consisting (x)), int (Round (Y), true) = true 'Whether there is a chess piece to be true
END IF
Load btnblack (btnblack.ubound 1)
Btnblack (btnblack.ubound) .left = int (Round (x)) - btnblack (btnblack.ubound) .width / 2
Btnblack (btnblack.ubound) .top = int (runk (y) - btnblack (btnblack.ubound) .height / 2
Btnblack (btnblack.ubound) .fillcolor = ChangePlayerColor
WHO = not who
Btnblack (btnblack.ubound) .visible = true
Call getwon (Arr ())
Call ChangePlayerColor
End Sub
This process uses the CONVENTONUMBER function. The purpose is to convert the currently captured position to a value, and change the element of the current converted value of the Arr () array to TRUE. Indicates that there is a chess piece.
Next, explain how to implement automatic alignment function.
In code 4.
Btnblack (btnblack.ubound) .left = int (Round (x)) - btnblack (btnblack.ubound) .width / 2
Btnblack (btnblack.ubound) .top = int (runk (y) - btnblack (btnblack.ubound) .height / 2
Indicates the coordinate value of the currently incoming. And minus half of the chess pieces themselves. Just aligned to the intersection.
Next, how to determine if it is a series, please see Figure 1-1:
In the figure, there are 0 to 255 a few, which are arranged in order. These numbers represent each element of the array of arrays.
Array types of Boolean represents whether the element exists.
Private Arr (255) as boolean '// Declare whether there is a panel variable
And use a I loop, traverse the entire array, and judge 4 possible locations. Whether it is True.
Furthermore, four square frames have been given. We use 36 as a central point (indicating that four possibly a series of positions can be circulated when I cycles 36).
First, we can find a law. Let's see "/" first. 36, 50, 64, 78, 92. It is every 14 digits. It is apparent that we can use the I loop inside, then use a J cycle, which is used to traverse 5 points on the "/" line, and whether it exists. If there is an end.
The same, the other three lines, also have similar laws.
PRIVATE FUNCTION GETWON (ARR () AS Boolean '// Returns whether to have a series of serials (5 groups)
DIM Seriesum as integer
DIM H
For i = 0 to ubound (arr) '// Convenience the entire array for j = i to (i 65) MOD 255 STEP 16' /
IF arr (j) and iswho (j) = iswho (i) Then Seriesum = Seriesum 1
NEXT J
IF isfive (Seriesum) THEN CALL WIN (IsWho (i)): exit function
For j = i to (i 56) MOD 255 STEP 14 '/
IF arr (j) and iswho (j) = iswho (i) Then Seriesum = Seriesum 1
NEXT J
IF isfive (Seriesum) THEN CALL WIN (IsWho (i)): exit function
For J = I to (i 60) MOD 255 STEP 15 '-
IF arr (j) and iswho (j) = iswho (i) Then Seriesum = Seriesum 1
NEXT J
IF isfive (Seriesum) THEN CALL WIN (IsWho (i)): exit function
For j = i to (i 4) MOD 255 Step 1 '|
IF arr (j) and iswho (j) = iswho (i) Then Seriesum = Seriesum 1
NEXT J
IF isfive (Seriesum) THEN CALL WIN (IsWho (i)): exit function
Next i
END FUNCTION
At the same time, it emphasizes that during each play, the color of the chess pieces must be replaced. Identify with the current player. I am using this variable here. And when a piece of chess is added, it must also be identified which player belongs to. I use private iswho (255) as boolean variable here.
The final details will no longer discuss. I published the papers for the first time, and the literary talent is very poor. Please see understanding. If you are willing to make friends with me, please join QQ: 630843. Or email: ray530@21cn.com
Original code download address: http://www.monthsoft.com/file/fivegame.rar