3 Replies - 418 Views - Last Post: 15 February 2013 - 05:33 PM Rate Topic: -----

#1 Bitgod79  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-February 13

Console - Adventure Game Args

Posted 15 February 2013 - 03:45 PM

I am trying to make a adventure game via windows Command Console (old school).

I'm able to take basic Take, Look, etc commands but I lack the ability to do 'Args', like:

Take Flashlight
Look Up
etc.
What am I missing?

Current code:
Module Main
    'Public Cmds As New Commands
    Public Prompt As String = "? "
    Public Command As String

    Sub Main()
        Dim Args() As String
        Dim A As Int16

        If Args.Length = 0 Then
            Console.WriteLine("No args!")
            Console.ReadLine()
        Else
            Console.WriteLine(Prompt)

            Command = Console.ReadLine()

            Select Case Command
                Case "Take"
                    If Args.Length = 0 Then
                        Console.WriteLine("Take what?")
                    Else
                        For A = 0 To Args.Length - 1
                            Select Case Args(A).ToString
                                Case "Poop"
                                    Console.WriteLine("You a poop!")
                                    Console.ReadLine()
                                Case "Flashlight"
                                    Console.WriteLine("You took the flashlight!")
                                    Console.ReadLine()
                                Case Else
                                    Console.WriteLine("You took nothing, what the hell?")
                                    Console.ReadLine()
                            End Select
                        Next
                    End If

                    Console.WriteLine(Prompt)
                    Console.ReadLine()
                Case Else
                    Console.WriteLine("Invalid Command")
                    Command = Console.ReadLine()
            End Select
        End If

    End Sub

End Module




poop was a test heh...

Is This A Good Question/Topic? 0
  • +

Replies To: Console - Adventure Game Args

#2 tycos  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 53
  • Joined: 12-February 13

Re: Console - Adventure Game Args

Posted 15 February 2013 - 04:15 PM

This is very primitive but you can type "Take Book" or "Look Up" and it will say You take Book or You Look Up:

Module Module1
    'Public Cmds As New Commands
    Public Prompt As String = "? "
    Public Command As String
    Public run As Boolean = True
    Public err_text As String = "Invalid Command"

    Sub Main()
        Call prompt_player()
    End Sub

    Public Sub prompt_player()
        Try
            Dim args As String()
            Console.WriteLine(">")
            Command = Console.ReadLine()
            args = Command.Split(New Char() {" "c})

            If args.Length > 0 Then
                Select Case args(0).ToLower
                    Case "take"
                        take(args)
                    Case "look"
                        look(args)
                    Case Else
                        Console.WriteLine(err_text)
                End Select
            End If
          
            Call Main()
        Catch ex As Exception

        End Try
    End Sub

    Public Sub take(args As String())
        Try
            If args.Length > 1 Then
                Console.WriteLine("You take a " & args(1))
            Else
                Console.WriteLine("Take What?")
            End If
        Catch ex As Exception
            Console.WriteLine(err_text)
        End Try
    End Sub

    Public Sub look(args As String())
        Try
            If args.Length > 1 Then
                Console.WriteLine("You look " & args(1))
            Else
                Console.WriteLine("Look where?")
            End If
        Catch ex As Exception
            Console.WriteLine(err_text)
        End Try
    End Sub

End Module


Was This Post Helpful? 0
  • +
  • -

#3 Bitgod79  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-February 13

Re: Console - Adventure Game Args

Posted 15 February 2013 - 04:24 PM

Was hoping more for a dynamic args thing. so i can use them in other 'rooms' hehe.

View Posttycos, on 15 February 2013 - 04:15 PM, said:

This is very primitive but you can type "Take Book" or "Look Up" and it will say You take Book or You Look Up:

Module Module1
    'Public Cmds As New Commands
    Public Prompt As String = "? "
    Public Command As String
    Public run As Boolean = True
    Public err_text As String = "Invalid Command"

    Sub Main()
        Call prompt_player()
    End Sub

    Public Sub prompt_player()
        Try
            Dim args As String()
            Console.WriteLine(">")
            Command = Console.ReadLine()
            args = Command.Split(New Char() {" "c})

            If args.Length > 0 Then
                Select Case args(0).ToLower
                    Case "take"
                        take(args)
                    Case "look"
                        look(args)
                    Case Else
                        Console.WriteLine(err_text)
                End Select
            End If
          
            Call Main()
        Catch ex As Exception

        End Try
    End Sub

    Public Sub take(args As String())
        Try
            If args.Length > 1 Then
                Console.WriteLine("You take a " & args(1))
            Else
                Console.WriteLine("Take What?")
            End If
        Catch ex As Exception
            Console.WriteLine(err_text)
        End Try
    End Sub

    Public Sub look(args As String())
        Try
            If args.Length > 1 Then
                Console.WriteLine("You look " & args(1))
            Else
                Console.WriteLine("Look where?")
            End If
        Catch ex As Exception
            Console.WriteLine(err_text)
        End Try
    End Sub

End Module


Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 369
  • View blog
  • Posts: 1,082
  • Joined: 01-February 13

Re: Console - Adventure Game Args

Posted 15 February 2013 - 05:33 PM

View PostBitgod79, on 15 February 2013 - 05:45 PM, said:

I am trying to make a adventure game via windows Command Console (old school).

I'm able to take basic Take, Look, etc commands but I lack the ability to do 'Args', like:

Take Flashlight
Look Up
etc.
What am I missing?


Hey Bitgod79,
I don`t use console apps at all but, I do know if you pass args in dos that if there is a space between them like "Take Flashlight" it counts "Take" as 1 arg and would take "Flashlight" as the second arg. Maybe you could read the line that the user types like (Take Flashlight) and use the String.Replace like :

        StringName.Replace(" ", "_")



That would make it "Take_Flashlight" and it would be looked at as 1 arg.

This post has been edited by IronRazer: 15 February 2013 - 05:34 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1