title: Enhancing 'Rock, Paper, Scissors' to include 'Lizard, Spock' in VB.NET and making the code more extensible, maintainable and re-usable
body: <p>I'm new to programming and OOP so please forgive me for my lack of knowledge.</p>
  
  <p>As part of my Rock, Paper and Scissors game I have a abstract superclass (<strong>Weapon</strong>) which has subclasses (<strong>Rock, Paper and Scissors</strong>) in VB.NET like:</p>
  
  <pre><code>    Public MustInherit Class Weapons
           Public MustOverride Function compareTo(ByVal Weapons As Object) As Integer
  
      End Class
  
      Public Class Paper
          Inherits Weapons
  
          Public Overrides Function compareTo(ByVal Weapons As Object) As Integer
              If TypeOf Weapons Is Paper Then
                  Return 0
              ElseIf TypeOf Weapons Is Rock Then
                  Return 1
              Else
                  Return -1
              End If
          End Function
      End Class
  
      Public Class Rock
          Inherits Weapons
  
          Public Overrides Function compareTo(ByVal Weapons As Object) As Integer
              If TypeOf Weapons Is Rock Then
                  Return 0
              ElseIf TypeOf Weapons Is Scissors Then
                  Return 1
              Else
                  Return -1
              End If
          End Function
      End Class
  
      Public Class Scissors
          Inherits Weapons
  
          Public Overrides Function compareTo(ByVal Weapons As Object) As Integer
              If TypeOf Weapons Is Scissors Then
                  Return 0
              ElseIf TypeOf Weapons Is Paper Then
                  Return 1
              Else
                  Return -1
              End If
          End Function
      End Class
  </code></pre>
  
  <p>Also have a superclass <strong>Player</strong> which has subclasses (<strong>PlayerComputerRandom</strong>, <strong>PlayerHumanPlayer</strong> and <strong><em>PlayerComputerTactical</em></strong>) like:</p>
  
  <pre><code>    Imports RockPaperScissors.Weapons
  
  Public Class Player
  
      Private pName As String
      Private pNumberOfGamesWon As String
      Public pWeapon As Weapons
  
      Property Name() As String
          Get
              Return pName
          End Get
          Set(ByVal value As String)
              pName = value
          End Set
      End Property
  
      Property NumberOfGamesWon As String
          Get
              Return pNumberOfGamesWon
          End Get
          Set(ByVal value As String)
              pNumberOfGamesWon = value
          End Set
      End Property
  
      Property getWeapon As Weapons
          Get
              Return pWeapon
          End Get
          Set(ByVal value As Weapons)
              pWeapon = value
          End Set
      End Property
  
      Public Sub pickWeapon(ByVal WeaponType As String)
          If WeaponType = "Rock" Then
              pWeapon = New Rock()
  
          ElseIf WeaponType = "Paper" Then
              pWeapon = New Paper()
  
          Else
              pWeapon = New Scissors()
  
          End If
  
      End Sub
  
  End Class
  
  
  
      Imports RockPaperScissors.Weapons
  
  Public Class PlayerComputerRandom
      Inherits Player
  
      Private Enum weaponsList
          Rock
          Paper
          Scissors
      End Enum
  
      Public Overloads Sub pickWeapon()
  
          Dim randomChoice = New Random()
          Dim CompChoice As Integer = randomChoice.Next(0, [Enum].GetValues(GetType(weaponsList)).Length)
  
          If CompChoice = "0" Then
              pWeapon = New Rock()
  
          ElseIf CompChoice = "1" Then
              pWeapon = New Paper()
  
          Else
              pWeapon = New Scissors()
  
          End If
  
  
      End Sub
  
  End Class
  
  
  
   Public Class PlayerComputerTactical
      Inherits Player
  
      Private plastMove As String
  
      Property lastMove() As String
          Get
              Return plastMove
          End Get
          Set(ByVal value As String)
              plastMove = value
          End Set
      End Property
  
      Public Overloads Sub pickWeapon()
          ' Add tactical player functionality
      End Sub
  
  
  End Class
  
  
       Public Class PlayerHumanPlayer
          Inherits Player
  
      End Class
  </code></pre>
  
  <p>I have the GameForm class which instantiates the objects and performs various other logic used for the front-end as shown below:</p>
  
  <pre><code>    Public Class GameForm
      Private Sub btnRock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRock.Click
          findWinner("HumanPlayer", "Rock", "RandomComputer")
      End Sub
  
      Private Sub btnPaper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaper.Click
          findWinner("HumanPlayer", "Paper", "RandomComputer")
      End Sub
  
  
      Private Sub btnScissors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnScissors.Click
          findWinner("HumanPlayer", "Scissors", "RandomComputer")
      End Sub
  
      Public Sub findWinner(ByVal p1name As String, ByVal p1WeaponSelected As String, ByVal p2Name As String)
          Dim player1 = New PlayerHumanPlayer()
          Dim player2 = New PlayerComputerRandom()
  
          player1.Name = p1name
          player1.pickWeapon(p1WeaponSelected)  ' Should I be using the Rock Class???
  
          player2.Name = p2Name
          player2.pickWeapon()
  
          Dim winner As Integer = player1.getWeapon().compareTo(player2.getWeapon())
  
          Select Case winner
              Case 1
                  txtGameStatus.Text = player1.Name() + " wins!"
              Case -1
                  txtGameStatus.Text = player2.Name() + " wins!"
              Case 0
                  txtGameStatus.Text = "Draw!"
          End Select
      End Sub
  
  End Class
  </code></pre>
  
  <p>What I need to do is to be able to add new Weapons (<strong>Lizard, Spock</strong>) which I know I can do this by simply adding subclasses(<strong>Lizard, Spock</strong>) which inherit <strong>Weapons</strong> baseclass. </p>
  
  <p>However, this will require code changes to ALL subclasses (<strong>Rock, Paper and Scissors</strong>) which is not really a long-term maintainable solution. Certainly not best practise. </p>
  
  <p>Im new to coding and OOP so, could someone kindly show how I could enhance the existing Game to easily allow additional weapons to be added? Could I use a DB table to store the Weapons? If so, could you show how? I just want to be able long-term, reusable solution for this Game.</p>
  
  <p>Any idea how I can achieve this? Any help would be greatly appreciated.</p>
  
  <p>Manys thanks in advance </p>