00001 VERSION 5.00
00002 Begin VB.Form Form1
00003 Caption = "TittyMemory"
00004 ClientHeight = 5010
00005 ClientLeft = 60
00006 ClientTop = 345
00007 ClientWidth = 6930
00008 Icon = "Form1.frx":0000
00009 KeyPreview = -1 'True
00010 LinkTopic = "Form1"
00011 ScaleHeight = 5010
00012 ScaleWidth = 6930
00013 StartUpPosition = 3 'Windows Default
00014 Begin VB.Timer Timer2
00015 Interval = 200
00016 Left = 5760
00017 Top = 120
00018 End
00019 Begin VB.CommandButton Command2
00020 Caption = "Settings"
00021 Height = 375
00022 Left = 1320
00023 TabIndex = 3
00024 Top = 120
00025 Width = 1095
00026 End
00027 Begin VB.Timer Timer1
00028 Enabled = 0 'False
00029 Interval = 200
00030 Left = 3720
00031 Top = 120
00032 End
00033 Begin VB.PictureBox Picture1
00034 Height = 4095
00035 Left = 120
00036 ScaleHeight = 4035
00037 ScaleWidth = 6675
00038 TabIndex = 1
00039 Top = 840
00040 Width = 6735
00041 End
00042 Begin VB.CommandButton Command1
00043 Caption = "New Game"
00044 Height = 375
00045 Left = 120
00046 TabIndex = 0
00047 Top = 120
00048 Width = 1095
00049 End
00050 Begin VB.Image Image2
00051 Height = 615
00052 Left = 4920
00053 Picture = "Form1.frx":0442
00054 Top = 120
00055 Visible = 0 'False
00056 Width = 780
00057 End
00058 Begin VB.Label Label2
00059 Caption = "Time:"
00060 Height = 255
00061 Left = 2520
00062 TabIndex = 2
00063 Top = 120
00064 Visible = 0 'False
00065 Width = 975
00066 End
00067 Begin VB.Image Image1
00068 Height = 495
00069 Left = 4320
00070 Top = 120
00071 Visible = 0 'False
00072 Width = 495
00073 End
00074 End
00075 Attribute VB_Name = "Form1"
00076 Attribute VB_GlobalNameSpace = False
00077 Attribute VB_Creatable = False
00078 Attribute VB_PredeclaredId = True
00079 Attribute VB_Exposed = False
00080 Option Explicit
00081
00082 Dim square() As MemoCard
00083 Dim initOK As Boolean
00084 Dim firstClick As Boolean
00085 Public cardName As String
00086 Public deckName As String
00087 Public squareMaxX As Long
00088 Public squareMaxY As Long
00089 Public attempts As Long
00090 Public elapsedTime As Long
00091 Public dirty As Boolean
00092 Dim startTime As Single
00093 Dim mutexNewGame As Boolean
00094
00095 Private Sub Command1_Click()
00096 mutexNewGame = True
00097 firstClick = False
00098 newGame
00099 mutexNewGame = False
00100 End Sub
00101
00102 Private Sub Command2_Click()
00103 Dim oldCardName As String
00104 Dim oldDeckName As String
00105 Dim oldMaxX As Long
00106 Dim oldMaxY As Long
00107 oldCardName = cardName
00108 oldDeckName = deckName
00109 oldMaxX = squareMaxX
00110 oldMaxY = squareMaxY
00111 If Not (mutexNewGame) Then
00112 Dialog.Show vbModal, Me
00113 DoEvents
00114 If (oldCardName <> cardName) Then
00115 Picture1.Cls
00116 dirty = True
00117 Command1_Click
00118 ElseIf (oldMaxX <> squareMaxX Or oldMaxY <> squareMaxY) Then
00119 Picture1.Cls
00120 dirty = True
00121 Command1_Click
00122 ElseIf (oldDeckName <> deckName) Then
00123 Image1.Picture = getPic(deckName, -1)
00124 End If
00125 End If
00126 Me.Refresh
00127 End Sub
00128
00129 Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
00130 If (KeyCode = vbKeyF5) Then
00131 Form_Resize
00132 KeyCode = 0
00133 End If
00134 End Sub
00135
00136 Private Sub Form_Load()
00137 cardName = "cardPussy"
00138 deckName = "deckAcorn"
00139 squareMaxX = 4
00140 squareMaxY = 4
00141 dirty = True
00142 End Sub
00143
00144 Sub newGame()
00145 initOK = False
00146 If dirty Then
00147 ReDim square(squareMaxX, squareMaxY)
00148 makeSquare
00149 dirty = False
00150 End If
00151 initGame
00152 End Sub
00153
00154 Sub initGame()
00155 clearSquare
00156 randomizeSquare
00157 rePosSquare
00158 drawSquare
00159 initOK = True
00160 startTime = Timer
00161 attempts = 0
00162 elapsedTime = 0
00163 Timer1.Enabled = True
00164 End Sub
00165
00166 Sub clearSquare()
00167 Dim x As Long
00168 Dim y As Long
00169 For x = 0 To UBound(square, 1) - 1
00170 For y = 0 To UBound(square, 2) - 1
00171 square(x, y).isFound = False
00172 square(x, y).isOpen = False
00173 Next y
00174 Next x
00175 End Sub
00176
00177 Sub makeSquare()
00178 Dim x As Long
00179 Dim y As Long
00180 Dim i As Long
00181 Dim picCount As Long
00182 If Not (FormProgress.Visible) Then FormProgress.Show
00183 FormProgress.setMax (UBound(square, 1) * UBound(square, 2)) / 2
00184 For x = 0 To UBound(square, 1) - 1
00185 For y = 0 To UBound(square, 2) - 1
00186 Set square(x, y) = New MemoCard
00187 If (i Mod 2 = 0) Then
00188 Image1.Picture = getPic(cardName, picCount)
00189 If (Image1.Picture = 0) Then
00190 cardName = "(select new)"
00191 If Not (Dialog.Visible) Then Dialog.Show vbModal, Me
00192 Image1.Picture = getPic(cardName, picCount)
00193 End If
00194 picCount = picCount + 1
00195 FormProgress.update picCount
00196 End If
00197 Set square(x, y).pic = Image1.Picture
00198 square(x, y).fName = cardName & picCount
00199 i = i + 1
00200 DoEvents
00201 Next y
00202 Next x
00203 Image1.Picture = getPic(deckName, -1)
00204 If (Image1.Picture = 0) Then
00205 deckName = "(select new)"
00206 If Not (Dialog.Visible) Then Dialog.Show vbModal, Me
00207 Image1.Picture = getPic(deckName, -1)
00208 End If
00209 Unload FormProgress
00210 End Sub
00211
00212 Function getPic(fName As String, Optional count As Long) As IPictureDisp
00213 On Error GoTo Hell
00214 Dim path As String
00215 If (count = -1) Then
00216 path = App.path & "\pics\" & fName & ".jpg"
00217 Else
00218 path = App.path & "\pics\" & fName & Format(count, "00") & ".jpg"
00219 End If
00220 If (Dir(path) = "") Then
00221 MsgBox "Cannot find file: " & vbNewLine & _
00222 path & vbNewLine & _
00223 "Please read the 'ReadMe.txt' file.", _
00224 vbCritical, "TittyMemory"
00225 Set getPic = Nothing
00226 Else
00227 Set getPic = LoadPicture(path)
00228 End If
00229 Exit Function
00230 Hell:
00231 MsgBox "Error while loading file: " & vbNewLine & _
00232 path & vbNewLine & _
00233 "Please read the 'ReadMe.txt' file.", _
00234 vbCritical, "TittyMemory"
00235 Unload Me
00236 End Function
00237
00238 Sub randomizeSquare()
00239 Dim swap As New MemoCard
00240 Dim x1 As Long
00241 Dim y1 As Long
00242 Dim x2 As Long
00243 Dim y2 As Long
00244 Dim i As Long
00245 Dim maxX As Long
00246 Dim maxY As Long
00247 maxX = UBound(square, 1) - 1
00248 maxY = UBound(square, 2) - 1
00249 Randomize
00250 For i = 1 To (maxX * maxY)
00251 x1 = Rnd() * maxX
00252 y1 = Rnd() * maxY
00253 x2 = Rnd() * maxX
00254 y2 = Rnd() * maxY
00255 Set swap = square(x1, y1)
00256 Set square(x1, y1) = square(x2, y2)
00257 Set square(x2, y2) = swap
00258 Next i
00259 End Sub
00260
00261 Sub drawSquare()
00262 Dim x As Long
00263 Dim y As Long
00264 Picture1.Cls
00265 For x = 0 To UBound(square, 1) - 1
00266 For y = 0 To UBound(square, 2) - 1
00267 drawPic x, y
00268 Next y
00269 Next x
00270 End Sub
00271
00272 Sub drawPic(x As Long, y As Long)
00273 Dim w As Long
00274 Dim h As Long
00275 w = square(x, y).x2 - square(x, y).x1
00276 h = square(x, y).y2 - square(x, y).y1
00277 If (w < 50 Or h < 50) Then Exit Sub
00278 If (square(x, y).isFound Or square(x, y).isOpen) Then
00279 If (square(x, y).pic <> 0) Then
00280 Picture1.PaintPicture square(x, y).pic, _
00281 square(x, y).x1, square(x, y).y1, _
00282 w, h
00283 Else
00284 Picture1.PaintPicture Image2.Picture, _
00285 square(x, y).x1, square(x, y).y1, _
00286 w, h
00287 End If
00288 Else
00289 If (Image1.Picture <> 0) Then
00290 Picture1.PaintPicture Image1.Picture, _
00291 square(x, y).x1, square(x, y).y1, _
00292 w, h
00293 Else
00294 Picture1.PaintPicture Image2.Picture, _
00295 square(x, y).x1, square(x, y).y1, _
00296 w, h
00297 End If
00298 End If
00299 End Sub
00300
00301 Sub rePosSquare()
00302 Dim x As Long
00303 Dim y As Long
00304 Dim w As Long
00305 Dim h As Long
00306 Dim distX As Long
00307 Dim distY As Long
00308 w = Picture1.Width
00309 h = Picture1.Height
00310 distX = w / (UBound(square, 1))
00311 distY = h / (UBound(square, 2))
00312 For x = 0 To UBound(square, 1) - 1
00313 For y = 0 To UBound(square, 2) - 1
00314 square(x, y).x1 = x * distX + 30
00315 square(x, y).y1 = y * distY + 30
00316 square(x, y).x2 = x * distX + distX - 100
00317 square(x, y).y2 = y * distY + distY - 100
00318 Next y
00319 Next x
00320 End Sub
00321
00322 Private Sub Form_Paint()
00323 If (initOK) Then
00324 drawSquare
00325 End If
00326 End Sub
00327
00328 Private Sub Form_Resize()
00329 If (WindowState <> vbMinimized) Then
00330 Picture1.Left = ScaleLeft
00331 Picture1.Top = Command1.Top + Command1.Height + 100
00332 Picture1.Width = ScaleWidth
00333 If (ScaleHeight > Picture1.Top) Then
00334 Picture1.Height = ScaleHeight - Picture1.Top
00335 End If
00336 If (initOK) Then
00337 rePosSquare
00338 drawSquare
00339 End If
00340 End If
00341 End Sub
00342
00343 Private Sub Form_Unload(Cancel As Integer)
00344 Dim f As Form
00345 For Each f In Forms
00346 Unload f
00347 Next f
00348 End Sub
00349
00350 Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
00351 Dim cardX As Long
00352 Dim cardY As Long
00353 If (initOK) Then
00354 For cardX = 0 To UBound(square, 1) - 1
00355 For cardY = 0 To UBound(square, 2) - 1
00356 If ((x > square(cardX, cardY).x1) And _
00357 (x < square(cardX, cardY).x2) And _
00358 (y > square(cardX, cardY).y1) And _
00359 (y < square(cardX, cardY).y2)) Then
00360 checkCardClick cardX, cardY
00361 End If
00362 Next cardY
00363 Next cardX
00364 End If
00365 End Sub
00366
00367 Sub checkCardClick(x As Long, y As Long)
00368 Static lastCardX As Long
00369 Static lastCardY As Long
00370 Dim time1 As Single
00371 If ((square(x, y).isFound) Or (square(x, y).isOpen)) Then
00372 Exit Sub
00373 Else
00374 attempts = attempts + 1
00375 End If
00376 If (firstClick) Then
00377 firstClick = False
00378 square(x, y).isOpen = True
00379 If (square(x, y).fName = square(lastCardX, lastCardY).fName) Then
00380 square(x, y).isFound = True
00381 square(lastCardX, lastCardY).isFound = True
00382 drawPic x, y
00383 checkGameOver
00384 Else
00385 drawPic x, y
00386 time1 = Timer
00387 Do
00388 '
00389 Loop While (Timer < time1 + 1)
00390 square(x, y).isOpen = False
00391 square(lastCardX, lastCardY).isOpen = False
00392 drawPic x, y
00393 drawPic lastCardX, lastCardY
00394 End If
00395 Else
00396 firstClick = True
00397 square(x, y).isOpen = True
00398 lastCardX = x
00399 lastCardY = y
00400 drawPic x, y
00401 End If
00402 End Sub
00403
00404 Private Sub Timer1_Timer()
00405 Static lastTime As Single
00406 If (Timer > lastTime + 1) Then
00407 Label2.Caption = "Time: " & _
00408 Format(lastTime - startTime, "00")
00409 elapsedTime = elapsedTime + 1
00410 lastTime = Timer
00411 End If
00412 End Sub
00413
00414 Private Sub Timer2_Timer()
00415 Static lastBottom As Long
00416 If (Form1.Top + Form1.Height < lastBottom) Then
00417 lastBottom = Form1.Top + Form1.Height
00418 Form_Paint
00419 End If
00420 If (Form1.Top + Form1.Height > Screen.Height - 1000) Then
00421 lastBottom = Form1.Top + Form1.Height
00422 End If
00423 End Sub
00424
00425 Sub checkGameOver()
00426 Dim x As Long
00427 Dim y As Long
00428 Dim res As VbMsgBoxResult
00429 For x = 0 To UBound(square, 1) - 1
00430 For y = 0 To UBound(square, 2) - 1
00431 If (square(x, y).isFound = False) Then Exit Sub
00432 Next y
00433 Next x
00434 Timer1.Enabled = False
00435 If Not (Dialog1.Visible) Then
00436 Dialog1.Show vbModal, Me
00437 End If
00438 End Sub
00439
00440 Public Sub redraw()
00441 Form_Paint
00442 End Sub