Programming Finals

My Cumulative Program: Part 2

This program focuses on a criminal’s journey through the cosmos, all while trying to escape the people he stole a diamond from. If you would like a more detailed overview of this program, my first post covers it. If you are a source code junky, my source code for this program is in my third post on this program. If you are more into the outputs of the program and what it looks like when it’s running, my fourth post covers that.

For this program, I had to learn some new techniques. One of these techniques was a slow print-like function. Now, I will have to admit, I did take this off the internet(it is the fourth response to the original post), but I didn’t stop there. After implementing it into my program, I decided to try to understand it, though I wasn’t too successful. This function prints out the words in a way that looks like the computer is typing it to the user. The piece of code does require you to import sys into your program and you must have a Mac computer otherwise it will not run correctly due to the music.

def sprint(str):
   for c in str + '\n':
     sys.stdout.write(c)
     sys.stdout.flush()
     time.sleep(3./90)

 

On the other hand, there were some parts that I did know, and, in my own opinion, did very well. One of these was my main(). For those of you who don’t know what a main is, it is the parent function where everything else is called or run. Throughout the whole semester, Mr. Sommerer has encouraged us to make our mains as small and efficient as possible. This program I feel as though I exceeded this task. My main was very small for the task it accomplished and worked like a charm.

def main():
    give_instructions()
    doAnother = 'yes'
    while doAnother.lower().strip() == 'yes':
        name = get_name()
        crossroads(name)
        doAnother = do_again()

 

Unfortunately, not all my code is beautiful like my main. One of these not-so-beautiful pieces of code is my “crossroads” procedure. This procedure does what it needs to, but I feel like it is clunky and could be made smaller, though I’m not sure how at this point. If I could’ve found a way to make it smaller or more pleasant to look at, I would have.

def crossroads(name):
    """gets the first senerio and leads to all others."""
    death = senerio1()
    checkDeath(death)
    death = senerio2()
    checkDeath(death)
    hungry()
    death, dagger, banana = senerio3()
    checkDeath(death)
    senerio4(dagger, banana)
    senerio5()