导航:首页 > 编程知识 > 如何用vb编程井字棋

如何用vb编程井字棋

发布时间:2023-02-12 04:25:28

Ⅰ 请电脑高手帮忙解释一下下面的一段用vb编的程序,关于井字棋游戏的算法。

这么长一段代码,都给你解释,LZ真不怕把人累死,问问题不是这么问的。。。

Ⅱ 怎么用VB编井字棋人机

定义棋盘格子数据结构
Private Type Wells
Wells_X As Long
Wells_Y As Long
Wells_Value As Integer
End Type

定义棋盘格子的实例数组
Private usrWells(1 To 9) As Wells

定义响应点击操作的逻辑棋盘格子代号数组
Private intWellsIndex(1 To 3, 1 To 3) As Integer

Ⅲ vb井字游戏的程序怎么写

在from中放8个command控件组成一组,再放一个command控件,名为"重来",见图,复制如下代码

玩法:轮流用鼠标点击相应数字的格子,当O或X横竖斜排成一线就算赢了。

Dimox(3,3)AsInteger

DimconditionAsInteger

DimresultAsInteger

PrivateSubCommand2_Click()

Dimi,jAsInteger

result=0:condition=0

Fori=0To8

Command1(i).Caption=""

Command1(i).Enabled=True

Nexti

Fori=0To2

Forj=0To2

ox(i,j)=0

Nextj

Nexti

EndSub

PrivateSubForm_Load()

Dimi,jAsInteger

condition=0:result=0

Fori=0To2

Forj=0To2

ox(i,j)=0

Nextj

Nexti

EndSub

PrivateSubCommand1_Click(IndexAsInteger)

Dimi,jAsInteger

DimoverAsBoolean

i=Index3

j=IndexMod3

Ifox(i,j)=0Then

Ifcondition=0Then

Command1(Index).Caption="O"

condition=1

ox(i,j)=1

Else

Command1(Index).Caption="X"

condition=0

ox(i,j)=2

EndIf

Rem判断是否连成一线

Fori=0To2

Ifox(0,i)=1Andox(1,i)=1Andox(2,i)=1Then

result=1

EndIf

Ifox(i,0)=1Andox(i,1)=1Andox(i,2)=1Then

result=1

EndIf

Ifox(0,i)=2Andox(1,i)=2Andox(2,i)=2Then

result=2

EndIf

Ifox(i,0)=2Andox(i,1)=2Andox(i,2)=2Then

result=2

EndIf

Nexti

Ifox(0,0)=1Andox(1,1)=1Andox(2,2)=1Then

result=1

EndIf

Ifox(0,0)=2Andox(1,1)=2Andox(2,2)=2Then

result=2

EndIf

Ifox(0,2)=1Andox(1,1)=1Andox(2,0)=1Then

result=1

EndIf

Ifox(0,2)=2Andox(1,1)=2Andox(2,0)=2Then

result=2

EndIf

Ifresult=1Then

MsgBox"O赢了"

EndIf

Ifresult=2Then

MsgBox"X赢了"

EndIf

Ifresult<>0Then

Fori=0To8

Command1(i).Enabled=False

Nexti

Else

over=True

Fori=0To2

Forj=0To2

Ifox(i,j)=0Then

over=False

EndIf

Nextj

Nexti

IfoverThen

MsgBox"结束"

EndIf

EndIf

EndIf

EndSub

Ⅳ vb井字棋怎么做

下载上面的图,文件后缀改成rar,解压出来就是源代码

Ⅳ 关于编写井字棋的问题

用坐标判断,比如说是0,0 0,1 0,2 1,0 1,1

如果两个点的x或y坐标相等,则在一条直线上,需要封堵。
或者|x1-x2|=|y1-y2|,刚在一条斜线上,需要封堵。

Ⅵ vb6.0 need help

代码太长,发不了,,你加我吧,,Q号就是我的名字的连接地址最后的数字号

Ⅶ VC++ 编程题 "井字棋"游戏设计(高手请进)

#include <stdio.h>
#include <stdlib.h> #define SIZE 3
typedef enum {CBLANK, CBLACK, CWHITE} CHESS;
typedef enum {GM_WIN, GM_LOST, GM_UNKNOW, GM_ERROR} GAMEFLAG;void init_board(CHESS board[SIZE][SIZE]) //初始化
{
int i, j;
for (i = 0; i < SIZE; i++)
{
for (j = 0; j < SIZE; j++)
{
board[i][j] = CBLANK;
}
}
}void print_chess(CHESS board[SIZE][SIZE]) //打印棋盘
{
int i, j;

putchar(' ');
for (i=0; i < SIZE; i++)
{
printf("%2d", i+1);
}
putchar('\n');

for (i=0; i < SIZE; i++)
{
printf("%-2d", i+1);
for (j=0; j < SIZE; j++)
{
switch (board[i][j])
{
case CWHITE:
putchar('O');
break;
case CBLACK:
putchar('*');
break;
case CBLANK:
putchar('_');
break;
default:
putchar('?');
break;
}
putchar(' ');
}
putchar('\n');
}
}void swc(CHESS chess, int *black, int *white, int *bmax, int *wmax) //判断
{
switch (chess)
{
case CBLACK:
*white = 0;
(*black)++;
break;
case CWHITE:
*black = 0;
(*white)++;
break;
case CBLANK:
*black = 0;
*white = 0;
break;
default:
break;
} if (*black > *bmax) *bmax = *black;
if (*white > *wmax) *wmax = *white;
}
GAMEFLAG res(CHESS board[SIZE][SIZE]) //判断输赢
{
int i, j;
int win[4] = {0, 0, 0, 0};
int rblack, rwhite, cblack, cwhite,
loblack = 0, lowhite = 0,
roblack = 0, rowhite = 0,
bmax = 0, wmax = 0; for (i=0; i < SIZE; i++)
{
rblack = 0;
rwhite = 0;
cblack = 0;
cwhite = 0; swc(board[i][i], &loblack, &lowhite, &bmax, &wmax);
swc(board[i][SIZE-i-1], &roblack, &rowhite, &bmax, &wmax); for (j=0; j < SIZE; j++)
{
swc(board[i][j], &rblack, &rwhite, &bmax, &wmax);
swc(board[j][i], &cblack, &cwhite, &bmax, &wmax); } } if (bmax >= 3)
{
if (wmax >= 3)
{
return GM_ERROR;
}
else
{
return GM_WIN;
}
}
else
{
if (wmax >= 3)
{
return GM_LOST;
}
else
{
return GM_UNKNOW;
}
}}int move(CHESS board[SIZE][SIZE], CHESS chs, int x, int y)
{
int bs = 1;
if (board[x][y])
bs = 0;
else if (y >= SIZE || y < 0 || x >= SIZE || x < 0)
bs = 0;
else
board[x][y] = chs;

return bs;
}int main()
{
CHESS b[SIZE][SIZE];
char *msg[] = {"BLACK WIN!\n", "WHITE LOST!", "NOT YET", "ERROR!!"};
char *plr[] = {"NON", "BLACK", "WHITE"};
CHESS p = CBLACK;
GAMEFLAG flg;

init_board(b);
while ((flg = res(b)) == GM_UNKNOW)
{
int x, y, bmv = 1;
system("cls");
print_chess(b);
while (bmv)
{
printf("%s回合,输入坐标:", plr[p]);
scanf("%d%d", &x, &y);
bmv = !move(b,p,x-1,y-1);
}
p = (CHESS)(CWHITE + CBLACK - p);
}

printf("%s", msg[flg]);
system("pause");

return 0;
}

Ⅷ 用VB做井字过三关中的一个问题

按你这样写的话,你有想过有多少组可以进行胜利呢??
横的,竖的,斜的,而你这这样的话只有一种情况.?
而且你的代码有错.
【设计思路】

首先,我们要知道,“井字棋”游戏是一款典型的棋类游戏,游戏时一方式是电脑,另一方是玩家。所以,这类游戏在开始时有两种方式:一种是玩家先走;另一种是电脑先走。这是我们要考虑的第一个问题。

其次,由于与玩家对战的是计算机,所以我们要编写一个过程(出棋),它可以使程序模拟人的思维与人下棋(其实就是“人工智能”的体现),这个Chuqi过程也是本游戏软件的关键。此外,我们还要编写两个过程(连线和输赢),连线过程用来时刻判断棋盘中是否有三个棋子连成一线;输赢过程用来判断如果有三个棋子连成一线,是哪一方连成一线的,即判断哪一方获胜。
以上几个问题就是该“井字棋”游戏实现的关键思路

