/ / converter array picturebox para string ou inteiro? - arrays, vb.net, picturebox

converter array picturebox para string ou inteiro? - arrays, vb.net, picturebox

Public Class frmMind
"Game Mastermind
Dim pbxBoard(3, 9) As PictureBox
Dim strColors() As String = {"Red", "Orange", "Yellow", "Green", "Blue", "Violet"} "Array for colors
Dim intKey(4) As Integer "Array for the mastermind"s key
Dim intCol As Integer = 0 "Subroutine for columns
Dim intRow As Integer = 0 "Subroutine for rows
Dim Red, Orange, Yellow, Green, Blue, Violet As Boolean
Private Sub frmMind_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Value As Boolean "Sets a true and false thing to do stuff
"Gets a random number for a key that the use will not see

Randomize()
Dim intRand As Integer = ((Rnd() * 5))
"Gets random numbers
intKey(0) = intRand
intKey(1) = intRand
intKey(2) = intRand
intKey(3) = intRand
"Assigns a random number from 1-6 to each row

Do Until Value = True "Checks to make sure a number is not duplicated.
If intKey(0) = intKey(1) Then
intKey(1) = ((Rnd() * 5))
ElseIf intKey(0) = intKey(2) Then
intKey(2) = ((Rnd() * 5))
ElseIf intKey(0) = intKey(3) Then
intKey(3) = ((Rnd() * 5))
ElseIf intKey(1) = intKey(2) Then
intKey(2) = ((Rnd() * 5))
ElseIf intKey(1) = intKey(3) Then
intKey(3) = ((Rnd() * 5))
ElseIf intKey(2) = intKey(3) Then
intKey(3) = ((Rnd() * 5))
Else
"All if statements above gets a new number if one has already been used.

Value = True
MessageBox.Show(intKey(0) & " " & intKey(1) & " " & intKey(2) & " " & intKey(3))
End If
Loop
"Sets the variables of strColors
If intRand = 5 Then
strColors(5) = "Violet"
ElseIf intRand = 4 Then
strColors(4) = "Blue"
ElseIf intRand = 3 Then
strColors(3) = "Green"
ElseIf intRand = 2 Then
strColors(2) = "Yellow"
ElseIf intRand = 1 Then
strColors(1) = "Orange"
Else
strColors(0) = "Red"
End If

End Sub
Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click


If  Then
MessageBox.Show("You good.")
Else
MessageBox.Show(":(")
End If

End Sub

"Creates border around peg on click. Red
Private Sub pbxPegR_Click(sender As Object, e As EventArgs) Handles pbxPegR.Click
Red = True
If Red = True Then
pbxPegR.BorderStyle = BorderStyle.FixedSingle
pbxPegY.BorderStyle = BorderStyle.None
pbxPegO.BorderStyle = BorderStyle.None
pbxPegG.BorderStyle = BorderStyle.None
pbxPegB.BorderStyle = BorderStyle.None
pbxPegP.BorderStyle = BorderStyle.None
End If
Yellow = False
Green = False
Violet = False
Blue = False
Orange = False
End Sub

Private Sub pbxJ0_Click(sender As Object, e As EventArgs) Handles pbxJ0.Click
If Red = True Then "changes the box from an empty square to a square with a red dot/piece
pbxJ0.Image = Image.FromFile("H:VB.netMasterMindpicturesCboxR.png")
pbxBoard(0, 9) = strColors(0)
ElseIf Yellow = True Then
pbxJ0.Image = Image.FromFile("H:VB.netMasterMindpicturesCboxY.png")
pbxBoard(0, 9) = strColors(2)
ElseIf Orange = True Then
pbxJ0.Image = Image.FromFile("H:VB.netMasterMindpicturesCboxO.png")
pbxBoard(0, 9) = strColors(1)
ElseIf Blue = True Then
pbxJ0.Image = Image.FromFile("H:VB.netMasterMindpicturesCboxB.png")
pbxBoard(0, 9) = strColors(4)
ElseIf Green = True Then
pbxJ0.Image = Image.FromFile("H:VB.netMasterMindpicturesCboxG.png")
pbxBoard(0, 9) = strColors(3)
ElseIf Violet = True Then
pbxJ0.Image = Image.FromFile("H:VB.netMasterMindpicturesCboxP.png")
pbxBoard(0, 9) = strColors(5)
End If
End Sub

Então o objetivo desse código é recriar um jogochamado de mentor. o usuário insere quatro cores diferentes na primeira linha e empates para adivinhar a ordem correta e cores como a chave (mentor). Temos isso para que o quadrado em branco seja substituído pela cor que o usuário seleciona. Não podemos descobrir como comparar os novos valores / cores com o do aleatório / chave. Ou como verificar se nenhuma cor é usada mais de uma vez. Por favor ajude.

Respostas:

0 para resposta № 1

Eu recomendo dar uma olhada na estrutura Color definida em System.Drawing que define muitas cores conhecidas. Incluindo aquelas que você nomeia em strColors.

Se você precisa comparar mais do que a igualdade das cores, fica um pouco mais complicado, mas comece verificando as propriedades ARGB das cores.

Programa de console simplificado:

Imports System.Drawing

Module Module1
Sub Main()
Dim a As Color = Color.Red
Dim b As Color = Color.Orange
Dim c As Color = Color.Turquoise

CheckColors(a, a)
CheckColors(a, b)
CheckColors(c, Color.FromName("Turquoise"))

Console.ReadKey()
End Sub

Private Sub CheckColors(x As Color, y As Color)
Console.WriteLine("Does " & x.Name & " equal " & y.Name & "? " & (x = y).ToString)
End Sub
End Module

Saída:

Does Red equal Red? True
Does Red equal Orange? False
Does Turquoise equal Turquoise? True