Question About Data Types

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
 
A

Armin Zingler

Brian said:
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:

Code:
[/QUOTE]

Could you please post the code again? Copy it to notepad first, then from
notepad to the posting. This keeps identation and does not insert blank
lines. It's much easier for us to read.
 
B

Brian

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

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
Armin Zingler said:
Brian said:
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:

Code:
[/QUOTE]

Could you please post the code again? Copy it to notepad first, then from
notepad to the posting. This keeps identation and does not insert blank
lines. It's much easier for us to read.


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
[/QUOTE]
 
C

Cor

Hi Brian,

As far as I understand what you want, I think I would use a XML dataset in
this case.

I asume it is a standalone application.

Cor
 
B

Brian

Hmmm...interesting..I've done the same with some web site menus...I will see
what I can do.
 
T

Tom Leylan

Brian said:
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:

Hi Brian... Sounds like a fun project for you but before you get too far
down this road I'll mention that you are on the wrong track :)

Start to think of your "adventure world" as a physical place like your own
house. The code you posted has it set up as a "form" which has some objects
scattered around it like rooms and applicances and stuff. You aren't
"moving from room to room" you are clicking on the form and having the form
tell the user stuff. You see the difference?

Consider creating a single "Adventure World" Class that contains rooms
(another class) which contain objects (another class). But don't stop
there. Your LivingRoom, Den and Kitchen are all the same... you have them
described as "rooms" when in fact they should be subclassed from room. Your
LivingRoom should be a class that describes the LivingRoom, a Den class
describes a Den, etc. The television, atari game and such should similarly
contain their own data and have their own methods so the AdventureWorld (and
the UI) can interact with them.

Clicking the eastBtn for instance wouldn't have a bunch of IF or SELECT CASE
statements hoping to keep track of everything but rather it would simply
communicate the "move east one unit" to the player object in the
AdventureWorld object. The UI could ask the player object what it sees or
it can ask the LivingRoom object for a list of items in the room, etc.

In any case... think of it as a model of the real world (to begin with) it
isn't the real world of course but start with that line of thinking. The UI
simply interacts with that world, it doesn't "describe" it or decide what is
in each room.

Tom
 
B

Brian

Tom..can you e-mail me at the address on this posting? I have a few more
questions if you don't mind.
 
B

Brian

Tom..questions again...

What is the easiest way to more from room to room and keep inventory items
or show ones I've not picked up? Can I do all of this in classes? If so,
could you give me an example?

I do see endless code for buttons (like east, west, etc) the more the game
grows. I get a feeling, from your original post, that there is an easier way
to do this.

Thanks,
Brian
 
T

Tom Leylan

Hi Brian, in answer to your other posting... I'd prefer to avoid an email
exchange on text adventure game design (unless it's for hire) so let's keep
posting here :)
What is the easiest way to more from room to room and keep inventory items
or show ones I've not picked up? Can I do all of this in classes? If so,
could you give me an example?

You have to do it all in classes... even if you just wrote 100 unrelated
functions and procedures they are part of a class, just a poorly conceived
one. That's why I think writing this could turn out to be a good exercise
for you. And, I don't know what the optimal solution would be but consider
that you would minimally require:

a RoomClass
a RoomCollectionClass
a PlayerClass

a RoomClass would contain properties that decided it should have. So let's
say it could contain various objects, let's call it furniture since naming
them "objects" might get confusing, you'd need

a FurnitureClass
a FurnitureCollectionClass

and the RoomClass would have a property of type FurnitureCollectionClass
which would contain the furniture for that room.

If your player entered a room and the player object had a reference to the
room it was in then you could conceivably output a list of things in the
room by iterating through the collection printing the description (in the
Furniture object.)

objPlayer.GetRoom().GetFurniture.Item(0).Description

