B
Brian
Hi!
I am new to VB.net but know enough to kind of dive in. I want to make a text
adventure but I am having problems in how I want to store the data for
inventory items, characters and such. Right now, I have three rooms but a
lot of if and then statements on how to tell if they should appear in your
(listboxes) inventory or items in room box.
Any suggestions on where to store this information? Here is a sample of my
code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim lecroneLivingRoom As New room()
Dim lecroneKitchen As New room()
Dim lecroneDen As New room()
Dim wigwam As New items()
Dim television As New items()
Dim atari As New items()
Dim locale As String
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents mainLbl As System.Windows.Forms.Label
Friend WithEvents itemsList As System.Windows.Forms.ListBox
Friend WithEvents inventoryList As System.Windows.Forms.ListBox
Friend WithEvents lookBtn As System.Windows.Forms.Button
Friend WithEvents dropBtn As System.Windows.Forms.Button
Friend WithEvents talkBtn As System.Windows.Forms.Button
Friend WithEvents useBtn As System.Windows.Forms.Button
Friend WithEvents getBtn As System.Windows.Forms.Button
Friend WithEvents northBtn As System.Windows.Forms.Button
Friend WithEvents westBtn As System.Windows.Forms.Button
Friend WithEvents southBtn As System.Windows.Forms.Button
Friend WithEvents eastBtn As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mainLbl = New System.Windows.Forms.Label()
Me.inventoryList = New System.Windows.Forms.ListBox()
Me.itemsList = New System.Windows.Forms.ListBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.northBtn = New System.Windows.Forms.Button()
Me.westBtn = New System.Windows.Forms.Button()
Me.southBtn = New System.Windows.Forms.Button()
Me.eastBtn = New System.Windows.Forms.Button()
Me.talkBtn = New System.Windows.Forms.Button()
Me.useBtn = New System.Windows.Forms.Button()
Me.lookBtn = New System.Windows.Forms.Button()
Me.dropBtn = New System.Windows.Forms.Button()
Me.getBtn = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'mainLbl
'
Me.mainLbl.Location = New System.Drawing.Point(8, 8)
Me.mainLbl.Name = "mainLbl"
Me.mainLbl.Size = New System.Drawing.Size(448, 136)
Me.mainLbl.TabIndex = 0
'
'inventoryList
'
Me.inventoryList.Location = New System.Drawing.Point(480, 32)
Me.inventoryList.Name = "inventoryList"
Me.inventoryList.Size = New System.Drawing.Size(128, 121)
Me.inventoryList.TabIndex = 1
'
'itemsList
'
Me.itemsList.Location = New System.Drawing.Point(480, 200)
Me.itemsList.Name = "itemsList"
Me.itemsList.Size = New System.Drawing.Size(128, 121)
Me.itemsList.TabIndex = 2
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(480, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(128, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Inventory"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(480, 160)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(128, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Objects / Persons in Room"
'
'northBtn
'
Me.northBtn.Location = New System.Drawing.Point(208, 176)
Me.northBtn.Name = "northBtn"
Me.northBtn.TabIndex = 5
Me.northBtn.Text = "North"
'
'westBtn
'
Me.westBtn.Location = New System.Drawing.Point(136, 200)
Me.westBtn.Name = "westBtn"
Me.westBtn.TabIndex = 6
Me.westBtn.Text = "West"
'
'southBtn
'
Me.southBtn.Location = New System.Drawing.Point(208, 224)
Me.southBtn.Name = "southBtn"
Me.southBtn.TabIndex = 7
Me.southBtn.Text = "South"
'
'eastBtn
'
Me.eastBtn.Location = New System.Drawing.Point(280, 200)
Me.eastBtn.Name = "eastBtn"
Me.eastBtn.TabIndex = 8
Me.eastBtn.Text = "East"
'
'talkBtn
'
Me.talkBtn.Location = New System.Drawing.Point(176, 288)
Me.talkBtn.Name = "talkBtn"
Me.talkBtn.TabIndex = 9
Me.talkBtn.Text = "Talk"
'
'useBtn
'
Me.useBtn.Location = New System.Drawing.Point(88, 288)
Me.useBtn.Name = "useBtn"
Me.useBtn.TabIndex = 10
Me.useBtn.Text = "Use"
'
'lookBtn
'
Me.lookBtn.Location = New System.Drawing.Point(0, 288)
Me.lookBtn.Name = "lookBtn"
Me.lookBtn.TabIndex = 11
Me.lookBtn.Text = "Look"
'
'dropBtn
'
Me.dropBtn.Location = New System.Drawing.Point(352, 288)
Me.dropBtn.Name = "dropBtn"
Me.dropBtn.TabIndex = 12
Me.dropBtn.Text = "Drop"
'
'getBtn
'
Me.getBtn.Location = New System.Drawing.Point(264, 288)
Me.getBtn.Name = "getBtn"
Me.getBtn.TabIndex = 14
Me.getBtn.Text = "Get"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 374)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.getBtn,
Me.dropBtn, Me.lookBtn, Me.useBtn, Me.talkBtn, Me.eastBtn, Me.southBtn,
Me.westBtn, Me.northBtn, Me.Label3, Me.Label2, Me.itemsList,
Me.inventoryList, Me.mainLbl})
Me.Name = "Form1"
Me.Text = "Gravel Ridge Adventure 0.0"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub westBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles westBtn.Click
REM living room to Kitchen
If locale = "lecroneLivingRoom" Then
locale = "lecroneKitchen"
itemsList.Items.Remove("wigwam")
lecroneKitchen.desc = "You are in the Lecrone Kitchen"
mainLbl.Text = lecroneKitchen.desc & _
"There is a Bobo light hanging from the ceiling with a " _
& "wicker light fixture. It is moving back and forth as " _
& "if someone has recently ghunked it. The living room " _
& "is to the East"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles useBtn.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mainLbl.Text = "Welcome To Gravel Ridge Adventure"
lecroneLivingRoom.desc = "This is the Lecrone Living Room"
locale = "lecroneLivingRoom"
mainLbl.Text = mainLbl.Text & lecroneLivingRoom.desc
wigwam.itemExist = True
If wigwam.itemExist = True Then
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub itemsList_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles itemsList.SelectedIndexChanged
End Sub
Private Sub inventoryList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
inventoryList.SelectedIndexChanged
End Sub
Private Sub lookBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lookBtn.Click
If itemsList.SelectedItem = "wigwam" Then
mainLbl.Text = mainLbl.Text & "This is a superhero jacket"
End If
End Sub
Private Sub dropBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dropBtn.Click
End Sub
Private Sub getBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles getBtn.Click
REM Getting WigWam
If locale = "lecroneLivingRoom" And wigwam.itemExist = True Then
If itemsList.SelectedItem = "wigwam" Then
inventoryList.Items.Add("wigwam")
itemsList.Items.Remove("wigwam")
wigwam.itemExist = False
wigwam.itemHave = True
End If
End If
REM Getting Atari
If locale = "lecroneDen" And atari.itemExist = True Then
If itemsList.SelectedItem = "atari" Then
inventoryList.Items.Add("atari")
itemsList.Items.Remove("atari")
atari.itemExist = False
atari.itemHave = True
End If
End If
End Sub
Private Sub northBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles northBtn.Click
REM Den to Living Room
If locale = "lecroneDen" Then
locale = "lecroneLivingRoom"
itemsList.Items.Remove("atari")
End If
If wigwam.itemHave = True Then
mainLbl.Text = lecroneLivingRoom.desc
Else
mainLbl.Text = lecroneLivingRoom.desc & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub eastBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles eastBtn.Click
REM Kitchen to Living Room
If locale = "lecroneKitchen" Then
locale = "lecroneLivingRoom"
End If
REM Living Room To EAST
If locale = "lecroneLivingRoom" Then
mainLbl.Text = "You Can't Go That Way"
End If
If wigwam.itemHave = True Then
itemsList.Items.Clear()
Else
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub southBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles southBtn.Click
If locale = "lecroneLivingRoom" Then
locale = "lecroneDen"
itemsList.Items.Remove("wigwam")
lecroneDen.desc = "You are in the Lecrone Den."
mainLbl.Text = lecroneDen.desc & "This room could have " _
& "been a garage at one time. There is a couch and " _
& "television here."
atari.itemExist = True
If atari.itemExist = True Then
mainLbl.Text = lecroneDen.desc & "This room could have " _
& "been a garage at one time. There is a couch and " _
& "television here." & "There is an Atari Here"
itemsList.Items.Add("atari")
End If
End If
End Sub
End Class
and a seperate class module:
Option Strict Off
Option Explicit On
Friend Class room
Public desc As String
End Class
Friend Class people
End Class
Friend Class items
Public itemExist As Boolean
Public itemHave As Boolean
Public itemDesc As String
End Class
I am new to VB.net but know enough to kind of dive in. I want to make a text
adventure but I am having problems in how I want to store the data for
inventory items, characters and such. Right now, I have three rooms but a
lot of if and then statements on how to tell if they should appear in your
(listboxes) inventory or items in room box.
Any suggestions on where to store this information? Here is a sample of my
code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim lecroneLivingRoom As New room()
Dim lecroneKitchen As New room()
Dim lecroneDen As New room()
Dim wigwam As New items()
Dim television As New items()
Dim atari As New items()
Dim locale As String
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents mainLbl As System.Windows.Forms.Label
Friend WithEvents itemsList As System.Windows.Forms.ListBox
Friend WithEvents inventoryList As System.Windows.Forms.ListBox
Friend WithEvents lookBtn As System.Windows.Forms.Button
Friend WithEvents dropBtn As System.Windows.Forms.Button
Friend WithEvents talkBtn As System.Windows.Forms.Button
Friend WithEvents useBtn As System.Windows.Forms.Button
Friend WithEvents getBtn As System.Windows.Forms.Button
Friend WithEvents northBtn As System.Windows.Forms.Button
Friend WithEvents westBtn As System.Windows.Forms.Button
Friend WithEvents southBtn As System.Windows.Forms.Button
Friend WithEvents eastBtn As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mainLbl = New System.Windows.Forms.Label()
Me.inventoryList = New System.Windows.Forms.ListBox()
Me.itemsList = New System.Windows.Forms.ListBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.northBtn = New System.Windows.Forms.Button()
Me.westBtn = New System.Windows.Forms.Button()
Me.southBtn = New System.Windows.Forms.Button()
Me.eastBtn = New System.Windows.Forms.Button()
Me.talkBtn = New System.Windows.Forms.Button()
Me.useBtn = New System.Windows.Forms.Button()
Me.lookBtn = New System.Windows.Forms.Button()
Me.dropBtn = New System.Windows.Forms.Button()
Me.getBtn = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'mainLbl
'
Me.mainLbl.Location = New System.Drawing.Point(8, 8)
Me.mainLbl.Name = "mainLbl"
Me.mainLbl.Size = New System.Drawing.Size(448, 136)
Me.mainLbl.TabIndex = 0
'
'inventoryList
'
Me.inventoryList.Location = New System.Drawing.Point(480, 32)
Me.inventoryList.Name = "inventoryList"
Me.inventoryList.Size = New System.Drawing.Size(128, 121)
Me.inventoryList.TabIndex = 1
'
'itemsList
'
Me.itemsList.Location = New System.Drawing.Point(480, 200)
Me.itemsList.Name = "itemsList"
Me.itemsList.Size = New System.Drawing.Size(128, 121)
Me.itemsList.TabIndex = 2
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(480, 8)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(128, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Inventory"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(480, 160)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(128, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Objects / Persons in Room"
'
'northBtn
'
Me.northBtn.Location = New System.Drawing.Point(208, 176)
Me.northBtn.Name = "northBtn"
Me.northBtn.TabIndex = 5
Me.northBtn.Text = "North"
'
'westBtn
'
Me.westBtn.Location = New System.Drawing.Point(136, 200)
Me.westBtn.Name = "westBtn"
Me.westBtn.TabIndex = 6
Me.westBtn.Text = "West"
'
'southBtn
'
Me.southBtn.Location = New System.Drawing.Point(208, 224)
Me.southBtn.Name = "southBtn"
Me.southBtn.TabIndex = 7
Me.southBtn.Text = "South"
'
'eastBtn
'
Me.eastBtn.Location = New System.Drawing.Point(280, 200)
Me.eastBtn.Name = "eastBtn"
Me.eastBtn.TabIndex = 8
Me.eastBtn.Text = "East"
'
'talkBtn
'
Me.talkBtn.Location = New System.Drawing.Point(176, 288)
Me.talkBtn.Name = "talkBtn"
Me.talkBtn.TabIndex = 9
Me.talkBtn.Text = "Talk"
'
'useBtn
'
Me.useBtn.Location = New System.Drawing.Point(88, 288)
Me.useBtn.Name = "useBtn"
Me.useBtn.TabIndex = 10
Me.useBtn.Text = "Use"
'
'lookBtn
'
Me.lookBtn.Location = New System.Drawing.Point(0, 288)
Me.lookBtn.Name = "lookBtn"
Me.lookBtn.TabIndex = 11
Me.lookBtn.Text = "Look"
'
'dropBtn
'
Me.dropBtn.Location = New System.Drawing.Point(352, 288)
Me.dropBtn.Name = "dropBtn"
Me.dropBtn.TabIndex = 12
Me.dropBtn.Text = "Drop"
'
'getBtn
'
Me.getBtn.Location = New System.Drawing.Point(264, 288)
Me.getBtn.Name = "getBtn"
Me.getBtn.TabIndex = 14
Me.getBtn.Text = "Get"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(616, 374)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.getBtn,
Me.dropBtn, Me.lookBtn, Me.useBtn, Me.talkBtn, Me.eastBtn, Me.southBtn,
Me.westBtn, Me.northBtn, Me.Label3, Me.Label2, Me.itemsList,
Me.inventoryList, Me.mainLbl})
Me.Name = "Form1"
Me.Text = "Gravel Ridge Adventure 0.0"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub westBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles westBtn.Click
REM living room to Kitchen
If locale = "lecroneLivingRoom" Then
locale = "lecroneKitchen"
itemsList.Items.Remove("wigwam")
lecroneKitchen.desc = "You are in the Lecrone Kitchen"
mainLbl.Text = lecroneKitchen.desc & _
"There is a Bobo light hanging from the ceiling with a " _
& "wicker light fixture. It is moving back and forth as " _
& "if someone has recently ghunked it. The living room " _
& "is to the East"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles useBtn.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mainLbl.Text = "Welcome To Gravel Ridge Adventure"
lecroneLivingRoom.desc = "This is the Lecrone Living Room"
locale = "lecroneLivingRoom"
mainLbl.Text = mainLbl.Text & lecroneLivingRoom.desc
wigwam.itemExist = True
If wigwam.itemExist = True Then
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub itemsList_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles itemsList.SelectedIndexChanged
End Sub
Private Sub inventoryList_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
inventoryList.SelectedIndexChanged
End Sub
Private Sub lookBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lookBtn.Click
If itemsList.SelectedItem = "wigwam" Then
mainLbl.Text = mainLbl.Text & "This is a superhero jacket"
End If
End Sub
Private Sub dropBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dropBtn.Click
End Sub
Private Sub getBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles getBtn.Click
REM Getting WigWam
If locale = "lecroneLivingRoom" And wigwam.itemExist = True Then
If itemsList.SelectedItem = "wigwam" Then
inventoryList.Items.Add("wigwam")
itemsList.Items.Remove("wigwam")
wigwam.itemExist = False
wigwam.itemHave = True
End If
End If
REM Getting Atari
If locale = "lecroneDen" And atari.itemExist = True Then
If itemsList.SelectedItem = "atari" Then
inventoryList.Items.Add("atari")
itemsList.Items.Remove("atari")
atari.itemExist = False
atari.itemHave = True
End If
End If
End Sub
Private Sub northBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles northBtn.Click
REM Den to Living Room
If locale = "lecroneDen" Then
locale = "lecroneLivingRoom"
itemsList.Items.Remove("atari")
End If
If wigwam.itemHave = True Then
mainLbl.Text = lecroneLivingRoom.desc
Else
mainLbl.Text = lecroneLivingRoom.desc & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub eastBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles eastBtn.Click
REM Kitchen to Living Room
If locale = "lecroneKitchen" Then
locale = "lecroneLivingRoom"
End If
REM Living Room To EAST
If locale = "lecroneLivingRoom" Then
mainLbl.Text = "You Can't Go That Way"
End If
If wigwam.itemHave = True Then
itemsList.Items.Clear()
Else
mainLbl.Text = mainLbl.Text & "There is a Wigwam here."
itemsList.Items.Add("wigwam")
End If
End Sub
Private Sub southBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles southBtn.Click
If locale = "lecroneLivingRoom" Then
locale = "lecroneDen"
itemsList.Items.Remove("wigwam")
lecroneDen.desc = "You are in the Lecrone Den."
mainLbl.Text = lecroneDen.desc & "This room could have " _
& "been a garage at one time. There is a couch and " _
& "television here."
atari.itemExist = True
If atari.itemExist = True Then
mainLbl.Text = lecroneDen.desc & "This room could have " _
& "been a garage at one time. There is a couch and " _
& "television here." & "There is an Atari Here"
itemsList.Items.Add("atari")
End If
End If
End Sub
End Class
and a seperate class module:
Option Strict Off
Option Explicit On
Friend Class room
Public desc As String
End Class
Friend Class people
End Class
Friend Class items
Public itemExist As Boolean
Public itemHave As Boolean
Public itemDesc As String
End Class