Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Public cardsarray(15) As PictureBox
- Public pics(15) As Image
- Public isFirstPick As Boolean
- Public firstCardNumber As Integer
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- cardsarray = {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5, PictureBox6, PictureBox7, PictureBox8, PictureBox9, PictureBox10, PictureBox11, PictureBox12, PictureBox13, PictureBox14, PictureBox15, PictureBox16}
- Call loadDeck()
- Call shuffleDeck()
- Call resetGame()
- End Sub
- Public Sub loadDeck()
- pics(0) = My.Resources.card1
- pics(1) = pics(0)
- pics(2) = My.Resources.card2
- pics(3) = pics(2)
- pics(4) = My.Resources.card3
- pics(5) = pics(4)
- pics(6) = My.Resources.card4
- pics(7) = pics(6)
- pics(8) = My.Resources.card5
- pics(9) = pics(8)
- pics(10) = My.Resources.card6
- pics(11) = pics(10)
- pics(12) = My.Resources.card7
- pics(13) = pics(12)
- pics(14) = My.Resources.card8
- pics(15) = pics(14)
- End Sub
- Public Sub shuffleDeck()
- Dim tmp As Image
- Dim x As Integer
- Dim y As Integer
- Dim generator As New Random
- For x = 0 To 15
- y = generator.Next(0, 15)
- tmp = pics(x)
- pics(x) = pics(y)
- pics(y) = tmp
- Next
- End Sub
- Public Sub resetGame()
- 'make all hidden cards visible again, with back pic
- For x = 0 To 15
- cardsarray(x).Visible = True
- cardsarray(x).Image = My.Resources.back
- Next
- Call shuffleDeck()
- isFirstPick = True
- End Sub
- Private Sub PictureBoxALL_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox5.Click, PictureBox6.Click, PictureBox7.Click, PictureBox8.Click, PictureBox9.Click, PictureBox10.Click, PictureBox11.Click, PictureBox12.Click, PictureBox13.Click, PictureBox14.Click, PictureBox15.Click, PictureBox16.Click
- Dim index As Integer
- 'get which card number was clicked
- index = Array.IndexOf(cardsarray, sender)
- 'show the picture
- cardsarray(index).Image = pics(index)
- cardsarray(index).Refresh()
- 'do the matching logic
- If isFirstPick = True Then
- firstCardNumber = index
- isFirstPick = False
- Else
- Threading.Thread.Sleep(1000)
- If (pics(firstCardNumber) Is pics(index)) Then
- cardsarray(firstCardNumber).Visible = False
- cardsarray(index).Visible = False
- Call checkDone()
- Else
- cardsarray(firstCardNumber).Image = My.Resources.back
- cardsarray(index).Image = My.Resources.back
- End If
- isFirstPick = True
- End If
- End Sub
- Public Sub checkDone()
- Dim done As Boolean
- done = True
- For x = 0 To 15
- If cardsarray(x).Visible = True Then
- done = False
- End If
- Next
- If done = True Then
- MsgBox("You win!")
- Call resetGame()
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement