求VB编写中国象棋的源代码。急求。必有重谢

求VB编写中国象棋的源代码。急求。必有重谢,第1张

贴保存棋局和读取棋局部分的,你先看看:

Rem 读取棋局

Private Sub mnuRead_Click()

Dim s As String, i As Integer, t

If Dir(App.Path &"\cchess.che") = "" Then MsgBox "没有棋局文件可以读入!请先保存棋局!", , "中国象棋": Exit Sub

Open App.Path &"\cchess.che" For Input As #1

Input #1, s

Close #1

s = Replace(s, vbCrLf, "")

s = Trim(s)

t = Split(s, " ")

If UBound(t) <>89 Then MsgBox "棋局文件已遭到破坏!请重新保存棋局!", , "中国象棋": Exit Sub

For i = 0 To 89

a(i) = Val(t(i))

Next

MsgBox "棋局文件已成功读入!", , "中国象棋"

End Sub

Rem 保存棋局

Private Sub mnuSave_Click()

Dim s As String, i As Integer

s = ""

For i = 0 To 89

s = s &" " &a(i)

Next

s = Trim(s)

Open App.Path &"\cchess.che" For Output As #1

Print #1, s

Close #1

MsgBox "当前棋局已成功保存!", , "中国象棋"

End Sub

Private Sub Command1_Click()

s = 1

t = 1

For i = 2 To 64

  t = t + t

  s = s + t

Next i

Print "64个格子全部放完麦子,"

Print "总共为"s"粒"

End Sub

不知道你是不是就画这样一个棋盘,请在窗体上加入Picture1控件.

Private

Const

CELL_SIZE

=

60

'格子大小,单位像素

Private

Sub

Form_Load()

Picture1.AutoRedraw

=

True

Picture1.ScaleMode

=

vbPixels

'以像素为单位,作图

Picture1.BorderStyle

=

0

'无边框

Picture1.Height

=

15

*

CELL_SIZE

*

8

'棋盘大小,*15表示单位由像素变成缇

Picture1.Width

=

Picture1.Height

'长宽相同

Picture1.BackColor

=

vbWhite

'背景色,白色

Dim

i

As

Integer

For

i

=

1

To

8

Step

2

'先画黑色竖格4条

Picture1.Line

(i

*

CELL_SIZE,

0)-(i

*

CELL_SIZE

+

CELL_SIZE,

Picture1.ScaleHeight),

vbBlack,

BF

Next

Picture1.DrawMode

=

vbInvert

'下面画上去的与原有颜色相反,即黑色变成白色

For

i

=

1

To

8

Step

2

'横格4条

Picture1.Line

(0,

i

*

CELL_SIZE)-(Picture1.ScaleWidth,

i

*

CELL_SIZE

+

CELL_SIZE),

vbBlack,

BF

Next

Picture1.DrawMode

=

vbCopyPen

'画图模式变了缺省值

End

Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8068726.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存