/ / converte l'array picturebox in stringa o intero? - array, vb.net, picturebox

convertire l'array picturebox in stringa o intero? - array, 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

Quindi il punto di questo codice è ricreare un giocochiamato mastermind. l'utente immette quattro colori diversi sulla prima riga e cerca di indovinare l'ordine e i colori corretti come la chiave (mastermind). Abbiamo così il quadrato vuoto sarà sostituito con il colore selezionato dall'utente. Non riusciamo a capire come confrontare i nuovi valori / colori con quelli del tasto randomizzatore / chiave. O come verificare che nessun colore venga usato più di una volta. Per favore aiuto.

risposte:

0 per risposta № 1

Ti consiglio di dare uno sguardo alla struttura del colore definita in System.Drawing, che definisce molti colori noti. strColors.

Se hai bisogno di confrontare più dell'uguaglianza dei colori, diventa un po 'più complicato ma inizia a controllare le proprietà ARGB dei colori.

Programma di console semplificato:

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

Produzione:

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