定义棋盘格子数据结构
Private Type Wells
Wells_X As Long
Wells_Y As Long
Wells_Value As Integer
End Type

定义棋盘格子的实例数组
Private usrWells(1 To 9) As Wells

定义响应点击操作的逻辑棋盘格子代号数组
Private intWellsIndex(1 To 3, 1 To 3) As Integer

定义玩家的玩过的盘数和积分
Private lngPlayerTurn As Integer, lngPlayerScore As Long

定义游戏开始标志
Private blnGameStart As Boolean

定义玩家胜利和失败标志
Private blnPlayerWin As Boolean, blnPlayerLost As Boolean

定义枚举常量标识玩家类型
Private Enum Player
MAN = 0
COMPUTER = 1
End Enum

该过程用于显示游戏信息
Private Sub Form_Load()
Me.Show
Me.Caption = "BS井字游戏 — (版本 " & App.Major & "." & App.Minor & "." & App.Revision & ")"
End Sub

该过程用于重新开始开始游戏
Private Sub cmdGameStart_Click()
blnGameStart = True
lngPlayerTurn = lngPlayerTurn + 1
Me.picWells.Cls
Call subGameInitialize
Call subScreenRefresh
End Sub

该过程用于显示游戏规则
Private Sub CmdGameRules_Click()
Beep
MsgBox " BS井字游戏:一个最简单的智力游戏,您将与机" & Chr(13) & _
"器在9个格子大小的棋盘上一决高下。由您先开始" & Chr(13) & _
"和机器轮流,每次在任意的空格上下一枚棋子。先" & Chr(13) & _
"在棋盘上横向、纵向或对角线上排成三枚相同棋子" & Chr(13) & _
"的一方即可获得游戏的胜利,祝您好运!!", 0 + 64, "游戏规则"
End Sub

该过程用于显示游戏开发信息
Private Sub cmdAbout_Click()
Beep
MsgBox "BS井字游戏" & "(V-" & App.Major & "." & App.Minor & "版本)" & Chr(13) & Chr(13) & _
"" & Chr(13) & Chr(13) & _
"由PigheadPrince设计制作" & Chr(13) & _
"CopyRight(C)2002,BestSoft.TCG", 0, "关于本游戏"
End Sub

该过程用于退出游戏
Private Sub cmdExit_Click()
Beep
msg = MsgBox("您要退出本游戏吗?", 4 + 32, "BS井字游戏")
If msg = 6 Then End
End Sub

该过程用于实现玩家向井字棋盘中下棋子
Private Sub picWells_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lngGetWells_X As Long, lngGetWells_Y As Long
Dim blnWellsNotFull As Boolean
If Not blnGameStart Then Exit Sub
lngGetWells_X = Int(Y / (Me.picWells.Height / 3)) + 1
lngGetWells_Y = Int(X / (Me.picWells.Width / 3)) + 1
If usrWells(intWellsIndex(lngGetWells_X, lngGetWells_Y)).Wells_Value = 0 Then
usrWells(intWellsIndex(lngGetWells_X, lngGetWells_Y)).Wells_Value = 1
Me.picWells.PaintPicture Me.imgChequer(MAN).Picture, _
usrWells(intWellsIndex(lngGetWells_X, lngGetWells_Y)).Wells_X, _
usrWells(intWellsIndex(lngGetWells_X, lngGetWells_Y)).Wells_Y, _
Me.picWells.Width / 3, Me.picWells.Height / 3
If funPlayerWinIF(MAN) Then
Beep
MsgBox "恭喜,您胜利了!", , "BS井字游戏"
lngPlayerScore = lngPlayerScore + 100
Call subScreenRefresh
blnGameStart = False
Else
blnPlayerTurn = False
For i = 1 To 9
If usrWells(i).Wells_Value = 0 Then blnWellsNotFull = True
Next i
If blnWellsNotFull Then
Call subComputerDoing
Else
Beep
MsgBox "和局!", , "BS井字游戏"
blnGameStart = False
End If
End If
End If
End Sub

