晚上有空点写了一点点,明天继续 第一步,初始化工作,可选择并移动蓝色棋子 Public arr, a Private Sub Image8_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) For i = 1 To 3 For ii = 1 To 3 If X > arr(i, ii, 2) And X < arr(i, ii, 2) + 100 And Y > arr(i, ii, 3) And Y < arr(i, ii, 3) + 100 Then If arr(i, ii, 4) = -1 Then If a <> 0 Then Me.Controls(a).SpecialEffect = fmSpecialEffectFlat '重选棋子 a = arr(i, ii, 1) Me.Controls(a).SpecialEffect = fmSpecialEffectBump Else a = arr(i, ii, 1) Me.Controls(a).SpecialEffect = fmSpecialEffectBump End If End If If arr(i, ii, 4) = 0 And a <> 0 Then For iii = 1 To 3 For iiii = 1 To 3 If arr(iii, iiii, 1) = a Then X = iii Y = iiii End If Next iiii Next iii If X = i And Y = ii Then Exit Sub If Abs(X - i) > 1 Or Abs(Y - ii) > 1 Then Exit Sub Call 移动棋子(X, Y, i, ii) End If End If Next ii Next i End Sub Private Sub UserForm_Activate() Call 初始化_Click End Sub Private Sub 初始化_Click() Dim i As Long Dim ii As Long 行宽 = 122 列宽 = 122 ReDim arr(0 To 4, 0 To 4, 1 To 4) '分别记录棋子图片控件名称,位置 For i = 1 To 3 '位置 For ii = 1 To 3 arr(i, ii, 2) = 20 + (ii - 1) * 行宽 arr(i, ii, 3) = 25 + (i - 1) * 列宽 Next ii Next i '将棋子图片名称载入数组 arr(1, 1, 1) = "Image2" arr(1, 2, 1) = "Image3" arr(1, 3, 1) = "Image4" arr(3, 1, 1) = "Image5" arr(3, 2, 1) = "Image6" arr(3, 3, 1) = "Image7" '1代表蓝色棋子,-1代表黑化棋子 arr(1, 1, 4) = 1 arr(1, 2, 4) = 1 arr(1, 3, 4) = 1 arr(3, 1, 4) = -1 arr(3, 2, 4) = -1 arr(3, 3, 4) = -1 For i = 1 To 3 For ii = 1 To 3 If arr(i, ii, 1) <> "" Then Me.Controls(arr(i, ii, 1)).Left = arr(i, ii, 2) Me.Controls(arr(i, ii, 1)).Top = arr(i, ii, 3) Me.Controls(arr(i, ii, 1)).SpecialEffect = fmSpecialEffectFlat End If Next ii Next i End Sub Sub 移动棋子(X, Y, xx, yy) a = arr(X, Y, 1) arr(xx, yy, 1) = arr(X, Y, 1) arr(xx, yy, 4) = arr(X, Y, 4) Me.Controls(a).Left = arr(xx, yy, 2) Me.Controls(a).Top = arr(xx, yy, 3) arr(X, Y, 1) = 0 arr(X, Y, 4) = 0 Me.Controls(a).SpecialEffect = fmSpecialEffectFlat a = 0 End Sub
1vSrjcI6.rar
(50.4 KB, 下载次数: 51)
[此贴子已经被作者于2007-11-27 23:22:59编辑过] |