Advertisement
TermSpar

Rock Paper Scissors game by Ben Bollinger

Oct 9th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 17.49 KB | None | 0 0
  1. Form Design: https://plus.google.com/b/115806511419535531782/115806511419535531782/posts/GcBWSg2YxRv?pageId=115806511419535531782&hl=en&pid=6205320338051650082&oid=115806511419535531782
  2. ---------------------------------------------------------------------------------------------------------------------------------
  3. Public Class Form1
  4.     Dim Input As Integer
  5.     Dim wins As Integer
  6.     Dim loses As Integer
  7.     Dim ties As Integer
  8.     Dim best10 As Integer
  9.     Dim best5 As Integer
  10.  
  11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.         pbCompPaper.Hide()
  13.         pbCompRock.Hide()
  14.         pbCompScissors.Hide()
  15.         pbScissors.Hide()
  16.         pbPaper.Hide()
  17.         pbRock.Hide()
  18.         Dim r As Rectangle
  19.         If Parent IsNot Nothing Then
  20.             r = Parent.RectangleToScreen(Parent.ClientRectangle)
  21.         Else
  22.             r = Screen.FromPoint(Me.Location).WorkingArea
  23.         End If
  24.  
  25.         Dim x = r.Left + (r.Width - Me.Width) \ 2
  26.         Dim y = r.Top + (r.Height - Me.Height) \ 2
  27.         Me.Location = New Point(x, y)
  28.         best10 = False
  29.         best5 = False
  30.     End Sub
  31.  
  32.     Private Sub btnScissors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScissors.Click
  33.         pbScissors.Show()
  34.         pbPaper.Hide()
  35.         pbRock.Hide()
  36.         Randomize()
  37.         Dim computer As Double
  38.  
  39.         Input = 3
  40.         computer = Rnd()
  41.         computer = Int(Rnd() * 3) + 1
  42.         If computer <= 3 And computer > 2 And Input = 3 Then
  43.             lblDisply.Text = "It's a tie"
  44.             Me.BackColor = Color.RoyalBlue
  45.             ties = Val(lblTies.Text) + 1
  46.             lblTies.Text = ties
  47.             pbCompPaper.Hide()
  48.             pbCompRock.Hide()
  49.             pbCompScissors.Show()
  50.         ElseIf computer <= 1 And Input = 3 Then
  51.             lblDisply.Text = "Computer chose rock, you lost!"
  52.             Me.BackColor = Color.Red
  53.             loses = Val(lblLoses.Text) + 1
  54.             lblLoses.Text = loses
  55.             pbCompPaper.Hide()
  56.             pbCompRock.Show()
  57.             pbCompScissors.Hide()
  58.         ElseIf computer > 1 And computer <= 2 And Input = 3 Then
  59.             lblDisply.Text = "Computer chose paper, you win!"
  60.             Me.BackColor = Color.Green
  61.             wins = Val(lblWins.Text) + 1
  62.             lblWins.Text = wins
  63.             pbCompPaper.Show()
  64.             pbCompRock.Hide()
  65.             pbCompScissors.Hide()
  66.         End If
  67.         If best10 = True And wins >= 10 Then
  68.             MsgBox("You Won")
  69.             lblDisply.Text = "Click a button "
  70.             Me.BackColor = Color.RoyalBlue
  71.             Form1_Load(Me, New System.EventArgs)
  72.             Me.Text = "RPS (Mode: Default)"
  73.             lblDisply.Text = "Click a button "
  74.             Me.BackColor = Color.RoyalBlue
  75.             Form1_Load(Me, New System.EventArgs)
  76.             lblLoses.Text = "0"
  77.             lblTies.Text = "0"
  78.             lblWins.Text = "0"
  79.             Button2.PerformClick()
  80.         End If
  81.         If best10 = True And loses >= 10 Then
  82.             MsgBox("You Lost")
  83.             lblDisply.Text = "Click a button "
  84.             Me.BackColor = Color.RoyalBlue
  85.             Form1_Load(Me, New System.EventArgs)
  86.             Me.Text = "RPS (Mode: Default)"
  87.             lblDisply.Text = "Click a button "
  88.             Me.BackColor = Color.RoyalBlue
  89.             Form1_Load(Me, New System.EventArgs)
  90.             lblLoses.Text = "0"
  91.             lblTies.Text = "0"
  92.             lblWins.Text = "0"
  93.             Button2.PerformClick()
  94.         End If
  95.         If best5 = True And wins >= 5 Then
  96.             MsgBox("You Won")
  97.             lblDisply.Text = "Click a button "
  98.             Me.BackColor = Color.RoyalBlue
  99.             Form1_Load(Me, New System.EventArgs)
  100.             Me.Text = "RPS (Mode: Default)"
  101.             lblDisply.Text = "Click a button "
  102.             Me.BackColor = Color.RoyalBlue
  103.             Form1_Load(Me, New System.EventArgs)
  104.             lblLoses.Text = "0"
  105.             lblTies.Text = "0"
  106.             lblWins.Text = "0"
  107.             Button2.PerformClick()
  108.         End If
  109.         If best5 = True And loses >= 5 Then
  110.             MsgBox("You Lost")
  111.             lblDisply.Text = "Click a button "
  112.             Me.BackColor = Color.RoyalBlue
  113.             Form1_Load(Me, New System.EventArgs)
  114.             Me.Text = "RPS (Mode: Default)"
  115.             lblDisply.Text = "Click a button "
  116.             Me.BackColor = Color.RoyalBlue
  117.             Form1_Load(Me, New System.EventArgs)
  118.             lblLoses.Text = "0"
  119.             lblTies.Text = "0"
  120.             lblWins.Text = "0"
  121.             Button2.PerformClick()
  122.         End If
  123.         If best5 = True And ties >= 5 Then
  124.             MsgBox("You Tied")
  125.             lblDisply.Text = "Click a button "
  126.             Me.BackColor = Color.RoyalBlue
  127.             Form1_Load(Me, New System.EventArgs)
  128.             Me.Text = "RPS (Mode: Default)"
  129.             lblDisply.Text = "Click a button "
  130.             Me.BackColor = Color.RoyalBlue
  131.             Form1_Load(Me, New System.EventArgs)
  132.             lblLoses.Text = "0"
  133.             lblTies.Text = "0"
  134.             lblWins.Text = "0"
  135.             Button2.PerformClick()
  136.         End If
  137.         If best10 = True And ties >= 10 Then
  138.             MsgBox("You Tied")
  139.             lblDisply.Text = "Click a button "
  140.             Me.BackColor = Color.RoyalBlue
  141.             Form1_Load(Me, New System.EventArgs)
  142.             Me.Text = "RPS (Mode: Default)"
  143.             lblDisply.Text = "Click a button "
  144.             Me.BackColor = Color.RoyalBlue
  145.             Form1_Load(Me, New System.EventArgs)
  146.             lblLoses.Text = "0"
  147.             lblTies.Text = "0"
  148.             lblWins.Text = "0"
  149.             Button2.PerformClick()
  150.         End If
  151.  
  152.     End Sub
  153.  
  154.     Private Sub btnPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaper.Click
  155.         pbScissors.Hide()
  156.         pbRock.Hide()
  157.         pbPaper.Show()
  158.         Randomize()
  159.         Dim computer As Double
  160.  
  161.         Input = 2
  162.         computer = Rnd()
  163.         computer = Int(Rnd() * 3) + 1
  164.         If computer <= 2 And computer > 1 And Input = 2 Then
  165.             lblDisply.Text = "It's a tie"
  166.             Me.BackColor = Color.RoyalBlue
  167.             ties = Val(lblTies.Text) + 1
  168.             lblTies.Text = ties
  169.             pbCompPaper.Show()
  170.             pbCompRock.Hide()
  171.             pbCompScissors.Hide()
  172.         ElseIf computer <= 1 And Input = 2 Then
  173.             lblDisply.Text = "Computer chose rock, you win!"
  174.             Me.BackColor = Color.Green
  175.             wins = Val(lblWins.Text) + 1
  176.             lblWins.Text = wins
  177.             pbCompPaper.Hide()
  178.             pbCompRock.Show()
  179.             pbCompScissors.Hide()
  180.         ElseIf computer >= 2 And computer <= 3 And Input = 2 Then
  181.             lblDisply.Text = "Computer chose scissors, you lost"
  182.             Me.BackColor = Color.Red
  183.             loses = Val(lblLoses.Text) + 1
  184.             lblLoses.Text = loses
  185.             pbCompPaper.Hide()
  186.             pbCompRock.Hide()
  187.             pbCompScissors.Show()
  188.         End If
  189.         If best10 = True And wins >= 10 Then
  190.             MsgBox("You Won")
  191.             lblDisply.Text = "Click a button "
  192.             Me.BackColor = Color.RoyalBlue
  193.             Form1_Load(Me, New System.EventArgs)
  194.             Me.Text = "RPS (Mode: Default)"
  195.             lblDisply.Text = "Click a button "
  196.             Me.BackColor = Color.RoyalBlue
  197.             Form1_Load(Me, New System.EventArgs)
  198.             lblLoses.Text = "0"
  199.             lblTies.Text = "0"
  200.             lblWins.Text = "0"
  201.             Button2.PerformClick()
  202.         End If
  203.         If best10 = True And loses >= 10 Then
  204.             MsgBox("You Lost")
  205.             lblDisply.Text = "Click a button "
  206.             Me.BackColor = Color.RoyalBlue
  207.             Form1_Load(Me, New System.EventArgs)
  208.             Me.Text = "RPS (Mode: Default)"
  209.             lblDisply.Text = "Click a button "
  210.             Me.BackColor = Color.RoyalBlue
  211.             Form1_Load(Me, New System.EventArgs)
  212.             lblLoses.Text = "0"
  213.             lblTies.Text = "0"
  214.             lblWins.Text = "0"
  215.             Button2.PerformClick()
  216.         End If
  217.         If best5 = True And wins >= 5 Then
  218.             MsgBox("You Won")
  219.             lblDisply.Text = "Click a button "
  220.             Me.BackColor = Color.RoyalBlue
  221.             Form1_Load(Me, New System.EventArgs)
  222.             Me.Text = "RPS (Mode: Default)"
  223.             lblDisply.Text = "Click a button "
  224.             Me.BackColor = Color.RoyalBlue
  225.             Form1_Load(Me, New System.EventArgs)
  226.             lblLoses.Text = "0"
  227.             lblTies.Text = "0"
  228.             lblWins.Text = "0"
  229.             Button2.PerformClick()
  230.         End If
  231.         If best5 = True And loses >= 5 Then
  232.             MsgBox("You Lost")
  233.             lblDisply.Text = "Click a button "
  234.             Me.BackColor = Color.RoyalBlue
  235.             Form1_Load(Me, New System.EventArgs)
  236.             Me.Text = "RPS (Mode: Default)"
  237.             lblDisply.Text = "Click a button "
  238.             Me.BackColor = Color.RoyalBlue
  239.             Form1_Load(Me, New System.EventArgs)
  240.             lblLoses.Text = "0"
  241.             lblTies.Text = "0"
  242.             lblWins.Text = "0"
  243.             Button2.PerformClick()
  244.         End If
  245.         If best5 = True And ties >= 5 Then
  246.             MsgBox("You Tied")
  247.             lblDisply.Text = "Click a button "
  248.             Me.BackColor = Color.RoyalBlue
  249.             Form1_Load(Me, New System.EventArgs)
  250.             Me.Text = "RPS (Mode: Default)"
  251.             lblDisply.Text = "Click a button "
  252.             Me.BackColor = Color.RoyalBlue
  253.             Form1_Load(Me, New System.EventArgs)
  254.             lblLoses.Text = "0"
  255.             lblTies.Text = "0"
  256.             lblWins.Text = "0"
  257.             Button2.PerformClick()
  258.         End If
  259.         If best10 = True And ties >= 10 Then
  260.             MsgBox("You Tied")
  261.             lblDisply.Text = "Click a button "
  262.             Me.BackColor = Color.RoyalBlue
  263.             Form1_Load(Me, New System.EventArgs)
  264.             Me.Text = "RPS (Mode: Default)"
  265.             lblDisply.Text = "Click a button "
  266.             Me.BackColor = Color.RoyalBlue
  267.             Form1_Load(Me, New System.EventArgs)
  268.             lblLoses.Text = "0"
  269.             lblTies.Text = "0"
  270.             lblWins.Text = "0"
  271.             Button2.PerformClick()
  272.         End If
  273.     End Sub
  274.  
  275.     Private Sub btnRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRock.Click
  276.         pbPaper.Hide()
  277.         pbScissors.Hide()
  278.         pbRock.Show()
  279.         Randomize()
  280.         Dim computer As Double
  281.  
  282.         Input = 1
  283.         computer = Rnd()
  284.         computer = Int(Rnd() * 3) + 1
  285.         If computer <= 1 And Input = 1 Then
  286.             lblDisply.Text = "It's a tie"
  287.             Me.BackColor = Color.RoyalBlue
  288.             ties = Val(lblTies.Text) + 1
  289.             lblTies.Text = ties
  290.             pbCompPaper.Hide()
  291.             pbCompRock.Show()
  292.             pbCompScissors.Hide()
  293.         ElseIf computer > 1 And computer <= 2 And Input <= 1 Then
  294.             lblDisply.Text = "Computer chose paper, you lost!"
  295.             Me.BackColor = Color.Red
  296.             loses = Val(lblLoses.Text) + 1
  297.             lblLoses.Text = loses
  298.             pbCompPaper.Show()
  299.             pbCompRock.Hide()
  300.             pbCompScissors.Hide()
  301.         ElseIf computer > 2 And Input = 1 Then
  302.             lblDisply.Text = "Computer chose scissors, you win!"
  303.             Me.BackColor = Color.Green
  304.             wins = Val(lblWins.Text) + 1
  305.             lblWins.Text = wins
  306.             pbCompPaper.Hide()
  307.             pbCompRock.Hide()
  308.             pbCompScissors.Show()
  309.         End If
  310.         If best10 = True And wins >= 10 Then
  311.             MsgBox("You Won")
  312.             lblDisply.Text = "Click a button "
  313.             Me.BackColor = Color.RoyalBlue
  314.             Form1_Load(Me, New System.EventArgs)
  315.             Me.Text = "RPS (Mode: Default)"
  316.             lblDisply.Text = "Click a button "
  317.             Me.BackColor = Color.RoyalBlue
  318.             Form1_Load(Me, New System.EventArgs)
  319.             lblLoses.Text = "0"
  320.             lblTies.Text = "0"
  321.             lblWins.Text = "0"
  322.             Button2.PerformClick()
  323.         End If
  324.         If best10 = True And loses >= 10 Then
  325.             MsgBox("You Lost")
  326.             lblDisply.Text = "Click a button "
  327.             Me.BackColor = Color.RoyalBlue
  328.             Form1_Load(Me, New System.EventArgs)
  329.             Me.Text = "RPS (Mode: Default)"
  330.             lblDisply.Text = "Click a button "
  331.             Me.BackColor = Color.RoyalBlue
  332.             Form1_Load(Me, New System.EventArgs)
  333.             lblLoses.Text = "0"
  334.             lblTies.Text = "0"
  335.             lblWins.Text = "0"
  336.             Button2.PerformClick()
  337.         End If
  338.         If best5 = True And wins >= 5 Then
  339.             MsgBox("You Won")
  340.             lblDisply.Text = "Click a button "
  341.             Me.BackColor = Color.RoyalBlue
  342.             Form1_Load(Me, New System.EventArgs)
  343.             Me.Text = "RPS (Mode: Default)"
  344.             lblDisply.Text = "Click a button "
  345.             Me.BackColor = Color.RoyalBlue
  346.             Form1_Load(Me, New System.EventArgs)
  347.             lblLoses.Text = "0"
  348.             lblTies.Text = "0"
  349.             lblWins.Text = "0"
  350.             Button2.PerformClick()
  351.         End If
  352.         If best5 = True And loses >= 5 Then
  353.             MsgBox("You Lost")
  354.             lblDisply.Text = "Click a button "
  355.             Me.BackColor = Color.RoyalBlue
  356.             Form1_Load(Me, New System.EventArgs)
  357.             Me.Text = "RPS (Mode: Default)"
  358.             lblDisply.Text = "Click a button "
  359.             Me.BackColor = Color.RoyalBlue
  360.             Form1_Load(Me, New System.EventArgs)
  361.             lblLoses.Text = "0"
  362.             lblTies.Text = "0"
  363.             lblWins.Text = "0"
  364.             Button2.PerformClick()
  365.         End If
  366.         If best5 = True And ties >= 5 Then
  367.             MsgBox("You Tied")
  368.             lblDisply.Text = "Click a button "
  369.             Me.BackColor = Color.RoyalBlue
  370.             Form1_Load(Me, New System.EventArgs)
  371.             Me.Text = "RPS (Mode: Default)"
  372.             lblDisply.Text = "Click a button "
  373.             Me.BackColor = Color.RoyalBlue
  374.             Form1_Load(Me, New System.EventArgs)
  375.             lblLoses.Text = "0"
  376.             lblTies.Text = "0"
  377.             lblWins.Text = "0"
  378.             Button2.PerformClick()
  379.         End If
  380.         If best10 = True And ties >= 10 Then
  381.             MsgBox("You Tied")
  382.             lblDisply.Text = "Click a button "
  383.             Me.BackColor = Color.RoyalBlue
  384.             Form1_Load(Me, New System.EventArgs)
  385.             Me.Text = "RPS (Mode: Default)"
  386.             lblDisply.Text = "Click a button "
  387.             Me.BackColor = Color.RoyalBlue
  388.             Form1_Load(Me, New System.EventArgs)
  389.             lblLoses.Text = "0"
  390.             lblTies.Text = "0"
  391.             lblWins.Text = "0"
  392.             Button2.PerformClick()
  393.         End If
  394.     End Sub
  395.  
  396.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  397.         Application.Exit()
  398.     End Sub
  399.  
  400.     Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
  401.         Application.Exit()
  402.     End Sub
  403.  
  404.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  405.         Application.Restart()
  406.         Me.Text = "RPS (Mode: Default)"
  407.         lblDisply.Text = "Click a button "
  408.         Me.BackColor = Color.RoyalBlue
  409.         Form1_Load(Me, New System.EventArgs)
  410.         lblLoses.Text = "0"
  411.         lblTies.Text = "0"
  412.         lblWins.Text = "0"
  413.     End Sub
  414.  
  415.     Private Sub BestOf10ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BestOf10ToolStripMenuItem.Click
  416.         Me.Text = "RPS (Mode: Best of 10)"
  417.         If best5 = True Then
  418.             best5 = False
  419.         End If
  420.         best10 = True
  421.     End Sub
  422.  
  423.     Private Sub BestOf5ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BestOf5ToolStripMenuItem.Click
  424.         Me.Text = "RPS (Mode: Best of 5)"
  425.         If best10 = True Then
  426.             best10 = False
  427.         End If
  428.         best5 = True
  429.     End Sub
  430.  
  431.     Private Sub DefaultToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DefaultToolStripMenuItem.Click
  432.         Button2.PerformClick()
  433.         Me.Text = "RPS (Mode: Default)"
  434.         lblDisply.Text = "Click a button "
  435.         Me.BackColor = Color.RoyalBlue
  436.         Form1_Load(Me, New System.EventArgs)
  437.         lblLoses.Text = "0"
  438.         lblTies.Text = "0"
  439.         lblWins.Text = "0"
  440.         best10 = False
  441.         best5 = False
  442.     End Sub
  443.  
  444.     Private Sub Button2_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
  445.         With Button2
  446.             .Font = New Font("Impact", 12)
  447.             .Text = "Reloads Form"
  448.         End With
  449.     End Sub
  450.  
  451.     Private Sub Button2_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.MouseLeave
  452.         With Button2
  453.             .Font = New Font("Impact", 20)
  454.             .Text = "Reset"
  455.         End With
  456.     End Sub
  457.  
  458.     Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
  459.         Button1.Text = "Exit?"
  460.     End Sub
  461.  
  462.     Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
  463.         Button1.Text = "Exit"
  464.     End Sub
  465. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement