How To Make a Rock Paper Scissors Game Project Using Visual Basic .Net
In this VB.NET Tutorial we will see How To Make a Simple Rock, Paper, Scissors Game Using Panels and PictureBoxes In Visual Basic.Net Programming Language And Visual Studio Editor.
Project Source Code:
Public Class Game_Form
Dim rock As Bitmap = My.Resources.rock
Dim paper As Bitmap = My.Resources.paper
Dim scissors As Bitmap = My.Resources.scissors
Dim random_picture As Bitmap
Dim player_wins As Integer = 0, computer_wins As Integer = 0
Dim list As ArrayList = New ArrayList()
Dim random As Random = New Random()
Private Sub Game_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pictureBoxRock.Image = My.Resources.rock
pictureBoxPaper.Image = My.Resources.paper
pictureBoxScissors.Image = My.Resources.scissors
list.Add(rock)
list.Add(paper)
list.Add(scissors)
End Sub
Public Sub getWinner(ByVal player As Bitmap, ByVal computer As Bitmap)
If player.Equals(computer) Then
ElseIf player.Equals(rock) Then
If computer.Equals(scissors) Then
player_wins += 1
label_PlayerWins.Text = player_wins.ToString()
Else
computer_wins += 1
label_ComputerWins.Text = computer_wins.ToString()
End If
ElseIf player.Equals(paper) Then
If computer.Equals(rock) Then
player_wins += 1
label_PlayerWins.Text = player_wins.ToString()
Else
computer_wins += 1
label_ComputerWins.Text = computer_wins.ToString()
End If
ElseIf player.Equals(scissors) Then
If computer.Equals(paper) Then
player_wins += 1
label_PlayerWins.Text = player_wins.ToString()
Else
computer_wins += 1
label_ComputerWins.Text = computer_wins.ToString()
End If
End If
End Sub
Private Sub pictureBoxRock_Click(sender As Object, e As EventArgs) Handles pictureBoxRock.Click
pictureBox_player.Image = rock
random_picture = CType(list(random.[Next](list.Count)), Bitmap)
pictureBox_computer.Image = random_picture
getWinner(rock, random_picture)
End Sub
Private Sub pictureBoxPaper_Click(sender As Object, e As EventArgs) Handles pictureBoxPaper.Click
pictureBox_player.Image = paper
random_picture = CType(list(random.[Next](list.Count)), Bitmap)
pictureBox_computer.Image = random_picture
getWinner(paper, random_picture)
End Sub
Private Sub pictureBoxScissors_Click(sender As Object, e As EventArgs) Handles pictureBoxScissors.Click
pictureBox_player.Image = scissors
random_picture = CType(list(random.[Next](list.Count)), Bitmap)
pictureBox_computer.Image = random_picture
getWinner(scissors, random_picture)
End Sub
End Class
OutPut:
if you want the source code click on the download button below
Download Projects Source Code