Reputation: 27
context: im making a dice game, the goal is that i enter the number of throws i want ( of 2 dices at a time) when i click the button for the first time 2 dices are rolled and the total and the image of the dices that were rolled is displayed under player 1 when i click it a second time same thing but under player 2... so on until the players have both rolled the number of times i entered. https://gyazo.com/798aa46eb1eff6419811da7ca7ac8f9e link to what it looks like
problem : i dont know how to seperate the two and have 2 different totals. my idea was to somehow count the number of times the user presses the button and make it so i can set a limit (times) and use it to switch betweens textboxes, i just dont know how. thank you in advance for the help.
Picmain1.Visible = True
Picmain2.Visible = True
Picdice1.Image = Nothing
Picdice1_2.Image = Nothing
Picdice2.Image = Nothing
Picdice2_2.Image = Nothing
picdice3.Image = Nothing
picdice3_2.Image = Nothing
picdice4.Image = Nothing
picdice4_2.Image = Nothing
picdice5.Image = Nothing
picdice5_2.Image = Nothing
picdice6.Image = Nothing
picdice6_2.Image = Nothing
Integer.TryParse(NumericUpDown1.Text, fois)
nombre_aleatoire = MyRandomNumber.Next(1, 6)
nombre_aleatoire2 = MyRandomNumber.Next(1, 6)
TextBox1.Text &= Environment.NewLine & "ce jeu : " & total()
total1 += total()
lbltotal1.Text = "votre total est de :" & total1
Select Case nombre_aleatoire
Case 1
Picmain1.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-1.png")
Case 2
Picmain1.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-2-md.png")
Case 3
Picmain1.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-3-md.png")
Case 4
Picmain1.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-4.png")
Case 5
Picmain1.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-5.png")
Case 6
Picmain1.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-6.png")
End Select
REM multilinetextbox 2
nombre_aleatoire = MyRandomNumber.Next(1, 6)
nombre_aleatoire2 = MyRandomNumber.Next(1, 6)
Select Case nombre_aleatoire2
Case 1
Picmain2.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-1.png")
Case 2
Picmain2.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-2-md.png")
Case 3
Picmain2.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-3-md.png")
Case 4
Picmain2.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-4.png")
Case 5
Picmain2.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-5.png")
Case 6
Picmain2.Load("F:\new documents\Visual Studio 2015\Projects\mi-session\mi-session\Resources\dice-6.png")
End Select
TextBox2.Text &= Environment.NewLine & "ce jeu : " & total()
total2 += total()
Lbltotal2.Text = "votre total est de :" & total2
End Sub
End Class
Upvotes: 0
Views: 46
Reputation: 5545
You could use a variable and switch it each time like so..
Private _Player as byte = 1
...In your button click
IF _Player = 1 THEN
Textbox1.Text = [Something]
_Player = 2
else
Textbox2.Text = [Something]
_Player = 1
End if
Or if you are going to track the number of rolls anyway, you can use the MOD
operator:
Private _Rolls as int32 = 0
...In your button click
_Rolls += 1
If _Rolls mod 2 = 1 then
Textbox1.Text = [Something]
else
Textbox2.Text = [Something]
End if
Upvotes: 1