Infinitely deep text adventure: Nested if statements?

Infinitely deep text adventure: Nested if statements?

Postby mckryall » Wed Apr 16, 2014 2:15 am

If I were to make a text adventure in which every choice would lead the user on a new path, would it be considered good or bad form to break a major choice and it's related
if-statements into a function? Remember, the functions would not be used again, and would have an odd naming scheme that listed the major choices that led to it, such as "a_c_b_a_d".
Python 2.7
Mac Mini
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 94
Joined: Sat Nov 23, 2013 6:13 pm

Re: Infinitely deep text adventure: Nested if statements?

Postby Mekire » Wed Apr 16, 2014 3:11 am

No, not really.
You should try to be as general as possible with the overall architecture.

Switching on dictionaries is often a good idea. Say you have a generic environment/room/whatever class. Instances would be initialized with things like a description attribute and then a dictionary of maybe direction/choice keys with values of the next room/game state. If you just want a really basic choose your own advenuter type thing it won't be too rough. If you start wanting to implement things like inventory and such it gets trickier to keep your classes generic.

Basically if you ever find yourself making long blocks of nested if/elif/else statements, you are probably not going about things in the best (maintainable/extensible) way. Honestly, despite it often being the top of the list of sugestions for beginning programmers, making a good text game (or textgame framework) is amazingly tricky.

If you can come up with something I'll try to take a look and make some suggestions.
-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Infinitely deep text adventure: Nested if statements?

Postby mckryall » Wed Apr 16, 2014 4:45 am

Do you mean, like, make one function that lets you interact with the room and repeats over and over again and moves about the dictionary as if it were a map? Would it be better to have it move around a 2D array and have the points on that array named after dictionary items? If so, I've finally found a reason to learn about those things.
Edit:
I'm no longer talking about an infinitely deep text adventure.
Edit of an Edit:
I'm actually going to make a framework for a text adventure with a map! At 12:51! On spring break! Yay!: :)
Python 2.7
Mac Mini
Laptop w/ Ubuntu 14.04
Steam; PSN
mckryall
 
Posts: 94
Joined: Sat Nov 23, 2013 6:13 pm

Re: Infinitely deep text adventure: Nested if statements?

Postby Mekire » Wed Apr 16, 2014 5:24 am

My game map for my pygame project is a dictionary of cartesian (x,y) tuples, to map name values. When I leave a map I increment/decrement the appropriate coordinate, and load the new map with the name retrieved from the dictionary. You are doing text, but the logic remains the same.

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Infinitely deep text adventure: Nested if statements?

Postby XndrK » Thu Apr 17, 2014 5:49 pm

That's genius!
Proverbs 26:14 describes me a bit too well.

Version: Python 2.7.5

https://github.com/4of92000
https://github.com/PythonForum/
User avatar
XndrK
 
Posts: 172
Joined: Sat Jun 15, 2013 7:57 pm


Return to Game Development

Who is online

Users browsing this forum: Google [Bot] and 3 guests