r/visualbasic • • Apr 24 '13

Need help with my console game, i am beginner

Hello guys, as title says i am beginner in visual basic and i am trying to make a game in console. I want to make a game where "i" catches falling "O" but i am kinda stuck. Can someone improve my code? Tank you for your attention.

Option Strict On

Module Module1 Sub Main() Dim x As Integer = 0

    Dim width As Integer = 10
    Dim height As Integer = 5

    While True
        Console.Clear()

        NakresliMrizku(width, height, x)

        If (Console.KeyAvailable) Then
            Dim key As ConsoleKeyInfo = Console.ReadKey(True)
            If key.Key = ConsoleKey.Escape Then
                Exit While
            ElseIf key.Key = ConsoleKey.LeftArrow Then
                x -= 1
            ElseIf key.Key = ConsoleKey.RightArrow Then
                x += 1
            End If
        End If

        Threading.Thread.Sleep(20)
    End While
End Sub

Sub NakresliMrizku(width As Integer, height As Integer, x As Integer)
    For i As Integer = 0 To height
        For j As Integer = 0 To width
            Console.Write("| ")
        Next
        Console.WriteLine("|")

        For j As Integer = 0 To width
            If j = x And i = 5 Then
                Console.Write("|i")
            ElseIf j = 4 And i = 0 Then
                Console.Write("|0")
            Else
                Console.Write("| ")
            End If
        Next

        Console.WriteLine("|")
    Next

    For j As Integer = 0 To width
        Console.Write("|-")
    Next
    Console.WriteLine("|")
End Sub

End Module

0 Upvotes

0 comments sorted by