Dict of classes versus lots of variables

Dict of classes versus lots of variables

Postby mckryall » Fri Apr 18, 2014 8:58 pm

I'm making a text adventure engine with support for a map, rooms, and, hopefully, an inventory. each room is a class that takes 6 variables. Should I store and access the rooms like this:
Code: Select all
rooms = {
   1:class_room("It is dark. You feel your way around the walls and find a door.", False, False, True, False, "You have memory of this room. You know that you are at the only doorway.")
}
print rooms[1].text

, like this:
Code: Select all
x = class_room("It is dark. You feel your way around the walls and find a door.", False, False, True, False, "You have memory of this room. You know that you are at the only doorway.")
print x.text

, or in some other way (possibly involving a dict of lists)?
Python 2.7
Mac Mini
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 94
Joined: Sat Nov 23, 2013 6:13 pm

Re: Dict of classes versus lots of variables

Postby metulburr » Fri Apr 18, 2014 9:51 pm

, or in some other way (possibly involving a dict of lists)?

It completely depends on whether you want to store the objects sequencially in a list, or by key in a dictionary.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1448
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Dict of classes versus lots of variables

Postby mckryall » Fri Apr 18, 2014 10:12 pm

Each separate room is an entry in the dict. I'm going to have the class_room class get stuff from another class which will contain a list (not the data type) of objects and their properties/associated code/dialog.
Edit:
The rooms are on a map of variable dimensions, which is really just a range of numbers, thought of as a grid. (currently 1-100 in a 10x10 grid.) The range is the product of two numbers, one of them being the width. The width will be used to move down, Ex. CurrentRoom = 1; input = "south"; CurrentRoom += 10; CurrentRoom = 11.
Python 2.7
Mac Mini
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 94
Joined: Sat Nov 23, 2013 6:13 pm


Return to Game Development

Who is online

Users browsing this forum: Exabot [Bot] and 2 guests