Computer vs Human Player in a Rock-Paper Scissor Game
Submitted by donbermoy on Sunday, March 9, 2014 - 11:15.
A rock-paper-scissor game is one of the most popular kiddie games here in Surigao City. It is a simple game played around the world with many names and variations. It's a good way to decide whose turn it is to do something, and it's also played competitively. And today we will make this game and compete with a computer player.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add one Combobox named ComboBox1, three labels named Label1 labeled as “Current Choice:”, Label2 labeled as “PC Choice:” and Label3 as “ ”. Add also one button named Button1 for us to know who won the game. You must design your layout like this:
3. Add this code as your Form_Load. This will add the choices of Rock, Paper, and Scissor in our combobox as the input of the player.
4. Now put add this code for your code module. This code is for Button1_Click. This will trigger to decide who won the game.
- ComboBox1.Items.Add("Rock")
- ComboBox1.Items.Add("Paper")
- ComboBox1.Items.Add("Scissors")
- Dim r As Random = New Random
- Dim rr As Integer = r.Next(3)
- Dim cChoice As Integer = rr
- Dim uChoice As Integer = ComboBox1.SelectedIndex
- Dim pcChoice As String = "Rock"
- If (cChoice = 1) Then pcChoice = "Paper"
- If (cChoice = 2) Then pcChoice = "Scissors"
- Label3.Text = pcChoice
- If (cChoice = uChoice) Then
- Else
- If (cChoice = 0) Then
- If (uChoice = 1) Then
- Else
- End If
- ElseIf (cChoice = 1) Then
- If (uChoice = 0) Then
- Else
- End If
- Else
- If (uChoice = 0) Then
- Else
- End If
- End If
- End If
- rr = Nothing
- uChoice = Nothing
- cChoice = Nothing
Explanation:
We have initialized r variable as our random number, rr variable that will hold an integer variable of 3 as the ccChoice variable will hold this random integer value and will display the random choice in Label3. We also initialized variable uChoice as an Integer that will locate the inputted index of the Combobox. If the random input of cChoice is the same with variable uChoice, then it will display a draw. Otherwise if the random integer value of uChoice is 0 which means Rock and the inputted index value of the user in the combobox is 1 which means Paper then it will display “You Won” otherwise “You Lose” will display. If the random integer value of uChoice is 1 which means Paper and the inputted index value of the user in the combobox is 0 which means Rock then it will display “You Won” otherwise “You Lose” will display. And otherwise it will trigger to the result value if one them inputted a scissor.Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]
Visit and like my page on Facebook at: Bermz ISware Solutions
Subscribe at my YouTube Channel at: SerBermz
Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISwareAdd new comment
- 136 views