该自定义子过程用于游戏数据初始化
Private Sub subGameInitialize()
intWellsIndex(1, 1) = 1
intWellsIndex(1, 2) = 2
intWellsIndex(1, 3) = 3
intWellsIndex(2, 1) = 4
intWellsIndex(2, 2) = 5
intWellsIndex(2, 3) = 6
intWellsIndex(3, 1) = 7
intWellsIndex(3, 2) = 8
intWellsIndex(3, 3) = 9
For i = 1 To 7 Step 3
usrWells(i).Wells_X = 0
Next i
For i = 2 To 8 Step 3
usrWells(i).Wells_X = Me.picWells.Width * (1 / 3)
Next i
For i = 3 To 9 Step 3
usrWells(i).Wells_X = Me.picWells.Width * (2 / 3)
Next i
For i = 1 To 3 Step 1
usrWells(i).Wells_Y = 0
Next i
For i = 4 To 6 Step 1
usrWells(i).Wells_Y = Me.picWells.Height * (1 / 3)
Next i
For i = 7 To 9 Step 1
usrWells(i).Wells_Y = Me.picWells.Height * (2 / 3)
Next i
For i = 1 To 9
usrWells(i).Wells_Value = 0
Next i
End Sub

该自定义子过程用于游戏开始时刷新屏幕
Private Sub subScreenRefresh()
Me.lblPlayerTurns.Caption = lngPlayerTurn
Me.lblPlayerScore.Caption = lngPlayerScore
Me.picWells.Line (0, Me.picWells.Height * (1 / 3))-(Me.picWells.Width, Me.picWells.Height * (1 / 3)), vbBlack
Me.picWells.Line (0, Me.picWells.Height * (2 / 3))-(Me.picWells.Width, Me.picWells.Height * (2 / 3)), vbBlack
Me.picWells.Line (Me.picWells.Width * (1 / 3), 0)-(Me.picWells.Width * (1 / 3), Me.picWells.Height), vbBlack
Me.picWells.Line (Me.picWells.Width * (2 / 3), 0)-(Me.picWells.Width * (2 / 3), Me.picWells.Height), vbBlack
End Sub

该自定义子过程用于执行机器的下子
Private Sub subComputerDoing()
Randomize
Dim lngGetWells_X As Long, lngGetWells_Y As Long
Dim intPCFirstWells As Integer
Dim blnPCWellsExists As Boolean
Dim intPCWells As Integer
For i = 1 To 9 Step 1
If usrWells(i).Wells_Value = -1 Then
blnPCWellsExists = True
End If
Next i
If Not blnPCWellsExists Then
GoTo GetPCFirstWells:
Else
GoTo GetPCNextWells:
End If

GetPCFirstWells: 随机获得机器的第一个落子位置
intPCFirstWells = Int((9 - 1 + 1) * Rnd + 1)
If usrWells(intPCFirstWells).Wells_Value <> 0 Then
GoTo GetPCFirstWells:
Else
intPCWells = intPCFirstWells
End If
GoTo GoOn:

GetPCNextWells: 获得机器下一步的落子位置
intPCWells = funGetPCWells

GoOn: 绘制落子并判断胜利
usrWells(intPCWells).Wells_Value = -1
lngGetWells_X = usrWells(intPCWells).Wells_X
lngGetWells_Y = usrWells(intPCWells).Wells_Y
Me.picWells.PaintPicture Me.imgChequer(COMPUTER).Picture, lngGetWells_X, lngGetWells_Y, _
Me.picWells.Width / 3, Me.picWells.Height / 3
If funPlayerWinIF(COMPUTER) Then
Beep
MsgBox "抱歉,您失败了!", , "BS井字游戏"
lngPlayerScore = lngPlayerScore - 100
If lngPlayerScore < 0 Then lngPlayerScore = 0
Call subScreenRefresh
blnGameStart = False
Else
blnPlayerTurn = True
End If
End Sub