If it was something that could be picked up by the player (you would
essentially be keeping a reference to the thing in a collection of things
the player had. You would need to add a collection to the PlayerClass to
hold on to Furniture objects. (Furniture isn't a good name obviously.)
When the player picked up the object it would be removed from the room's
collection of furniture objects and added to the player's collection of
furniture objects.

To display what the player had you would iterate through its collection:

objPlayer.GetFurniture(0).Description

Moving from room to room depends upon (I guess) whether you only move in and
out of room or whether you can move around within the room. If you can
navigate around the room it sounds like you might need to implement a grid
system to keep track of the coordinates. That would complicate it of course
but the furniture could be placed somewhere specifically and not just be "in
the room."

Are you planning on giving the Player object omni-directional view? That is
can they see everything just by entering? Or must they turn to face the
wall in order to see the picture on the wall? Granted it isn't going to be
easy using an OOP methodology but it would surely be harder using strictly
procedural code.
I do see endless code for buttons (like east, west, etc) the more the game
grows. I get a feeling, from your original post, that there is an easier way
to do this.

The "trick" is that the game must be able to be played without any GUI at
all. If you write it such that you can control the player, the rooms, the
furniture in the rooms, etc. by addressing the objects you've created
(through the debugger for instance) then you can add a UI surface to the
game after it is working.

Don't start by adding code to the EastButton_Click event hander. You know
that will make the player move east... that's easy. What happens in the
AdventureWorld model when the player moves east? That's the hard part and
that's the game. Not the GUI interface to the game. The same thing would
happen inside AdventureWorld if the user typed "move east" into a text box
and pressed "Enter." You don't want to find yourself cutting the code from
EastButton_Click and pasting it into TextCommand_Changed because you wanted
to test out a new method of moving the player around.

Not to belabor the point but consider... if it is all made up of classes of
objects how easy you can introduce a new feature. Let's say you decided
that "weight" was something you want to know about so you could send the
message "it's too heavy to lift." You would add Weight as a property of the
furniture class (obviously assigning each furniture object a weight) you
would add a MaxWeight property to the player class representing the total
weight of items he can carry.

You add some code to the Player's PickUpFurniture() method to test whether
this object plus the weight of the objects the player is already carrying
exceeds that player's MaxWeight. You haven't wandered around the UI looking
for the PickUpButton_Click event in order to add another select case
statement.

In any case... if I were you I'd hang around or search the game development
websites/newsgroups. Even if you choose to write your version in VB.Net it
doesn't mean that reading Basic, C or Pascal coded solutions would hurt.
Search out the concepts and translate them into VB.Net.

Hope this helps... and have fun.
Tom
 
B

Brian

Thanks again..this is making sense finally but I am still a little stuck on
how to make a button command refer to a class room. I don't mind having a
class for each room and item and such but just don't know how to make the
actions refer to them. I know using a variable like currentLocation would be
useful.

Brian
 
T

Tom Leylan

Brian said:
Thanks again..this is making sense finally but I am still a little stuck on
how to make a button command refer to a class room. I don't mind having a
class for each room and item and such but just don't know how to make the
actions refer to them. I know using a variable like currentLocation would be
useful.

Brian I don't know your background or experience with OOP but before you try
to write anything complicated you need to familiarize yourself with the
basics. Create a few classes. Understand inheritance and containment.
Create private properties and public accessors. Instantiate a few objects,
interact with them... figure out where you would have to instantiate one in
an app in order to have any button in your UI interact with the object.

If you do it right you won't have a "variable like currentLocation" anywhere
in the UI. The player object isn't in the UI, it is in AdventureWorld. If
there was no UI at all the player would still be a part of AdventureWorld.
:) The UI can't suddenly be responsible for remembering where the player
is. If it is going to do that it may as well remember where the lamp and
desk is and everything else also. You're back to writing spaghetti code.


I still think you need to read something or start coding "something" just to
get a handle on it... but, consider creating a single class, name it
AdventureWorld. Then in your application (the UI) declare an AdventureWorld
property (name it AW) and instantiate it when the form loads.

Now go back and add one property to the AdventureWorld class, something like
"Name" and have it return AdventureWorld. Go back the UI app and in a
button click event have it output AW.Name. If you see "AdventureWorld"
you're communicating to the object. From them on you add more things to the
world and you interact with them the same way.

At no point (in the UI) do you suddenly start creating variables to hold
onto items the player is carrying or the score or the elapsed time. Put
these things into the AdventureWorld class, it will keep track of
everything. If you need to know the score or the player's name or how long
you've been playing you will ask the AdventureWorld object that you've named
AW. For instance:

AW.Player.Name("Brian") ' should set the player's name
AW.Player.Name ' should return the player's name

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top