Home > Software engineering >  Gobang vb source code
Gobang vb source code

Time:09-24

Renju renju renju renju vb source code vb source code vb source code vb source gobang vb source gobang vb source code

Option Explicit
Dim blackturn As Boolean 'turn black following
Dim whiteturn As Boolean 'turn black following
Dim qipan (0 To 15, 0 To 15) As an Integer 'with the representation of a two-dimensional array board
Dim inti As an Integer array elements'
Dim intj As Integer
Dim boolF As Boolean 'said chess state:/end
Private Sub begin_Click resume () '
Me. Cls' removal window
For inti=0 To 15
For intj=0 To 15
Qipan array (inti, the intj)=0 'reset
Next
Next
Form_Load 'drawing board
End Sub
Private Sub exit_Click () 'exit
Unload Me
The Set Form1=Nothing
End Sub

Private Sub Form_Load ()
Form_Paint 'drawing board
Blackturn=True 'black down
BoolF=True 'start
Label1. Caption=under "black start"
End Sub

'the following
Private Sub Form_MouseDown (Button As an Integer, Shift the As an Integer, As Single x, y As Single)
Dim intx As Integer 'move later transverse position
Dim inty vertical position As Integer 'move later
If boolF=False Then 'to determine whether a chess board in the works, whether, jump out
Label1. Caption="end"
The Exit Sub
End the If
The location of the 'sure move later
'if the mouse to click position is not in the board, the jump out
If x & lt; 10 the Or x & gt; 310 the Or y & lt; 10 the Or y & gt; Then 310
The Exit Sub
End the If
'if the mouse to click the position in the board, is converted to the corresponding coordinate point, the famous board
If the Mod (x - 10) 20 & lt; 10 Then
Intx=x - (x - 10) Mod 20
The Else
Intx=x + 20 - (x - 10) Mod 20
End the If
If (y - 10) Mod 20 & lt; 10 Then
Inty=y (y - 10) Mod 20
The Else
Inty=y + 20 - (y - 10) Mod 20
End the If
'converts coordinates into the corresponding elements in the array
Inti=(intx - 10)/20
Intj=(inty - 10)/20

'if the array elements is zero, it indicates that the board of the corresponding points for pieces, then jump out
If qipan (inti, the intj) & lt;> 0 Then
The Exit Sub
End the If

'painting a (round)
If blackturn=True Then
Black
'Me. FillColor=RGB (0, 0, 0)
Qipan (inti, the intj)=1 'sunspot fu 1
Label1. Caption="white"
The Else
White
'Me. FillColor=RGB (255, 255, 255)
Qipan (inti, the intj)=2 'albino fu 2
Label1. Caption="black"
End the If
Me. The FillStyle=0 'an indispensible
Me. Circle (intx, inty), 8

'to determine whether there are five cords
Call IfFiveLine
'
in turnBlackturn=Not blackturn 'invert
End Sub
Private Sub IfFiveLine () 'to determine whether there are five cords
Dim strwho As String 'following party name

If qipan (inti, the intj)=1 Then, 'said black child
Strwho="black"
The Else
Strwho="white"
End the If
', namely, diagonal abital, this code is more complex, may be that to understand, but its high execution efficiency
'very suits with the checkerboard many
the condition of the
If samelinenums (1, 0) & gt;=5 Or samelinenums (0, 1) & gt;=5 Or samelinenums (1, 1) & gt;=5 Or samelinenums (1, 1) & gt; 5 Then=
MsgBox strwho & amp; "Victory!"
Chess boolF=False 'end
End the If
End Sub

The Function samelinenums (changei As an Integer, changej As Integer) 'judgment on the same straight line on the number of pieces
Dim As Integer I
Dim j As Integer
Dim num As Integer 'online same color the same number of pieces
'the calculation of the piece side with color, the
I=inti: j=intj
Do
If qipan (I, j) & lt;> Qipan (inti, the intj) Then
Num=Max (Abs (inti - I), Abs (intj - j))
The Exit Do
End the If
I=I + changei: j=j + changej
Loop Until I & lt; 0 Or I & gt; 15 the Or j & lt; 0 Or j & gt; 15

'the calculation of the pieces with color on the other side, the
I=inti: j=intj
Do
If qipan (I, j) & lt;> Qipan (inti, the intj) Then
Num=+ Max num - 1 (Abs (inti - I), Abs (intj - j))
The Exit Do
End the If
I=I - changei: j=j - changej
Loop Until I & lt; 0 Or I & gt; 15 the Or j & lt; 0 Or j & gt; 15
'MsgBox num
Samelinenums num=
End the Function
'get larger value
Function Max (inta As an Integer, intb.br deal As Integer)
Max=inta
If Max & lt; Intb.br deal Then Max=intb.br deal
End the Function

Private Sub Form_Paint () '(10, 10) to the upper left corner coordinates to draw a 16 * 16, the chessboard of each grid side length of 20 pixels
Cls' removal
Dim As Integer I
ScaleMode=3 'set the form of the canvas unit for pixel
For I=10 To 330 Step 20
Me. The Line (10, I) - (330 I)
Me. The Line (I, 10) - (I, 330)
Next
End Sub

CodePudding user response:

Forming the vb forming cells

CodePudding user response:

Top,

Not how you look at it, but feel very bad,

CodePudding user response:

Learning, the content is accepted, strengthen again and see if I can,

CodePudding user response:

BS archaeological brick home!!!!!!


This code is very junk:
1. No AI, can only be "double play",
2. The serious "logic and implementation bugs,"
To run the program, and then to "a few steps chess";
And then drag the window to the screen edge to form beyond the desktop part move back, or another program window in a bit of time to move it,
You all through the piece "" disappeared!!!!!!

CodePudding user response:

https://www.baidu.com/s? Wd=% 20 VB6 code gobang
  • Related