⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.frm

📁 汉诺塔的程序源码和动画演示
💻 FRM
📖 第 1 页 / 共 2 页
字号:
If KeyCode = 114 Then Call mnuRestart_Click

'LEVO
If KeyCode = 37 Then
pozicija = pozicija - 1
If pozicija < 0 Then pozicija = 2
Image1.Left = cen(pozicija) - Image1.Width / 2
End If

'GORE
If KeyCode = 38 Then
End If

'DESNO
If KeyCode = 39 Then
pozicija = pozicija + 1
If pozicija > 2 Then pozicija = 0
Image1.Left = cen(pozicija) - Image1.Width / 2

End If

'DOLE
If KeyCode = 40 Then
End If

'SPACE
If KeyCode = 32 Then
    If Image1.Tag = -1 Then
        If poln(pozicija) <> 0 Then
        Image1.Tag = teg(pozicija, poln(pozicija))
        Image3(Image1.Tag).Visible = False
        poln(pozicija) = poln(pozicija) - 1
        Image1.Left = cen(pozicija) - Image3(Image1.Tag).Width / 2
        Image1.Picture = Image3(Image1.Tag).Picture
        If Timer1.Enabled = False Then Timer1.Enabled = True
        End If
    Else
        If Val(teg(pozicija, poln(pozicija))) > Val(Image1.Tag) Then
            poln(pozicija) = poln(pozicija) + 1
            teg(pozicija, poln(pozicija)) = Image1.Tag
            Image3(Image1.Tag).Top = topd(poln(pozicija) - 1)
            Image3(Image1.Tag).Left = cen(pozicija) - Image3(Image1.Tag).Width / 2
            Image3(Image1.Tag).Visible = True
            Image1.Left = cen(pozicija) - ImageRez.Width / 2
            Image1.Picture = ImageRez.Picture
            Image1.Tag = -1
            moves = moves + 1
            StatusBar1.Panels(3).Text = "Moves:" + Str(moves)
            
            'KRAJ
            If Image3(0).Top = topd(level + 1) And _
                Image3(0).Left <> (cen(1) - Image3(0).Width / 2) Then
                
                If Not solut_b Then
                    level = level + 1
                    Timer1.Enabled = False
                
                    Call rezul(level - 2)
                    XMsgBox "Congratulations!!!" + vbCrLf + vbCrLf _
                    + "Level" + Str(level - 1) + " completed." + vbCrLf _
                    + "Moves: " + Str(moves) + vbCrLf _
                    + "Time: " + forma(vreme) + vbCrLf _
                    + "Next level:" + Str(level), vbOKOnly, "Hanoi Towers", _
                    , App.Path + "\drum.ANI"
                    If level = 7 Then level = 1
                    Call loading(level)
                Else
                    ShowCursor solut_b
                    XMsgBox "Now it's Your turn!!!" + vbCrLf _
                    + "", vbOKOnly, "Hanoi Towers", _
                    , App.Path + "\drum.ANI"
                   
                   Call loading(level)
                End If
            End If
            
        End If
    End If
End If

End Sub
Private Sub rezul(ll)
Dim o1, o As Boolean
o = False
o1 = o

If Val(Form5.Label4(ll)) > moves Then
o = True
End If

If forma1(Form5.Label5(ll + 6)) > vreme Then
o1 = True
End If

If o Or o1 Then
'Vnesi Ime
Form6.Show 1, Me
End If

If o Then
    Form5.Label3(ll).Caption = Label1.Caption
    Form5.Label4(ll).Caption = moves
    Form5.Label5(ll).Caption = forma(vreme)
                    Call zapisi
End If

If o1 Then
    Form5.Label3(ll + 6).Caption = Label1.Caption
    Form5.Label4(ll + 6).Caption = moves
    Form5.Label5(ll + 6).Caption = forma(vreme)
                    Call zapisi
End If

End Sub

Private Sub loading(s)
    level = s
    
    For t = 1 To level + 2
        teg(1, t) = level + 2 - t
    Next t
    teg(0, 0) = 100
    teg(1, 0) = 100
    teg(2, 0) = 100
    For t = 0 To level + 1
        Image3(level + 1 - t).Top = topd(t)
        Image3(t).Left = Image3(t).Tag
        Image3(t).Visible = True
    Next t
    If level < 6 Then
        For t = level + 2 + 1 To 8
            Image3(t - 1).Visible = False
        Next t
    End If
    poln(0) = 0
    poln(1) = level + 2
    poln(2) = 0
    pozicija = 1
    Image1.Left = cen(pozicija) - Image1.Width / 2
    moves = 0
    vreme = 0
    StatusBar1.Panels(3).Text = "Moves:" + Str(moves)
    StatusBar1.Panels(1).Text = "Level:" + Str(level)
    StatusBar1.Panels(2).Text = "Time: " + forma(vreme)
    StatusBar1.Panels(4).Text = "Min. Moves:" + Str(2 ^ (level + 2) - 1)
    Timer1.Enabled = False
    Image1.Picture = ImageRez.Picture
    Image1.Left = cen(1) - Image1.Width / 2
    solut.Enabled = True
End Sub
Private Sub Form_Load()
    Load Form5
    'Prociti rezultati
    
    Dim filenum As Integer
    Dim vntFileLine As String
    
    If Dir("C:\Windows\rezultati.DAT") = "" Then
    
    Dim dd As String
    dd = ""
    For t = 0 To 11
        dd = dd + "Name" + Trim(Str(((t Mod 6) + 1))) + Chr(5)
    Next t

    For t = 0 To 11
        dd = dd + "999" + Chr(5)
    Next t

    For t = 0 To 11
        dd = dd + "9999" + Chr(5)
    Next t

    filenum = FreeFile
    Open "C:\Windows\rezultati.DAT" For Output As filenum
         Print #filenum, dd
    Close filenum

    End If
    
    filenum = FreeFile
    Open "C:\Windows\rezultati.DAT" For Input As filenum
         Input #filenum, vntFileLine
    Close filenum
    Label2.Caption = vntFileLine
    Call razdelirezul
    
    
    For t = 0 To 7
        topd(7 - t) = 155 + 23 * t
        Image3(t).Tag = Image3(t).Left
    Next t
    For t = 0 To 2
        cen(t) = 108 + 160 * t
    Next t
    
    ' teg(shipka,pozicija na shipka)=golemina na teg   Dim teg(2, 8)
    
Call loading(1)
End Sub

Private Sub razdelirezul()
Dim o, o1
o = 0
o1 = 0
    For t1 = 0 To 11
        Form5.Label3(t1).Caption = ""
    Next t1
    For t1 = 0 To 11
        Form5.Label4(t1).Caption = ""
    Next t1
    For t1 = 0 To 11
        Form5.Label5(t1).Caption = ""
    Next t1
For t = 1 To Len(Label2.Caption)

If o1 = 0 Then
    If Mid(Label2.Caption, t, 1) = Chr(5) Then
        o = o + 1
        If o = 12 Then
            o1 = o1 + 1
            o = 0
        End If
    Else
        Form5.Label3(o).Caption = Form5.Label3(o).Caption + Mid(Label2.Caption, t, 1)
    End If
ElseIf o1 = 1 Then
    If Mid(Label2.Caption, t, 1) = Chr(5) Then
        o = o + 1
        If o = 12 Then
            o1 = o1 + 1
            o = 0
        End If
    Else
        Form5.Label4(o).Caption = Form5.Label4(o).Caption + Mid(Label2.Caption, t, 1)
    End If
Else
    If Mid(Label2.Caption, t, 1) = Chr(5) Then
        o = o + 1
        If o = 12 Then
            o1 = o1 + 1
            o = 0
        End If
    Else
        Form5.Label5(o).Caption = Form5.Label5(o).Caption + Mid(Label2.Caption, t, 1)
    End If

End If

Next t
For t = 0 To 11
    Form5.Label5(t).Caption = forma(Val(Form5.Label5(t).Caption))
Next t

End Sub

Private Function forma(v As Integer) As String
Dim s, M, C
Dim f
M = v \ 60
C = M \ 60
s = v - M * 60
M = M - C * 60
f = Format(Str(C), "00") + ":" + Format(Str(M), "00") + ":" + Format(Str(s), "00")
forma = f
End Function

Private Function forma1(o) As Integer
Dim s, M, C
C = Val(Mid(o, 1, 2))
M = Val(Mid(o, 4, 2))
s = Val(Mid(o, 7, 2))
forma1 = s + M * 60 + C * 3600
End Function
Private Sub Form_Unload(Cancel As Integer)
'Zapisi novi rezultati

End
End Sub


Private Sub mnuAbout_Click()
Form3.Show 1, Me
End Sub

Private Sub mnuExit_Click()
    Unload Me
End Sub

Private Sub mnuInst_Click()
Form4.Show 1, Me
End Sub

Private Sub mnuNew_Click()
    Form2.Show 1, Me
    Call loading(Val(Me.Tag))
End Sub

Private Sub mnuRestart_Click()
    loading (level)
End Sub

Private Sub mnuTop_Click()
    Form5.Show 1, Me
End Sub

Private Sub solut_Click()
  solut_b = True
  ShowCursor Not solut_b
  Form1.Enabled = False
  
  solve level + 2, 1, 2, 0
  
  Form1.Enabled = True
  solut_b = False
End Sub

Private Sub Timer1_Timer()
vreme = vreme + 1
StatusBar1.Panels(2).Text = "Time: " + forma(vreme)
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -