For instance,with 5 possible colors and 4 positions,the guess would be for the right position and with the right colors combination too...:) using an input text and assigning numbers for randomizing to colors(not string randomizing)...
Hi, what is the simplest way to write the master mind game code for visual basic?
I can't completely understand you but I think your saying you must guess between 1 to 5 and 1 to 4 and get them both right.
Place this code under a command button. It will keep asking you to guess between 1 and 5 and 1 and 4 until you get both.
Private Sub Command1_Click()
Dim OnetoFiveRandom As Integer
Dim OnetoFourRandom As Integer
Dim Inputguess1 As Integer
Dim Inputguess2 As Integer
Randomize Timer
OnetoFiveRandom = Int(Rnd * 5) + 1
OnetoFourRandom = Int(Rnd * 4) + 1
Do Until Inputguess1 = OnetoFiveRandom And Inputguess2 = OnetoFourRandom
Inputguess1 = InputBox("Guess a number between 1 and 5.", "Guess")
Inputguess2 = InputBox("Guess a number between 1 and 4.", "Guess")
If Inputguess1 = OnetoFiveRandom Then
MsgBox "Your 1 to 5 is correct"
End If
If Inputguess2 = OnetoFourRandom Then
MsgBox "Your 1 to 4 is correct"
End If
Loop
MsgBox "You win."
End Sub
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment