|
||||||
| Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I am by no means an expert in programming, but I thought that I would share with the forum my recent love for the dictionary data-type in Python. This seems to be a versatile data-type and recently I found a use for it in a game project I'm working on.
I used it to store a room object's, exit objects by a string name. This allows me to take raw_input from the user to utilize said exit object Here is my move() function to give a visual to what I'm talking about. Code:
def move(char, rooms, exit):
#Here we move our character through one of his room's exits
for i in rooms:
if i.loc == char.loc:
#lock testing
if i.exits[exit].locked == "yes":
if i.exits[exit].openwith in char.inventory:
char.loc = i.exits[exit].link
elif i.exits[exit].conditions in char.conditions:
char.loc = i.exits[exit].link
else:
#if not locked
char.loc = i.exits[exit].link
break
I know it's not much but I wanted to share. Anyone else have a love for dictionaries, or another data-type? |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sign Of Love | Jaan | The Lounge | 36 | 08-19-2008 01:55 PM |
| I know you love it | F0551L | Introductions | 31 | 07-24-2008 09:19 AM |
| l realy love programming but i dont know how to study for it | kia | C and C++ | 10 | 01-17-2008 04:46 PM |
| Why I love and hate Firefox? | TcM | Computer Software/OS | 25 | 08-28-2007 05:46 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |