/ / конвертувати масив картинок у рядок чи ціле число? - масиви, vb.net, картинка

перетворити масив з picturebox в рядок чи ціле число? - масиви, 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

Тож сенс цього коду - відтворити груназивається натхненником. Користувач вводить чотири різних кольори в перший рядок і пов'язує, щоб відгадати правильний порядок і кольори як ключ (натур). У нас він є, тому порожній квадрат буде замінений тим, який колір обрав користувач. Ми не можемо розібратися, як порівняти нові значення / кольори з значеннями рандомізера / ключа. Або як перевірити, що жоден колір не використовується більше одного разу. Будь ласка, допоможіть.

Відповіді:

0 для відповіді № 1

Я рекомендую переглянути структуру кольорів, визначену в System.Намалювавши це визначає безліч відомих кольорів. У тому числі ті, яких ви називаєте в strColors.

Якщо вам потрібно порівняти більше, ніж рівність кольорів, це стане трохи складніше, але почніть з перевірки властивостей ARGB кольорів.

Спрощена консольна програма:

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

Вихід:

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