Code in VB.NET

Post Reply
PKDemon
Posts: 91
Joined: Tue Nov 15, 2011 5:51 pm

Code in VB.NET

Post by PKDemon »

i have converted the code in vb.net here is the code i will upload the source too

Note: I will update this as new video's are released.

Tutorial.vb

Code: Select all


Module Tutorial

    Sub Main()

        PrintTitle.ShowTitle()
        PrintTitle.ShowStatus()
        Player.Swing()

    End Sub

End Module

PrintTitle Class

Code: Select all


Public Class PrintTitle

    Public Shared Sub ShowTitle()
        Console.WriteLine("Welcome to Kill a Kobold!")
        Console.ReadKey()
    End Sub

    Public Shared Sub ShowStatus()

        Console.Clear()

        Console.Write("Player " & vbNewLine & "**************" & vbNewLine)
        Console.WriteLine("Attack: " & Player.Attack)
        Console.WriteLine("Defense: " & Player.Defense)
        Console.WriteLine("Hit Points: " & Player.HitPoints)

        Console.Write(vbNewLine & vbNewLine)

        Console.Write("Kobold " & vbNewLine & "**************" & vbNewLine)
        Console.WriteLine("Attack: " & Kobold.Attack)
        Console.WriteLine("Defense: " & Kobold.Defense)
        Console.WriteLine("Hit Points: " & Kobold.HitPoints)

        Console.Write(vbNewLine & "Press a key to Attack")

        Console.ReadKey()

        If Kobold.HitPoints > 0 And Player.HitPoints > 0 Then

            Player.Swing()

        Else

            Console.Clear()

            Console.WriteLine("Game Over")
            Console.ReadKey()

        End If

    End Sub

End Class

AttackFunctions Class

Code: Select all


Public Class AttackFunctions

    Shared Function Attack1() As Integer

        Dim playerattack As Integer = 5
        Dim creaturedefense As Integer = 3

        Dim finalattack As Integer = playerattack - creaturedefense

        Return finalattack

    End Function

End Class

Player Class

Code: Select all


Public Class Player
    Private Shared p_attack As Integer = 5
    Private Shared p_defense As Integer = 5
    Private Shared p_hitpoints As Integer = 10
    Private Shared p_damage As Integer = 3

    Public Shared Property Attack As Integer
        Get
            Return p_attack
        End Get
        Set(value As Integer)
            p_attack = value
        End Set
    End Property

    Public Shared Property Defense As Integer
        Get
            Return p_defense
        End Get
        Set(value As Integer)
            p_defense = value
        End Set
    End Property

    Public Shared Property HitPoints As Integer
        Get
            Return p_hitpoints
        End Get
        Set(value As Integer)
            p_hitpoints = value
        End Set
    End Property

    Public Shared Property Damage As Integer
        Get
            Return p_damage
        End Get
        Set(value As Integer)
            p_damage = value
        End Set
    End Property

    Public Shared Sub Swing()

        If Player.HitPoints < 1 Or Kobold.HitPoints < 1 Then

            Return

        End If
        Console.Clear()
        Console.Write("Player swings and ")

        Dim attackroll As New Random
        Dim finalroll = attackroll.Next(1, 6)
        Dim finalattackroll = finalroll + Attack

        Dim defenseroll As New Random
        Dim finaldefenseroll = defenseroll.Next(1, 6)
        Dim finalkobolddefense = finaldefenseroll + Kobold.Defense

        If finalattackroll > finalkobolddefense Then

            Console.Write("HITS! " & vbNewLine & " For ")
            Dim damageroll As New Random
            Dim finaldamage = damageroll.Next(1, Damage)
            Kobold.HitPoints -= finaldamage
            Console.Write(finaldamage & " points of damage." & vbNewLine & " Press any key to continue.")
            Console.ReadKey()

            If Kobold.HitPoints < 1 Then

                Console.WriteLine(vbNewLine & "You have killed the Kobold!")
                Console.WriteLine("You Win!")

                Console.ReadKey()

                Return

            Else

                Kobold.Swing()

            End If

        Else

            Console.Write("Missed")
            Console.ReadKey()

        End If

    End Sub

End Class

Kobold Class

Code: Select all


Public Class Kobold
    Private Shared k_attack As Integer = 3
    Private Shared k_defense As Integer = 3
    Private Shared k_hitpoints As Integer = 6
    Private Shared k_damage As Integer = 2

    Public Shared Property Attack As Integer
        Get
            Return k_attack
        End Get
        Set(value As Integer)
            k_attack = value
        End Set
    End Property

    Public Shared Property Defense As Integer
        Get
            Return k_defense
        End Get
        Set(value As Integer)
            k_defense = value
        End Set
    End Property

    Public Shared Property HitPoints As Integer
        Get
            Return k_hitpoints
        End Get
        Set(value As Integer)
            k_hitpoints = value
        End Set
    End Property

    Public Shared Property Damage As Integer
        Get
            Return k_damage
        End Get
        Set(value As Integer)
            k_damage = value
        End Set
    End Property

    Public Shared Sub Swing()

        Console.Clear()
        Console.Write("Kobold swings and ")

        Dim attackroll As New Random
        Dim finalroll = attackroll.Next(1, 6)
        Dim finalattackroll = finalroll + Attack

        Dim defenseroll As New Random
        Dim finaldefenseroll = defenseroll.Next(1, 6)
        Dim finalplayerdefense = finaldefenseroll + Player.Defense

        If finalattackroll > finalplayerdefense Then

            Console.Write("HITS! " & vbNewLine & " For ")
            Dim damageroll As New Random
            Dim finaldamage = damageroll.Next(1, Damage)
            Player.HitPoints -= finaldamage
            Console.Write(finaldamage & " points of damage." & vbNewLine & " Press any key to continue.")
            Console.ReadKey()

            If Player.HitPoints < 1 Then

                Console.WriteLine(vbNewLine & "You have been killed!")
                Console.WriteLine("You Lose!")

                Console.ReadKey()

                Return

            Else

                PrintTitle.ShowStatus()

            End If

        Else

            Console.Write("Missed")
            Console.ReadKey()

            PrintTitle.ShowStatus()

        End If

    End Sub

End Class

Source Code Download
http://www.mediafire.com/?2rfryrnvlxhr62o
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: Code in VB.NET

Post by hallsofvallhalla »

nice
PKDemon
Posts: 91
Joined: Tue Nov 15, 2011 5:51 pm

Re: Code in VB.NET

Post by PKDemon »

hallsofvallhalla wrote:nice
thanks i figured i would help out with my vb skills lmao

i might try to code up a little text game in vb.net or something haha

and to let you knwo the problem with the Kobold not attacking is b/c the attack is lower than the defense all the time so i am working on making it work right :P
Post Reply

Return to “C# Tutorials Videos”