该自定义函数用于判断玩家是否胜利
Private Function funPlayerWinIF(PlayerType As Integer) As Boolean
Dim intWinCase(1 To 8) As Integer
intWinCase(1) = usrWells(1).Wells_Value + usrWells(2).Wells_Value + usrWells(3).Wells_Value
intWinCase(2) = usrWells(4).Wells_Value + usrWells(5).Wells_Value + usrWells(6).Wells_Value
intWinCase(3) = usrWells(7).Wells_Value + usrWells(8).Wells_Value + usrWells(9).Wells_Value
intWinCase(4) = usrWells(1).Wells_Value + usrWells(4).Wells_Value + usrWells(7).Wells_Value
intWinCase(5) = usrWells(2).Wells_Value + usrWells(5).Wells_Value + usrWells(8).Wells_Value
intWinCase(6) = usrWells(3).Wells_Value + usrWells(6).Wells_Value + usrWells(9).Wells_Value
intWinCase(7) = usrWells(1).Wells_Value + usrWells(5).Wells_Value + usrWells(9).Wells_Value
intWinCase(8) = usrWells(3).Wells_Value + usrWells(5).Wells_Value + usrWells(7).Wells_Value
Select Case PlayerType
Case MAN
If intWinCase(1) = 3 Or intWinCase(2) = 3 Or intWinCase(3) = 3 Or intWinCase(4) = 3 Or _
intWinCase(5) = 3 Or intWinCase(6) = 3 Or intWinCase(7) = 3 Or intWinCase(8) = 3 Then
blnPlayerWin = True
blnPlayerLost = False
funPlayerWinIF = blnPlayerWin
End If
Case COMPUTER
If intWinCase(1) = -3 Or intWinCase(2) = -3 Or intWinCase(3) = -3 Or intWinCase(4) = -3 Or _
intWinCase(5) = -3 Or intWinCase(6) = -3 Or intWinCase(7) = -3 Or intWinCase(8) = -3 Then
blnPlayerWin = False
blnPlayerLost = True
funPlayerWinIF = blnPlayerLost
End If
End Select
End Function

该自定义函数用于返回机器的落子
Private Function funGetPCWells() As Integer
Dim intWells(1 To 8) As Integer, intPCRandomWells As Integer
intWells(1) = usrWells(1).Wells_Value + usrWells(2).Wells_Value + usrWells(3).Wells_Value
intWells(2) = usrWells(4).Wells_Value + usrWells(5).Wells_Value + usrWells(6).Wells_Value
intWells(3) = usrWells(7).Wells_Value + usrWells(8).Wells_Value + usrWells(9).Wells_Value
intWells(4) = usrWells(1).Wells_Value + usrWells(4).Wells_Value + usrWells(7).Wells_Value
intWells(5) = usrWells(2).Wells_Value + usrWells(5).Wells_Value + usrWells(8).Wells_Value
intWells(6) = usrWells(3).Wells_Value + usrWells(6).Wells_Value + usrWells(9).Wells_Value
intWells(7) = usrWells(1).Wells_Value + usrWells(5).Wells_Value + usrWells(9).Wells_Value
intWells(8) = usrWells(3).Wells_Value + usrWells(5).Wells_Value + usrWells(7).Wells_Value
如果任何一线已有机器的两个子并且另外一格仍空,机器方即将成一线
机器落子的结果等于该空格
If intWells(1) = -2 Then
For i = 1 To 3 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(2) = -2 Then
For i = 4 To 6 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(3) = -2 Then
For i = 7 To 9 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(4) = -2 Then
For i = 1 To 7 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(5) = -2 Then
For i = 2 To 8 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(6) = -2 Then
For i = 3 To 9 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(7) = -2 Then
For i = 1 To 9 Step 4
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(8) = -2 Then
For i = 3 To 7 Step 2
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
End If
如果任何一线已有玩家方两个子并且另外一格仍空,防止玩家方作成一线
机器落子的结果等于该空格
If intWells(1) = 2 Then
For i = 1 To 3 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(2) = 2 Then
For i = 4 To 6 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(3) = 2 Then
For i = 7 To 9 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(4) = 2 Then
For i = 1 To 7 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(5) = 2 Then
For i = 2 To 8 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(6) = 2 Then
For i = 3 To 9 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(7) = 2 Then
For i = 1 To 9 Step 4
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(8) = 2 Then
For i = 3 To 7 Step 2
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
End If
如果任何一线已有机器方一个子并且另外两格仍空,作成机器方的两个子
机器落子的结果等于该空格
If intWells(1) = -1 Then
For i = 1 To 3 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(2) = -1 Then
For i = 4 To 6 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(3) = -1 Then
For i = 7 To 9 Step 1
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(4) = -1 Then
For i = 1 To 7 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(5) = -1 Then
For i = 2 To 8 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(6) = -1 Then
For i = 3 To 9 Step 3
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(7) = -1 Then
For i = 1 To 9 Step 4
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
ElseIf intWells(8) = -1 Then
For i = 3 To 7 Step 2
If usrWells(i).Wells_Value = 0 Then
funGetPCWells = i
Exit Function
End If
Next i
End If
面临和局,随机在空白的格子内落子
GetRandomWells:
Randomize
intPCRandomWells = Int((9 - 1 + 1) * Rnd + 1)
If usrWells(intPCRandomWells).Wells_Value = 0 Then
funGetPCWells = intPCRandomWells
Else
GoTo GetRandomWells:
End If
End Function

Ⅸ 用VB设置井字棋程序并给出代码注释

代码:
Private Sub command1_Click()
ChessBoard.Enabled = True
Command1.Enabled = False
DrawChessBoard
If MsgBox("你要先行吗?", vbInformation + vbYesNo, "提示") = vbNo Then
Compute
End If
End Sub
Private Sub DrawChessBoard()
Dim x As Long, y As Long
ChessBoard.Cls
For x = 1000 To 3000 Step 1000
For y = 1000 To 3000 Step 1000
ChessBoard.Line (x, 0)-(x, y)
ChessBoard.Line (0, y)-(x, y)
Next
Next
End Sub
Private Sub DrawChess(ByVal x As Long, ByVal y As Long, ByVal who As Boolean)
If who = 0 Then ChessBoard.FillColor = vbBlue Else ChessBoard.FillColor = vbRed
ch(x, y) = True
x = x - 1: y = y - 1
ChessBoard.Circle (x * 1000 + 500, y * 1000 + 500), 300, vbWhite
End Sub
Private Sub Compute()
If IsEnded Then
MsgBox "和棋了!", vbInformation, "提示"
ReInit
Exit Sub
End If
Dim x As Long, y As Long, cnum As Integer
'进攻
'\\\\\
For x = 1 To 3
y = x
If ch(x, y) = 1 Then Exit For
If ch(x, y) = 2 Then cnum = cnum + 1
Next
If cnum = 2 Then
For x = 1 To 3
y = x
If ch(x, y) = 0 Then Call Win(x, y): Exit Sub
Next

Ⅹ vb编写井字棋

Rem 棋盘初始化
Private Sub gameInit()
Dim k As Integer

For k = 0 To 8
a(k \ 3, k Mod 3) = 0
Next
mnuRed.Enabled = True
mnuBlue.Enabled = True
Me.Caption = IIf(rbFirst, "井字棋:现在是红方先走!", "井字棋:现在是蓝方先走!")
Call Picture1_Paint
End Sub

Rem 棋局结束
Private Sub gameOver(ByVal result As String, k As Integer)
MsgBox result
k = 0
Call gameInit
End Sub

完整的代码已经给你了

阅读全文

与如何用vb编程井字棋相关的资料

热点内容
苹果四S万能钥匙怎么破不开 浏览:603
网络打印机共享怎么连接 浏览:313
fme系统找不到指定文件 浏览:301
iphoneid和密码忘了怎么办 浏览:238
苹果电脑优盘里的文件如何加密 浏览:284
word标题名和文件名一致 浏览:957
excel修改后的文件保持了怎么恢复 浏览:340
社保网络认证怎么弄 浏览:92
苹果手机怎么传数据到新手机相册 浏览:50
5s升级ios92无服务 浏览:354
ubuntu翻译工具 浏览:665
wifi安装教程 浏览:398
苹果有些qq文件打不开 浏览:139
微信分身图片缓存在哪个文件 浏览:544
众筹用什么网站 浏览:1
天马座的幻想版本 浏览:536
微云保存文件图片没有了 浏览:236
如何把excel表格图片导出到文件夹 浏览:387
qq三国快速升级攻略 浏览:660
js监听手机home事件 浏览:439

友情链接