cassisdesign
06-14-2009, 03:51 AM
I am very new to vb. I am working on a final project for one of my classes. I have all of the game working except for displaying all of the matches once the display button is clicked.
I have it set up so that initially all of the images in my array are randomly placed into pictureBoxes and then reset to a "postIt" image:
For i = 0 To 15
'Reset the images of all the tiles to the postIt image
Tile(i).TileRef.Image = ilistCast.Images(postIt)
'Reset the Flipped, Matched and officeCastIndex variables
Tile(i).Reset()
Next i
Can anyone help me with revealing the results/ matches once the display button is clicked?
Here is what I have so far:
Public Class frmFugateFinal
Structure TileStructure
'Stores the index location of a cast member image
' in ilistCast.
Dim officeCastIndex As Integer
'True when the cast member is showing, False if
' postIt is showing.
Dim Flipped As Boolean
'True if the tile has been matched, False
' if not.
Dim Matched As Boolean
'True if ALL the tiles have been matched, False
' if not.
Dim allMatched As Boolean
'A reference to the PictureBox so we
' can change the image in it.
Dim TileRef As PictureBox
'A custom method that resets the above
' values when the player starts a
' new game.
Public Sub Reset()
officeCastIndex = -1
Flipped = False
Matched = False
allMatched = False
End Sub
End Structure
Dim Tile(16) As TileStructure
'declare
Dim startClicked As Boolean
'The value of an unassigned office cast array index is -1
Const UNASSIGNED As Integer = -1
'The postIt image is at index 8 in ilistCast image list
Const postIt As Integer = 8
'Stores the office cast array index value of the last flipped Tile
Dim iLastFlipped As Integer
'Stores the number of tiles that are flipped over
Dim iNumFlipped As Integer
'Stores the number of
Dim iNumDundies As Integer
Private Sub frmFugateFinal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' set TitleRef object reference variables
' to each picturebox
Tile(0).TileRef = picTile0
Tile(1).TileRef = picTile1
Tile(2).TileRef = picTile2
Tile(3).TileRef = picTile3
Tile(4).TileRef = picTile4
Tile(5).TileRef = picTile5
Tile(6).TileRef = picTile6
Tile(7).TileRef = picTile7
Tile(8).TileRef = picTile8
Tile(9).TileRef = picTile9
Tile(10).TileRef = picTile10
Tile(11).TileRef = picTile11
Tile(12).TileRef = picTile12
Tile(13).TileRef = picTile13
Tile(14).TileRef = picTile14
Tile(15).TileRef = picTile15
' seed the random number generator
Randomize()
End Sub
Private Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim i, iPos, iCast As Integer
Dim bLooking As Boolean
startClicked = True
'Reset total dundies score to zero
iNumDundies = 0
lblTotalDundies.Text = ""
lblGameMessage.Text = ""
'Set initial values for starting a new game
For i = 0 To 15
'Reset the images of all the tiles to the postIt image
Tile(i).TileRef.Image = ilistCast.Images(postIt)
'Reset the Flipped, Matched and officeCastIndex variables
Tile(i).Reset()
Next i
iLastFlipped = UNASSIGNED
iNumFlipped = 0
'Iterate through the office cast array index values
For iCast = 0 To 7
'Set the bLooking looping flag to
' True when the Do-Loop begins.
bLooking = True
Do
'Generate a random Tile index value
iPos = CInt(Int(Rnd() * 16))
'Check if the officeCastIndex data member of
' Tile(iPos) is unassigned.
If Tile(iPos).officeCastIndex = UNASSIGNED Then
'If officeCastIndex is unassigned, assign iCast to it
Tile(iPos).officeCastIndex = iCast
'Set the bLooking looping flag to False to
' stop looping.
bLooking = False
End If
'The bLooking looping flag will still be True if
' the officeCastIndex data member of Tile(iPos)
' was already assigned.
Loop Until bLooking = False
'Set the bLooking looping flag to True when
' the Do-Loop begins.
bLooking = True
Do
'Generate a random Tile index value
iPos = CInt(Int(Rnd() * 16))
'Check if the officeCastIndex data member of
' Tile(iPos) is unassigned.
If Tile(iPos).officeCastIndex = UNASSIGNED Then
'If officeCastIndex is unassigned, assign iFlag to it
Tile(iPos).officeCastIndex = iCast
'Set the bLooking looping flag to False to
' stop looping.
bLooking = False
End If
'The bLooking looping flag will still be True if
' the officeCastIndex data member of Tile(iPos)
' was already assigned.
Loop Until bLooking = False
Next iCast
End Sub
Private Sub TileClicked(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles picTile0.Click, _
picTile1.Click, _
picTile2.Click, _
picTile3.Click, _
picTile4.Click, _
picTile5.Click, _
picTile6.Click, _
picTile7.Click, _
picTile8.Click, _
picTile9.Click, _
picTile10.Click, _
picTile11.Click, _
picTile12.Click, _
picTile13.Click, _
picTile14.Click, _
picTile15.Click
Dim picBox As PictureBox
Dim i, Index As Integer
'Declare variable for error and correct match message labels
Dim strError As String
strError = "Sorry Try Again!"
Dim strCorrect As String
strCorrect = "You Are Correct Sir!"
Dim strWon As String
strWon = "Congrats! You Win...now get back to work!"
'Dim intTotalDundies As Integer
Dim intTotalPossiblePairs As Integer
intTotalPossiblePairs = 8
'declare a holder for the current score
Dim Score As Integer
'take current score and store it Sum
Score = CInt(Val(lblTotalDundies.Text))
'Reference sender with a PictureBox object reference
' variable so we can access the Tag property of the
' PictureBox that raised the event.
picBox = CType(sender, PictureBox)
Index = CInt(picBox.Tag)
'Don't process clicks if the tile is already flipped and the start button has been clicked.
If Tile(Index).Flipped = False AndAlso startClicked = True Then
'reset game message
lblGameMessage.Text = ""
'Flip the tile over so that the cast member is showing
Tile(Index).TileRef.Image = _
ilistCast.Images(Tile(Index).officeCastIndex)
'Set the Flipped data member to True
Tile(Index).Flipped = True
'Increment the iNumFlipped counter
iNumFlipped += 1
Select Case iNumFlipped
Case 1
'Store the flag index of the just flipped tile
iLastFlipped = Index
Case 2
'Look for a match by comparing the officeCastIndex values of the tile
' that was just flipped (Index) with the iLastFlipped tile.
If Tile(Index).officeCastIndex = Tile(iLastFlipped).officeCastIndex Then
'When a match is found, set the Matched data
' member of both tiles to True.
Tile(Index).Matched = True
Tile(iLastFlipped).Matched = True
'Increment the iNumDundies counter
iNumDundies += 1
'Display result to user
lblTotalDundies.Text = CStr(CInt(iNumDundies))
If iNumDundies < 8 Then
'Display correct message to the user
lblGameMessage.Text = strCorrect
ElseIf iNumDundies = 8 Then
'Display result to user
lblTotalDundies.Text = CStr(CInt(iNumDundies))
'Display won message to the user
lblGameMessage.Text = strWon
End If
'Clear the tile index value stored in iLastFlipped
iLastFlipped = UNASSIGNED
Else
lblGameMessage.Text = strError
End If
Case 3
'Store the cast member index of the just flipped tile and
' set iNumFlipped to 1.
iLastFlipped = Index
iNumFlipped = 1
'Scan through all the tiles and flip back over the ones
' that were not matched--except the just flipped tile.
For i = 0 To 15
If Tile(i).Matched = False And i <> Index Then
Tile(i).Flipped = False
Tile(i).TileRef.Image = ilistCast.Images(postIt)
End If
Next i
End Select
End If
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
End Sub
End Class
I have it set up so that initially all of the images in my array are randomly placed into pictureBoxes and then reset to a "postIt" image:
For i = 0 To 15
'Reset the images of all the tiles to the postIt image
Tile(i).TileRef.Image = ilistCast.Images(postIt)
'Reset the Flipped, Matched and officeCastIndex variables
Tile(i).Reset()
Next i
Can anyone help me with revealing the results/ matches once the display button is clicked?
Here is what I have so far:
Public Class frmFugateFinal
Structure TileStructure
'Stores the index location of a cast member image
' in ilistCast.
Dim officeCastIndex As Integer
'True when the cast member is showing, False if
' postIt is showing.
Dim Flipped As Boolean
'True if the tile has been matched, False
' if not.
Dim Matched As Boolean
'True if ALL the tiles have been matched, False
' if not.
Dim allMatched As Boolean
'A reference to the PictureBox so we
' can change the image in it.
Dim TileRef As PictureBox
'A custom method that resets the above
' values when the player starts a
' new game.
Public Sub Reset()
officeCastIndex = -1
Flipped = False
Matched = False
allMatched = False
End Sub
End Structure
Dim Tile(16) As TileStructure
'declare
Dim startClicked As Boolean
'The value of an unassigned office cast array index is -1
Const UNASSIGNED As Integer = -1
'The postIt image is at index 8 in ilistCast image list
Const postIt As Integer = 8
'Stores the office cast array index value of the last flipped Tile
Dim iLastFlipped As Integer
'Stores the number of tiles that are flipped over
Dim iNumFlipped As Integer
'Stores the number of
Dim iNumDundies As Integer
Private Sub frmFugateFinal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' set TitleRef object reference variables
' to each picturebox
Tile(0).TileRef = picTile0
Tile(1).TileRef = picTile1
Tile(2).TileRef = picTile2
Tile(3).TileRef = picTile3
Tile(4).TileRef = picTile4
Tile(5).TileRef = picTile5
Tile(6).TileRef = picTile6
Tile(7).TileRef = picTile7
Tile(8).TileRef = picTile8
Tile(9).TileRef = picTile9
Tile(10).TileRef = picTile10
Tile(11).TileRef = picTile11
Tile(12).TileRef = picTile12
Tile(13).TileRef = picTile13
Tile(14).TileRef = picTile14
Tile(15).TileRef = picTile15
' seed the random number generator
Randomize()
End Sub
Private Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim i, iPos, iCast As Integer
Dim bLooking As Boolean
startClicked = True
'Reset total dundies score to zero
iNumDundies = 0
lblTotalDundies.Text = ""
lblGameMessage.Text = ""
'Set initial values for starting a new game
For i = 0 To 15
'Reset the images of all the tiles to the postIt image
Tile(i).TileRef.Image = ilistCast.Images(postIt)
'Reset the Flipped, Matched and officeCastIndex variables
Tile(i).Reset()
Next i
iLastFlipped = UNASSIGNED
iNumFlipped = 0
'Iterate through the office cast array index values
For iCast = 0 To 7
'Set the bLooking looping flag to
' True when the Do-Loop begins.
bLooking = True
Do
'Generate a random Tile index value
iPos = CInt(Int(Rnd() * 16))
'Check if the officeCastIndex data member of
' Tile(iPos) is unassigned.
If Tile(iPos).officeCastIndex = UNASSIGNED Then
'If officeCastIndex is unassigned, assign iCast to it
Tile(iPos).officeCastIndex = iCast
'Set the bLooking looping flag to False to
' stop looping.
bLooking = False
End If
'The bLooking looping flag will still be True if
' the officeCastIndex data member of Tile(iPos)
' was already assigned.
Loop Until bLooking = False
'Set the bLooking looping flag to True when
' the Do-Loop begins.
bLooking = True
Do
'Generate a random Tile index value
iPos = CInt(Int(Rnd() * 16))
'Check if the officeCastIndex data member of
' Tile(iPos) is unassigned.
If Tile(iPos).officeCastIndex = UNASSIGNED Then
'If officeCastIndex is unassigned, assign iFlag to it
Tile(iPos).officeCastIndex = iCast
'Set the bLooking looping flag to False to
' stop looping.
bLooking = False
End If
'The bLooking looping flag will still be True if
' the officeCastIndex data member of Tile(iPos)
' was already assigned.
Loop Until bLooking = False
Next iCast
End Sub
Private Sub TileClicked(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles picTile0.Click, _
picTile1.Click, _
picTile2.Click, _
picTile3.Click, _
picTile4.Click, _
picTile5.Click, _
picTile6.Click, _
picTile7.Click, _
picTile8.Click, _
picTile9.Click, _
picTile10.Click, _
picTile11.Click, _
picTile12.Click, _
picTile13.Click, _
picTile14.Click, _
picTile15.Click
Dim picBox As PictureBox
Dim i, Index As Integer
'Declare variable for error and correct match message labels
Dim strError As String
strError = "Sorry Try Again!"
Dim strCorrect As String
strCorrect = "You Are Correct Sir!"
Dim strWon As String
strWon = "Congrats! You Win...now get back to work!"
'Dim intTotalDundies As Integer
Dim intTotalPossiblePairs As Integer
intTotalPossiblePairs = 8
'declare a holder for the current score
Dim Score As Integer
'take current score and store it Sum
Score = CInt(Val(lblTotalDundies.Text))
'Reference sender with a PictureBox object reference
' variable so we can access the Tag property of the
' PictureBox that raised the event.
picBox = CType(sender, PictureBox)
Index = CInt(picBox.Tag)
'Don't process clicks if the tile is already flipped and the start button has been clicked.
If Tile(Index).Flipped = False AndAlso startClicked = True Then
'reset game message
lblGameMessage.Text = ""
'Flip the tile over so that the cast member is showing
Tile(Index).TileRef.Image = _
ilistCast.Images(Tile(Index).officeCastIndex)
'Set the Flipped data member to True
Tile(Index).Flipped = True
'Increment the iNumFlipped counter
iNumFlipped += 1
Select Case iNumFlipped
Case 1
'Store the flag index of the just flipped tile
iLastFlipped = Index
Case 2
'Look for a match by comparing the officeCastIndex values of the tile
' that was just flipped (Index) with the iLastFlipped tile.
If Tile(Index).officeCastIndex = Tile(iLastFlipped).officeCastIndex Then
'When a match is found, set the Matched data
' member of both tiles to True.
Tile(Index).Matched = True
Tile(iLastFlipped).Matched = True
'Increment the iNumDundies counter
iNumDundies += 1
'Display result to user
lblTotalDundies.Text = CStr(CInt(iNumDundies))
If iNumDundies < 8 Then
'Display correct message to the user
lblGameMessage.Text = strCorrect
ElseIf iNumDundies = 8 Then
'Display result to user
lblTotalDundies.Text = CStr(CInt(iNumDundies))
'Display won message to the user
lblGameMessage.Text = strWon
End If
'Clear the tile index value stored in iLastFlipped
iLastFlipped = UNASSIGNED
Else
lblGameMessage.Text = strError
End If
Case 3
'Store the cast member index of the just flipped tile and
' set iNumFlipped to 1.
iLastFlipped = Index
iNumFlipped = 1
'Scan through all the tiles and flip back over the ones
' that were not matched--except the just flipped tile.
For i = 0 To 15
If Tile(i).Matched = False And i <> Index Then
Tile(i).Flipped = False
Tile(i).TileRef.Image = ilistCast.Images(postIt)
End If
Next i
End Select
End If
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
End Sub
End Class