 |
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1617
|
Re: Minesweeper Project: 1. MinePlacement 2. Best score Archived to Disk
1)
ReDim arrayname(x) ' where x is any number, it'll erase all contents
'ReDim Preserve arrayname(x), Preserve keeps all values previously entered
- or -
Erase arrayname()
2) (scores)
easiest: text file
next easiest: registry or ini file
easiest for sorting: Access DB
as far as sorting, in a database, just run a query. For a text file or registry type of entries, any method would work, including storing the scores and names into a list box, with a sorted property=true.
|
|
16-04-2002 at 04:56 AM |
|
|
admin Level: Administrator

 Registered: 04-04-2002 Posts: 530
|
Re: Minesweeper Project: 1. MinePlacement 2. Best score Archived to Disk
Hello,
This is my MineSweep Example...Hope you like it...
Create a Form with a little PictureBox Control Named pctCell and index it (0)
Add this code to the form:
Option Explicit
Dim XMaze As Long
Dim YMaze As Long
Dim Bomb As Long
Dim CellsLeft As Long
Private Sub InitMaze()
Dim i As Integer
Dim x As Long
Randomize Timer
For i = 0 To XMaze * YMaze - 1
With pctCell(i)
If .BorderStyle = 0 Then
.BorderStyle = 1
.Cls
.Tag = ""
End If
If .BackColor <> vb3DLight Then
.BackColor = vb3DLight
End If
.ZOrder 0
End With
Next
For i = 1 To Bomb
Do
x = CInt(Rnd * XMaze * YMaze)
Loop Until pctCell(x).Tag = ""
pctCell(x).Tag = "B"
Next
CellsLeft = (XMaze * YMaze) - Bomb
End Sub
Private Sub Form_Load()
Dim i As Integer
pctCell(0).AutoRedraw = True
pctCell(0).Font = "Verdana"
pctCell(0).FontSize = 8
pctCell(0).FontBold = True
XMaze = 15
YMaze = 15
Bomb = 45
For i = 1 To XMaze * YMaze - 1
Load pctCell(i)
pctCell(i).Move pctCell(0).Left + pctCell(0).Width * (i Mod XMaze), pctCell(0).Top + pctCell(0).Height * (i XMaze), pctCell(0).Width, pctCell(0).Height
pctCell(i).Visible = True
Next
InitMaze
End Sub
Private Sub BombCount(ByVal Index As Long)
Dim x As Integer
Dim y As Integer
Dim Count As Integer
Count = 0
pctCell(Index).Tag = "X"
For x = (Index Mod XMaze) - 1 To (Index Mod XMaze) + 1
For y = (Index XMaze) - 1 To (Index XMaze) + 1
If x >= 0 And y >= 0 And x < XMaze And y < YMaze Then
If pctCell(x + y * XMaze).Tag = "B" Then
Count = Count + 1
End If
End If
Next
Next
If Count = 0 Then
For x = (Index Mod XMaze) - 1 To (Index Mod XMaze) + 1
For y = (Index XMaze) - 1 To (Index XMaze) + 1
If x >= 0 And y >= 0 And x < XMaze And y < YMaze Then
If pctCell(x + y * XMaze).Tag = "" And pctCell(x + y * XMaze).BorderStyle = 1 Then
BombCount x + y * XMaze
End If
End If
Next
Next
End If
pctCell(Index).ZOrder 1
pctCell(Index).BorderStyle = 0
pctCell(Index).BackColor = vb3DLight
If Count > 0 Then
pctCell(Index).CurrentX = 0
pctCell(Index).CurrentY = 0
pctCell(Index).ForeColor = QBColor(Count)
pctCell(Index).Print Count
End If
CellsLeft = CellsLeft - 1
If CellsLeft = 0 Then
ShowMaze
MsgBox "You Win!", vbInformation, "You Win"
InitMaze
End If
End Sub
Private Sub ClearXTag()
Dim i As Integer
For i = 0 To XMaze * YMaze - 1
If pctCell(i).Tag = "X" Then pctCell(i).Tag = ""
Next
End Sub
Private Sub ShowMaze()
Dim i As Integer
For i = 0 To XMaze * YMaze - 1
If pctCell(i).Tag = "B" Then
pctCell(i).BackColor = vbYellow
pctCell(i).BorderStyle = 0
pctCell(i).ForeColor = vbRed
pctCell(i).CurrentX = 0
pctCell(i).CurrentY = 0
pctCell(i).Print "B"
End If
Next
End Sub
Private Sub pctCell_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
If pctCell(Index).BorderStyle = 1 Then
If Button = vbLeftButton Then
If pctCell(Index).Tag = "B" Then
pctCell(Index).BackColor = vbYellow
pctCell(Index).BorderStyle = 0
pctCell(Index).ForeColor = vbRed
pctCell(Index).CurrentX = 0
pctCell(Index).CurrentY = 0
pctCell(Index).Print "B"
ShowMaze
MsgBox "Bomb!", vbCritical, "Bomb"
InitMaze
Else
BombCount Index
ClearXTag
End If
ElseIf Button = vbRightButton Then
If pctCell(Index).BackColor = vb3DLight Then
pctCell(Index).BackColor = vbRed
ElseIf pctCell(Index).BackColor = vbRed Then
pctCell(Index).BackColor = vbBlue
Else
pctCell(Index).BackColor = vb3DLight
End If
End If
End If
End Sub |
Enjoy with it!!
Have a nice day!
____________________________
AndreaVB
|
|
16-04-2002 at 06:08 AM |
|
|
|
|
 |
 |