• We just launched and are currently in beta. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Computer vs Human Player in a Rock-Paper Scissor Game

meeksleek

Platform Monetization Strategist
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
37
Likes
47
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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:

rpsdesign.png


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. Dim

    pcChoice As

    String

    =

    "Rock"
  6. If

    (

    cChoice =

    1

    )

    Then

    pcChoice =

    "Paper"
  7. If

    (

    cChoice =

    2

    )

    Then

    pcChoice =

    "Scissors"
  8. Label3.

    Text

    =

    pcChoice

  9. If

    (

    cChoice =

    uChoice)

    Then
  10. MsgBox

    (

    "Draw!"

    )
  11. Else
  12. If

    (

    cChoice =

    0

    )

    Then
  13. If

    (

    uChoice =

    1

    )

    Then
  14. MsgBox

    (

    "PC Choice: Rock"

    &

    vbNewLine &

    "You Win!"

    )
  15. Else
  16. MsgBox

    (

    "PC Choice: Rock"

    &

    vbNewLine &

    "You Lose!"

    )
  17. End

    If
  18. ElseIf

    (

    cChoice =

    1

    )

    Then
  19. If

    (

    uChoice =

    0

    )

    Then
  20. MsgBox

    (

    "PC Choice: Paper"

    &

    vbNewLine &

    "You Lose!"

    )
  21. Else
  22. MsgBox

    (

    "PC Choice: Paper"

    &

    vbNewLine &

    "You Win!"

    )
  23. End

    If
  24. Else
  25. If

    (

    uChoice =

    0

    )

    Then
  26. MsgBox

    (

    "PC Choice: Scissors"

    &

    vbNewLine &

    "You Win!"

    )
  27. Else
  28. MsgBox

    (

    "PC Choice: Scissors"

    &

    vbNewLine &

    "You Lose!"

    )
  29. End

    If
  30. End

    If
  31. End

    If
  32. rr =

    Nothing
  33. uChoice =

    Nothing
  34. 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:

rpsoutput1_0.png

rpsoutput2.png


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


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,498

347,739

347,748

Top