Computer vs Human Player in a Rock-Paper Scissor Game

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: design 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.
  1. ComboBox1.Items.Add("Rock")
  2.         ComboBox1.Items.Add("Paper")
  3.         ComboBox1.Items.Add("Scissors")
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.
  1.         Dim r As Random = New Random
  2.         Dim rr As Integer = r.Next(3)
  3.         Dim cChoice As Integer = rr
  4.         Dim uChoice As Integer = ComboBox1.SelectedIndex
  5.  
  6.         Dim pcChoice As String = "Rock"
  7.         If (cChoice = 1) Then pcChoice = "Paper"
  8.         If (cChoice = 2) Then pcChoice = "Scissors"
  9.         Label3.Text = pcChoice
  10.  
  11.         If (cChoice = uChoice) Then
  12.             MsgBox("Draw!")
  13.         Else
  14.             If (cChoice = 0) Then
  15.                 If (uChoice = 1) Then
  16.                     MsgBox("PC Choice: Rock" & vbNewLine & "You Win!")
  17.                 Else
  18.                     MsgBox("PC Choice: Rock" & vbNewLine & "You Lose!")
  19.                 End If
  20.             ElseIf (cChoice = 1) Then
  21.                 If (uChoice = 0) Then
  22.                     MsgBox("PC Choice: Paper" & vbNewLine & "You Lose!")
  23.                 Else
  24.                     MsgBox("PC Choice: Paper" & vbNewLine & "You Win!")
  25.                 End If
  26.             Else
  27.                 If (uChoice = 0) Then
  28.                     MsgBox("PC Choice: Scissors" & vbNewLine & "You Win!")
  29.                 Else
  30.                     MsgBox("PC Choice: Scissors" & vbNewLine & "You Lose!")
  31.                 End If
  32.             End If
  33.         End If
  34.         rr = Nothing
  35.         uChoice = Nothing
  36.         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:

output 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/BermzISware

Add new comment