Alright, this is my first time using VB, and I'm using the 2010 express edition.
What I'm trying to do is essentially a scrabble game. I created an array and loaded the images I'm using for the tiles, but I want to assign these images an integer value which I can then use as a score whenever it's placed on the board. I have a GridControl which handles the board, and a PlaceTile sub:
An array which assigns a letter
LetterSelection Sub:
PlaceTile Sub:
The problem I'm having is that I have no idea as to how to set an integer value to a picturebox, and then recall it based on what tiles are placed on the board. I was thinking something along the lines of "scoreArray(0) = CInt(letterArray(0) = 1)", and then using that to recall the value as (how I read it) scoreArray(0) should technically have set the A (letterArray(0) = A) to a 1 (The score for that tile)
Any help appreciated,
Rhys.
What I'm trying to do is essentially a scrabble game. I created an array and loaded the images I'm using for the tiles, but I want to assign these images an integer value which I can then use as a score whenever it's placed on the board. I have a GridControl which handles the board, and a PlaceTile sub:
Code:
Public Sub AddImages()
placedImageArray(0) = My.Resources.APlaced
placedImageArray(1) = My.Resources.BPlaced
placedImageArray(2) = My.Resources.CPlaced
placedImageArray(3) = My.Resources.DPlaced
placedImageArray(4) = My.Resources.EPlaced
placedImageArray(5) = My.Resources.FPlaced
placedImageArray(6) = My.Resources.GPlaced
placedImageArray(7) = My.Resources.HPlaced
placedImageArray(8) = My.Resources.IPlaced
placedImageArray(9) = My.Resources.JPlaced
placedImageArray(10) = My.Resources.KPlaced
placedImageArray(11) = My.Resources.LPlaced
placedImageArray(12) = My.Resources.MPlaced
placedImageArray(13) = My.Resources.NPlaced
placedImageArray(14) = My.Resources.OPlaced
placedImageArray(15) = My.Resources.PPlaced
placedImageArray(16) = My.Resources.QPlaced
placedImageArray(17) = My.Resources.RPlaced
placedImageArray(18) = My.Resources.SPlaced
placedImageArray(19) = My.Resources.TPlaced
placedImageArray(20) = My.Resources.UPlaced
placedImageArray(21) = My.Resources.VPlaced
placedImageArray(22) = My.Resources.WPlaced
placedImageArray(23) = My.Resources.XPlaced
placedImageArray(24) = My.Resources.YPlaced
placedImageArray(25) = My.Resources.ZPlaced
Return
End Sub
Code:
letterArray(0) = "A"
letterArray(1) = "B"
letterArray(2) = "C"
letterArray(3) = "D"
letterArray(4) = "E"
letterArray(5) = "F"
letterArray(6) = "G"
letterArray(7) = "H"
letterArray(8) = "I"
letterArray(9) = "J"
letterArray(10) = "K"
letterArray(11) = "L"
letterArray(12) = "M"
letterArray(13) = "N"
letterArray(14) = "O"
letterArray(15) = "P"
letterArray(16) = "Q"
letterArray(17) = "R"
letterArray(18) = "S"
letterArray(19) = "T"
letterArray(20) = "U"
letterArray(21) = "V"
letterArray(22) = "W"
letterArray(23) = "X"
letterArray(24) = "Y"
letterArray(25) = "Z"
Code:
Private Sub FillPictureBox()
'Randomizes the letters which are then put into the
'scrabble holder during the game
Randomize()
Dim Random As Integer
Dim Count As Integer
For Count = 0 To 6
Random = CInt(Int(26 * Rnd()))
'Random = Int((CInt(Int(25 * Rnd()) + 1) + Random) / 2) - We did this, but eventually considered it as unnecessary.
If playerIndex = 1 Then
If Player1LetterArray(Count) = 0 Then
Player1LetterArray(Count) = Random
End If
ElseIf playerIndex = 2 Then
If Player2LetterArray(Count) = 0 Then
Player2LetterArray(Count) = Random
End If
End If
Next (Count)
'Sets the picturebox's to an image depending on what was
'randomly chosen
If playerIndex = 1 Then
Label1.Font = New Font("Microsoft Sans Serif", 13, FontStyle.Underline)
Label2.Font = New Font("Microsoft Sans Serif", 13, FontStyle.Regular)
PictureBox2.Image = imageArray(Player1LetterArray(0))
PictureBox3.Image = imageArray(Player1LetterArray(1))
PictureBox4.Image = imageArray(Player1LetterArray(2))
PictureBox5.Image = imageArray(Player1LetterArray(3))
PictureBox6.Image = imageArray(Player1LetterArray(4))
PictureBox7.Image = imageArray(Player1LetterArray(5))
PictureBox8.Image = imageArray(Player1LetterArray(6))
ElseIf playerIndex = 2 Then
Label1.Font = New Font("Microsoft Sans Serif", 13, FontStyle.Regular)
Label2.Font = New Font("Microsoft Sans Serif", 13, FontStyle.Underline)
PictureBox2.Image = imageArray(Player2LetterArray(0))
PictureBox3.Image = imageArray(Player2LetterArray(1))
PictureBox4.Image = imageArray(Player2LetterArray(2))
PictureBox5.Image = imageArray(Player2LetterArray(3))
PictureBox6.Image = imageArray(Player2LetterArray(4))
PictureBox7.Image = imageArray(Player2LetterArray(5))
PictureBox8.Image = imageArray(Player2LetterArray(6))
End If
End Sub
PlaceTile Sub:
Code:
Public Sub PlaceTile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlaceTile.Click
Dim MessageBox As String
Static PlaceTile_Click As Boolean
'Add a count for how many tiles are placed
PlaceCounter.Text = PlaceCounter.Text + 1
If PlaceCounter.Text = 1 Then
'Determines if the first tile was placed
'in the centre of the board
If X1.Text = "8" And Y1.Text = "8" Then
GoTo Place
Else
'If the first tile is not placed
'in the centre, an error message
'is displayed.
MessageBox = MsgBox("Tile must be placed on the centre tile (X: 8, Y: 8)")
If PlaceTile_Click Then
PlaceTile_Click = False
End If
If (X1.Text <> "8") And (Y1.Text <> "8") Then
PlaceCounter.Text = 0
Else
PlaceCounter.Text = 1
End If
End If
Else
Place:
Dim X1Var As Integer
Dim Y1Var As Integer
'Converts 15 x 15 entry data to pixels for placement
X1Var = (X1.Text * 30 - 30)
Y1Var = (Y1.Text * 30 - 30)
'Checks if the entered number in X1 or Y1 is below 1 or above 15
If X1Var > (14 * 30) Or (X1Var < 0) Then
MessageBox = MsgBox("X-Coordinate is out of range.")
End If
If Y1Var > (14 * 30) Or (Y1Var < 0) Then
MessageBox = MsgBox("Y-Coordinate is out of range")
End If
'Selects which tile is placed depending
'on which picturebox is selected
Select Case SelectedPictureBox
Case 1
For Count = 1 To 25
If PictureBox2.Image.Equals(clickedImageArray(Count)) Then
PlacedTile = placedImageArray(Count)
End If
Next
'Sets the picturebox to a null image
'after the tile is placed
PictureBox2.Image = Nothing
If playerIndex = 1 Then
Player1LetterArray(0) = 0
ElseIf playerIndex = 2 Then
Player2LetterArray(0) = 0
End If
Case 2
For Count = 1 To 25
If PictureBox3.Image.Equals(clickedImageArray(Count)) Then
PlacedTile = placedImageArray(Count)
End If
Next
PictureBox3.Image = Nothing
If playerIndex = 1 Then
Player1LetterArray(1) = 0
ElseIf playerIndex = 2 Then
Player2LetterArray(1) = 0
End If
Case 3
For Count = 1 To 25
If PictureBox4.Image.Equals(clickedImageArray(Count)) Then
PlacedTile = placedImageArray(Count)
End If
Next
PictureBox4.Image = Nothing
If playerIndex = 1 Then
Player1LetterArray(2) = 0
ElseIf playerIndex = 2 Then
Player2LetterArray(2) = 0
End If
Case 4
For Count = 1 To 25
If PictureBox5.Image.Equals(clickedImageArray(Count)) Then
PlacedTile = placedImageArray(Count)
End If
Next
PictureBox5.Image = Nothing
If playerIndex = 1 Then
Player1LetterArray(3) = 0
ElseIf playerIndex = 2 Then
Player2LetterArray(3) = 0
End If
Case 5
For Count = 1 To 25
If PictureBox6.Image.Equals(clickedImageArray(Count)) Then
PlacedTile = placedImageArray(Count)
End If
Next
PictureBox6.Image = Nothing
If playerIndex = 1 Then
Player1LetterArray(4) = 0
ElseIf playerIndex = 2 Then
Player2LetterArray(4) = 0
End If
Case 6
For Count = 1 To 25
If PictureBox7.Image.Equals(clickedImageArray(Count)) Then
PlacedTile = placedImageArray(Count)
End If
Next
PictureBox7.Image = Nothing
If playerIndex = 1 Then
Player1LetterArray(5) = 0
ElseIf playerIndex = 2 Then
Player2LetterArray(5) = 0
End If
Case 7
For Count = 1 To 25
If PictureBox8.Image.Equals(clickedImageArray(Count)) Then
PlacedTile = placedImageArray(Count)
End If
Next
PictureBox8.Image = Nothing
If playerIndex = 1 Then
Player1LetterArray(6) = 0
ElseIf playerIndex = 2 Then
Player2LetterArray(6) = 0
End If
End Select
'This control placed the letter on the board
'with dimensions 31x31
GridControl1.addLetter(PlacedTile, X1Var, Y1Var, Height = 31, Width = 31)
'Remove data from the textboxes
X1.Text = ""
Y1.Text = ""
End If
End Sub
Any help appreciated,
Rhys.