Support Forums
[TuT] Rock, Paper, Scissors Game [VB] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [TuT] Rock, Paper, Scissors Game [VB] (/showthread.php?tid=21092)

Pages: 1 2 3


[TuT] Rock, Paper, Scissors Game [VB] - Deceive - 08-03-2011

Hello, here is another little tutorial. This one is how to make a game of Rock, Paper, Scissors Smile
Lets get started.

What you Need:
  • 1 Combo Box
  • 1 Button (Label it "Choose")
  • 1 Label (Label it "...")

Code:
Code:
Public Class Form1
Dim userselected As Integer
Dim gameresult As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Random As New Random
Dim computerchoice = Random.Next(3)
If computerchoice = userselected Then gameresult = 0
Select Case computerchoice
Case 0
If userselected = 1 Then gameresult = 2
If userselected = 2 Then gameresult = 1
Case 1
If userselected = 0 Then gameresult = 1
If userselected = 2 Then gameresult = 2
Case 2
If userselected = 0 Then gameresult = 2
If userselected = 1 Then gameresult = 1
End Select
Select Case gameresult
Case 0
Label1.Text = "It Was A Draw"
Case 1
Label1.Text = "Bad Luck! Computer Wins"
Case 2
Label1.Text = "You Win!"
End Select
End Sub
End Class

It's pretty fun to play when you're bored Smile
If you want, you could also make a program with multiple games and have this in there, that's probably what I will be doing soon Smile


RE: [TuT] Rock, Paper, Scissors Game [VB] - BreShiE - 08-03-2011

I'm thinking about learning VB.NET, I just got so used to VB6.


RE: [TuT] Rock, Paper, Scissors Game [VB] - Deceive - 08-03-2011

(08-03-2011, 06:35 PM)BreShiE Wrote: I'm thinking about learning VB.NET, I just got so used to VB6.

It's a great thing to learn, it got me started in a bunch of stuff.
Coding in VB helped me realize what coding really is, before that, I was in Notepad making batch files :/


RE: [TuT] Rock, Paper, Scissors Game [VB] - AceInfinity - 08-03-2011

You have a lot of unnecessary code in this one. Also you wouldn't even need the combo box lol, it's just there to make it look like those random results are based off your choice from the combobox lol.

Here's the cleaner code though:
Code:
Public Class Form1
    Dim userselected As Integer
    Dim gameresult As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.SelectedIndex = 0
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Random As New Random
        'Random value with max 3
        Dim computerchoice = Random.Next(3)

        'Finding the game result
        Select Case computerchoice
            Case 0
                If computerchoice = userselected Then gameresult = 0
            Case 1
                If userselected = 0 Then gameresult = 1
            Case 2
                If userselected = 0 Then gameresult = 2
        End Select

        'Outputting proof of the game result to the label
        Select Case gameresult
            Case 0
                Label1.Text = "It Was A Draw"
            Case 1
                Label1.Text = "Bad Luck! Computer Wins"
            Case 2
                Label1.Text = "You Win!"
        End Select
    End Sub
End Class

You did not need this: (Highlighted in red)
Quote:Public Class Form1
Dim userselected As Integer
Dim gameresult As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Random As New Random
Dim computerchoice = Random.Next(3)
If computerchoice = userselected Then gameresult = 0
Select Case computerchoice
Case 0
If userselected = 1 Then gameresult = 2
If userselected = 2 Then gameresult = 1

Case 1
If userselected = 0 Then gameresult = 1
If userselected = 2 Then gameresult = 2
Case 2
If userselected = 0 Then gameresult = 2
If userselected = 1 Then gameresult = 1
End Select
Select Case gameresult
Case 0
Label1.Text = "It Was A Draw"
Case 1
Label1.Text = "Bad Luck! Computer Wins"
Case 2
Label1.Text = "You Win!"
End Select
End Sub
End Class

Why? Because userselected is just defined as an integer. There is no changing value. It will always be "0"


RE: [TuT] Rock, Paper, Scissors Game [VB] - Caffeine - 08-06-2011

Nice man. Really good effort here.


RE: [TuT] Rock, Paper, Scissors Game [VB] - Kotto*N[ix]mouth - 08-06-2011

Haha, that's neat. Thanks for sharing this, this could be fun to look at.


RE: [TuT] Rock, Paper, Scissors Game [VB] - Blue Screen of Death - 08-11-2011

haha, you made me laughBig Grin
Great invention though.


RE: [TuT] Rock, Paper, Scissors Game [VB] - Scream - 08-13-2011

Nice tutorial Tongue.
I will take a closer look, and try it now Smile


RE: [TuT] Rock, Paper, Scissors Game [VB] - LiveModz - 08-25-2011

this is nice but kind of useless. but nice tut


RE: [TuT] Rock, Paper, Scissors Game [VB] - The Flash - 08-25-2011

Hey, That is pretty cool. Thx for the share dude!