Private Sub btnRock_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles btnRock.Click
If lblP_Score.Text = "72"
Then
End
End If
'End game when score reaches 72 and Rock is selected
lblPlayer.Text = "Rock"
'assigns player as Rock
lblAI_Comment.Text = ""
picPlayer.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\HumanRock.png"
'changes player icon to rock
lblAI.Text = Int(Rnd() * 9 + 1)
'generates a random number between 1 and 9
Select lblAI.Text
Case 1
lblAI.Text = "Rock"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIRock.png"
Case 2
lblAI.Text = "Paper"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIPaper.png"
Case 3
lblAI.Text = "Scissors"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIScissors.png"
Case 4
lblAI.Text = "Paper"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIPaper.png"
Case 5
lblAI.Text = "Scissors"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIScissors.png"
Case 6
lblAI.Text = "Rock"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIRock.png"
Case 7
lblAI.Text = "Scissors"
picAI.ImageLocation = "M:\Visual Basic\Unit
2 AoS2 Projects\PSR Vs The
Computer\AIScissors.png"
Case 8
lblAI.Text = "Paper"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIPaper.png"
Case 9
lblAI.Text = "Rock"
picAI.ImageLocation = "M:\Visual
Basic\Unit 2 AoS2 Projects\PSR Vs The
Computer\AIRock.png"
End Select
'selects random image for computer depending on the random
number generated
If
lblAI.Text = "Paper" Then
lblAI_Score.Text = lblAI_Score.Text + 1
lblAI_Comment.Text = Int(Rnd() * 3 + 1)
Select Case
lblAI_Comment.Text
Case 1
lblAI_Comment.Text = "I WIN!"
Case
2
lblAI_Comment.Text = "Superior"
& vbCrLf & "Paper!"
Case 3
lblAI_Comment.Text = "Mere"
& vbCrLf & "mortals!"
End Select
'If paper was selected, add one to the score for the AI
'Selects a winning comment to display
End If
lblTitle.Text = "Paper, Scissors,
Rock!"
If lblAI.Text = "Scissors"
Then
lblP_Score.Text = lblP_Score.Text + 1
lblAI_Comment.Text = Int(Rnd() * 3 + 1)
Select Case
lblAI_Comment.Text
Case 1
lblAI_Comment.Text = "I lost?!"
Case 2
lblAI_Comment.Text = "Not..."
& vbCrLf & "like this!"
Case 3
lblAI_Comment.Text = "Beaten by"
& vbCrLf & "a mortal!"
End Select
'If paper was selected, add one to the score for the player
'Selects a defeat comment to display
End If
lblTitle.Text = "Paper, Scissors,
Rock!"
End Sub
Private Sub
btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btnClear.Click
lblAI.Text = ""
lblAI_Score.Text = "0"
lblP_Score.Text = "0"
lblAI_Comment.Text = ""
'clear all scores and selections for both computer and
player
picPlayer.ImageLocation = ""
picAI.ImageLocation = ""
'clear all player and computer images
End Sub
Firstly, there is the function to generate a random number. This is used to generate a integer between a set range (i.e. 1-9) . This was used in conjunction with the Select Case statement function. Depending on the number which was generated, the function will perform a set task.
These two functions were used to decide the AI's decision for either Rock, Paper or Scissors. They were also used in conjunction to form the AI's winning or losing comment.
A case select is when something occurs depending on the value of an expression. In this case, when the case select detected the number in the AI label was one, it displayed Rock for the picture.
No comments:
Post a Comment