I2P-L7+8

Choose your own adventure game:

Mind map  At the very beginning of our project, we made a mind map in order to showcase the different aspects we were thinking of including. By making these aspects it helped us to visualise the  different things that happened in the game, and some of the genera outlines of the game.

Photo on 14-11-2016 at 4.25 PM

Pseudo Code: This was our pseudo code for the adventure game. We made the pseudo code in order to help us manage the actual coding. Whilst creating the pseudo code, I didn’t think that it would help. It was only when I had started coding did i realise the pseudo code was good reference for the code, especially at times where the coding language is hard to understand.

Aim of the game: To allow the user to continue throughout their story Ask users to input their name Ask users to input their age

Print: You are stuck on a deserted island, known to be filled with mysteries of both the past and present. You wake up on the beach of the island with a chill up your back, and a mysterious feeling that you are being followed. You brush yourself off, and look around the island. Your stomach is growling, but you try to think clearly about your next options. You scratch your options into the sand: Indent: 1. Go to the faraway abandoned hut Indent: 2. Go into the forest Indent: 3. Search for people. Input: Which option do you choose? Which one holds your fate?

Faraway Hut: Print: After long contemplation, and seeing dark clouds hovering over the island, bursting to rain, you decide to go to the abandoned hut and seek shelter. You enter the hut, and notice that it looks empty. Input: Explore the house, or hide in one of the rooms and seek refuge just for the night?

Explore the house Print: You start to explore the rooms of the house, and notice a lot of guns hung up on the walls. After exploring all the rooms, and notice that the hut is empty, you finally start to relax. You sit in one of the lounge chairs in the main part of the hut, but the wind blares a chilly breath of air, and you shiver. You walk over to the window, and try to close it, but you aren’t tall enough. You reach on your tippy-toes and try to close the latch. Whilst doing it, you fall out the window, into a pit of thorns. The thorns dig deep into your skin, and you bleed to death. You die. The End.

Hide in one of the rooms Print: You take refuge in the kitchen and hear a man walk down the steps of the hut. Input: You hide again, or you greet him

  1. If user inputs: You hide again

Then print: You hide, and go to the backyard of his hut. But you walk into a pit of thorns, and bleed to death. You die. The End 2. If the user inputs:  Greet the man Then print: the man greets you with a smile and hugs you- a weird embrace especially since you have never met him. However, during the embrace, you still don’t completely trust him, and feel his pocket. A gun shaped indent. Do you take the gun, or do you run for you life If input is: Take the gun Print: When you take the gun you feel victorious. But as you look around, and see human heads hanging as prizes on the walls, you paralyse. You look around, suddenly forgetting that you just stole a gun from a madman. As you look at the room, you realise that the entire room not only has bloody human heads but also guns. Not just one gun, but many guns. Too many for your liking. But before you know it, the man shoot you five times. You die. The End. If input is: Run for your life. Print: You try to run, but realise this was all a dream. The hut had been latched close since you arrived. The man was watching you since you came on the island. He chuckles softly, and whispers like the madman he is. Tears streaming down your face, you see him take a knife, and say something about adding you to his pretty collection. You stare around the room, and realise all the monuments are dead humans. You have a panic attack, and he kills you when you have fainted. The end, you die.

Print: Go into the Forest:Print: You get lost. You are scared, and darkness is falling. Suddenly, you fall into a pit with poisonous vipers. You die. The End.

Search for People: PrintYou pick up a conch shell on the beach. Suddenly, you hear someone calling for you. Input: Do you go towards the sound (1), or ignore the call (2)? If Input is 2, Print: You try to live alone, but you cannot manage to suffice on your own. You eventually die from starvation. If input is 1, Print: You find a chubby boy with thick spectacles stuck in brambles. You help him out, and discover his name is PIggy. He sees that you have a conch shell, and asks if you know how to blow it. You don’t, and he offers to teach you. Input: Accept (1) or decline (2)? If input is 1, Print: You learn to blow the conch, and when you finally succeed in making a sound, the deep note resonates through the entire island. Over the course of one hour, boys ranging from 6 year olds to 19 year olds stream out of the forest, until eventually an entire choir of boys come out, with a redhead leading the way. All the boys want you to become their leader, but the redhead, Jack, seems to want to be leader too. Input: Do you let Jack share leadership with you (1), or be a dictator (2)? If input is 1, Print: You guys split the leadership and he and his choir helps the group hunt, while you and the others help create a signal fire to get rescued. Your leadership seems harmonious and works really well, living long enough to witness a plane see your signal fire and rescue you. You get rescued and return home safely. Congratulations, you’ve survived! If input is 2, Print: Jack gets jealous and rebels. He and his hunters become more and more uncivilised until they become savages and split from the group. Eventually, out of revenge, Jack and his choir come back and convince your crew that you are a misleading chief. Your group and Jack’s group both set out and rip you apart, until all your remains are washed out into the sea. The End. If input is 2, Print: You and Piggy decide to stay and create a fire, but a wild boar stumbles towards your source of light. Input: Do you fight (1) or flee(2)? If input is 1, Print: You both die trying to kill the wild boar. The End. If is 2, Print: You run away, but a herd of pigs corner you, separating you from Piggy. You get gored to death. The End.

The code, and some of the syntax errors we overcame: 

Some of the syntax errors we faced:

One of the problems that we faced was getting the program to loop on itself. So once a person dies, the game will ask the user to restart or to quit the program. At first we weren’t sure on how we wanted to carry out this program. So after some research and talking to Mr. Lin, we found out that the best way to do this was to create a global function. By creating the global function it allows us to call it up, and break the function at any time to ask the user to restart.

varglobal=0
def function_startagain ():
    startagain= input (print("Do you want to start the game again, press 1 (exit) or 2 (start again)"))
    global varglobal
    if startagain== "2":
        print (funct_game())
    if startagain==1:
        varglobal==1

This shows the function that can be called up by throughout the entire program to be able to quit the program.

Another syntax error that we faced was the combination of the two programs. In order to save time Sonia and I split up the code so that we could be more efficient with time. However, when we got to combining the codes together, we realised that we used two very different approaches to making the code, and therefore there was some things that we had to fix. For example, she used mostly functions and simply called up the function when she needed to use it. I took a different approach to this, and tried to make the program based on mainly if and else statements, combined with a while statement, and incased within a function. When we combined the two codes, we then managed to learn about different ways to solve the same problem, and learned the different perspectives.

Another syntax error that we faced was the different indentations. The indentations were a problem made that were at times hard to fix. Sometimes there were the indent errors due to the  combination of the two codes, but we managed to go through each line and solve the errors that were presented. The only problem with indent errors was that I had to remind myself when I had to indent the breaks.

Another syntax error I faced was one that dealt with the functions, and if and else statements. Since at times there were if and else statements. These if and else statements were hard especially if you had a statement like this inside another one, or a while statement. For example, if we had the user choose between two options, and one of those options led to another question, an if and else statement had to be used within the statement that was already there. This led to many problems with not only indentations but also aspects of the code.

Interpretation of the code: 

varglobal=0
def function_startagain ():
    startagain= input (print("Do you want to start the game again, press 1 (exit) or 2 (start again)"))
    global varglobal
    if startagain== "2":
        print (funct_game())
    if startagain==1:
        varglobal==1
def function_v3a12():
       v3a12 = input(print("""Do you fight (1) or flee(2)? """));
       if v3a12 == "1":
           print("""You both die trying to kill the wild boar. The End. """);
       if v3a12 == "2":
           print("""You run away, but a herd of pigs corner you, separating you from Piggy. You get gored to death. The End. """)
def function_v3a11():
       v3a11 = input(print("""Do you let Jack share leadership with you (1), or be a dictator (2)?"""))
       if v3a11 == "1":
           print("""You guys split the leadership and he and his choir helps the group hunt, while you and the others help create a signal fire to get rescued. Your leadership seems harmonious and works really well, living long enough to witness a plane see your signal fire and rescue you. You get rescued and return home safely. Congratulations, you’ve survived!""")
       if v3a11 == "2":
               print("""Jack gets jealous and rebels. He and his hunters become more and more uncivilised until they become savages and split from the group. Eventually, out of revenge, Jack and his choir come back and convince your crew that you are a misleading chief. Your group and Jack’s group both set out and rip you apart, until all your remains are washed out into the sea. The End.""");
def function_v3a1():
       v3a1 = input(print("""Accept (1) or decline (2)? """))
       if v3a1 == "1":
           print("""You learn to blow the conch, and when you finally succeed in making a sound, the deep note resonates through the entire island. Over the course of one hour, boys ranging from 6 year olds to 19 year olds stream out of the forest, until eventually an entire choir of boys come out, with a redhead leading the way. All the boys want you to become their leader, but the redhead, Jack, seems to want to be leader too. """);
           print(function_v3a11())
       if v3a1 == "2":
           print("""You and Piggy decide to stay and create a fire, but a wild boar stumbles towards your source of light. """);
           print(function_v3a12())

In this first part it was where we defined all the variables before we managed to use them. This is where the pseudo code came in handy, because we knew exactly what needed to be in a variable before we started the game. By already knowing what we wanted to store in the variable, it allowed us to create those variables first, and move into the rest of the code without any problems.


def funct_game(): vBeginning= input("You are stuck on a deserted island, " "known to be filled with mysteries of both " "the past and present. You wake up on the beach " "of the island with a chill up your back, and a mysterious " "feeling that you are being followed. You brush yourself off," " and look around the island. Your stomach is growling, but y" "ou try to think clearly about your next options. You scratch " "your options into the sand:" "\n" " 1. Go to the faraway abandoned hut" "\n" " 2. Go into the forest " "\n" " 3. Search for people.")

The next part of the code was actually starting the game. In order to do this we had to put everything into a function of its own, so that we could call up the function and print it. This means that it sort of makes all the main code into one piece (which would be helpful if this was one selection out of many games)

 

while vBeginning != "1" or "2" or "3":
        if vBeginning == "1":
            print (" After long contemplation, "
                   " seeing dark clouds hovering over "
                   "the island, bursting to rain, you decide to go "
                   "to the abandoned hut and seek shelter. You enter the "
                   "hut, and notice that it looks empty.")
            vhut= input ("Explore the house (1), or hide in one "
                     "of the rooms and seek refuge just for the night? (2) ")
            if vhut== "2":
                print ("You take refuge in the kitchen and hear a man walk down the "
                        "steps of the hut.")
                vhide= input("Do you greet the man(1), or do you continue to hide.(2)")
                if vhide == "2":
                    print ("You hide, and go to the backyard of his hut. But you walk into a pit of thorns, and bleed to death. You die. The End ")
                    print (function_startagain())
                    break
                else:
                    print("The man greets you with a smile and hugs you- a weird embrace especially since you have never met him. However, during the embrace, you still don’t completely trust him, and feel his pocket. A gun shaped indent. ")
                    vgun=input ("Do you take the gun (1), or do you run for your life (2)")
                    if vgun == "2":
                        print (" You try to run, but realise this was all a dream. The hut had been latched close since you arrived. The man was watching you since you came on the island. "
                               "He chuckles softly, and whispers like the madman he is. Tears streaming down your face, you see him take a knife, and say something about adding you to his pretty collection. "
                               "You stare around the room, and realise all the monuments are dead humans. You have a panic attack, and he kills you when you have fainted. The end, you die.")
                        print (function_startagain())
                        break
                    else:
                        print ("When you take the gun you feel victorious. But as you look around, and see human heads hanging as prizes on the walls, you paralyse. "
                               "You look around, suddenly forgetting that you just stole a gun from a madman. As you look at the room, you realise that the entire room not only has bloody "
                               "human heads but also guns. Not just one gun, but many guns. Too many for your liking. But before you know it, the man shoot you five times. You die. The End.")
                        print (function_startagain())
                            break 


This part of the code was the part that I tried to code, but not all of it ( just majority to try to explain) Through this part, I made all the different options into inputs, and for the input answer to be in a true or false ( if this equals to something, then an action will be followed) Once I got the hang of doing this, I completed the code with the same use of different if and else statements. I put the entire code into a while loop. This is to ensure the user will click 1 2 or 3 in the beginning of the game ( and if they don’t then the computer will simply keep asking them for it. As you can see at the end of the code, a break and a print ( function_startagain ()) is used. This is two things. The first is that when you die, the program breaks, and will ask/print the function of restarting the code explained earlier.

 

if vBeginning == "2":
            print("""You get lost. You are scared, and darkness is falling. Suddenly, you fall into a pit with poisonous vipers. You die. The End.""")
            print (function_startagain())
            break
        elif vBeginning == "3":
            print("""You pick up a conch shell on the beach. Suddenly, you hear someone calling for you. """)
            v3a = input("""Do you go towards the sound (1), or ignore the call (2)?""")
            while v3a != "1" or "2":
                if v3a == "1":
                    print("""You find a chubby boy with thick spectacles stuck in brambles. You help him out, and discover his name is PIggy. He sees that you have a conch shell, and asks if you know how to blow it. You don’t, and he offers to teach you. """)
                    print(function_v3a1())
                    break
                elif v3a == "2":
                    print("You try to live alone, but you cannot manage to suffice on your own. You eventually die from starvation. ")
                    print (function_startagain())
                    break

For Sonia’s part of the code, she started  by defining all the functions first, and in the main code simply called up the functions when needed. This seems like less code, and the more efficient way to do this code, but I feel as if it could’ve gotten quite confusing with the functions and calling them up if they were questions that could’ve been simply inputs.


Lists:

fruitList = ["apple", "orange", "banana", "grape"," tomato", "mango"]
print (fruitList [1])
#by printing the string, we can also add in other brackets a number, to print one from the list
#concatenation, adds the number lists together
numberList1 = [1,2,3]
numberList2 = [6,7,8]
numberList3= numberList1 + numberList2
print (numberList3)
#doing the same thing, in fact once you get the variable defined, you don't have to write the list again.
numberList4 = (numberList2 [1])*(numberList2[2])
print ( "\n" ,numberList4,  "\n" )

To start off the lists we began with making the list itself. In order to create a list you have to use the square brackets, and name the variable. Lists are helpful for many things, especially when you want to call different parts of a list ( you then don’t have to keep defining variables, as its all in the list) I also imagine this to be helpful for data collection, and when you have lists of numbers. After making the list itself, we started to add and do different things with our lists, and combinations with the list that we have gotten. So for example, if we wanted to print the list, but we only wanted to print certain parts of the list ( like the first thing in our list, in this case  was a fruit), we could use the position of the word in our list, and the computer would print that after we define this. Furthermore, we also did some refreshing on the indentations. This indenting will definitely come in handy for our choose your own adventure game, to make it look more professional.

#slicing, you can use this:
#Slices a phrase, is the starting point and the last number is the ending point.
#If these are left blank then python assumes that the start position is the beginning of the list, and the end of the list.
print (fruitList[2:5])
print (fruitList [:4])
print (fruitList [5:])

Another fun thing we can do with our lists, is that we can slice the list. This means we can print maybe only a selected amount of the list given, or to only print part of the list. Slicing can also help with the creation of substrings.

fruitList [1] = "Kiwi" #changes the position one fruit to Kiwi Edits the list
print (fruitList)

Furthermore, in the list, we can also choose to change certain parts of the list. This means that throughout the code, you can then change certain parts of your lists at different positions.

olympicList= (["Beijing", 2010],["London", 2012],["Rio", 2016])
print (olympicList)
print (olympicList [1])
print (olympicList [1][0])

Another concept we learned was creating lists within lists. So this means you have multiple lists within the list itself. You can also call up different parts of the list, since there are multiple different parts ( you can choose to call the first part of the second part of the same list)

inventoryList = ["sword","armour","shield","healing potion"]
print ( inventoryList )
inventoryList.sort () #inserts it in the middle #sort, makes it sort
print (inventoryList)

Furthermore, you can also choose to sort different lists. This makes the list into alphabetical order.

#list count - how many times the element appears on the list
#list extend,
 #list.pop #removes an element from the list
v_fruit= fruitList.pop ()
print (fruitList)
print (v_fruit ) #this helps show what  we have removed
v_fruit1= fruitList.pop (0)
print (v_fruit1) #this is to check that it worked
fruitList.reverse ()
print (fruitList)

Another trick we learned today was list count. This counted how many times a certain element appeared on the list. There was also list extend, which helps to combine two lists into one larger list. Furthermore, the list.pop can be used to remove certain aspects of the list. We also reviewed concepts like length, in which helps calculate the length of the element, and the minimum and maximum function. Reflection: Today in class we learnt about how to make lists, and different functions that we can do with the lists, such as how to sort the list, and other helpful tips and tricks. We started to then apply these list functions, as well as inputs into a game, and a brain frame, to make a choose your own adventure game. The brain frame was really helpful in order to sort of map out what we wanted to do with our game, and what direction we were headed for it. After creating the brain frame, we were then able to create our pseudo code with a clearer message in mind. Overall, i really enjoyed the choose your own adventure, as it helped us incorporate some of our concepts, and creativity into a short game that might actually be fun to play.

fruitList = ["apple", "orange", "banana", "grape"," tomato", "mango"]
print (fruitList [1])
#by printing the string, we can also add in other brackets a number, to print one from the list
#concatenation, adds the number lists together
numberList1 = [1,2,3]
numberList2 = [6,7,8]
numberList3= numberList1 + numberList2
print (numberList3)

#doing the same thing, in fact once you get the variable defined, you don't have to write the list again.
numberList4 = (numberList2 [1])*(numberList2[2])
print ( "\n" ,numberList4,  "\n" )


#slicing, you can use this:
#Slices a phrase, is the starting point and the last number is the ending point.
#If these are left blank then python assumes that the start position is the beginning of the list, and the end of the list.
print (fruitList[2:5])
print (fruitList [:4])
print (fruitList [5:])

#this idea of slicing is taking a list, and only commanding part of it to do something
fruitList [1] = "Kiwi" #changes the position one fruit to Kiwi Edits the list
print (fruitList)

olympicList= (["Beijing", 2010],["London", 2012],["Rio", 2016])
print (olympicList)
print (olympicList [1])
print (olympicList [1][0])

#append list methods, grab things
inventoryList = ["sword","armour","shield","healing potion"]
print ( inventoryList )
inventoryList.sort () #inserts it in the middle #sort, makes it sort
print (inventoryList)

#list count - how many times the element appears on the list
#list extend,
 #list.pop #removes an element from the list
v_fruit= fruitList.pop ()
print (fruitList)
print (v_fruit ) #this helps show what  we have removed
v_fruit1= fruitList.pop (0)
print (v_fruit1) #this is to check that it worked
fruitList.reverse ()
print (fruitList)

v_index = fruitList.index ("banana") #position of banana in the List
print (v_index) #prints out wher ethe banana is in the list
print (fruitList)
print (len(fruitList))

print ( "apple" in fruitList)

print (fruitList)
print (min(fruitList))
#minimum of the list
print (fruitList)
print (max(fruitList))

The code for the game:

varglobal=0

def function_startagain ():
    startagain= input (print("Do you want to start the game again, press 1 (exit) or 2 (start again)"))
    global varglobal
    if startagain== "2":
        print (funct_game())
    if startagain==1:
        varglobal==1
def function_v3a12():
       v3a12 = input(print("""Do you fight (1) or flee(2)? """));
       if v3a12 == "1":
           print("""You both die trying to kill the wild boar. The End. """);
       if v3a12 == "2":
           print("""You run away, but a herd of pigs corner you, separating you from Piggy. You get gored to death. The End. """)
def function_v3a11():
       v3a11 = input(print("""Do you let Jack share leadership with you (1), or be a dictator (2)?"""))
       if v3a11 == "1":
           print("""You guys split the leadership and he and his choir helps the group hunt, while you and the others help create a signal fire to get rescued. Your leadership seems harmonious and works really well, living long enough to witness a plane see your signal fire and rescue you. You get rescued and return home safely. Congratulations, you’ve survived!""")
       if v3a11 == "2":
               print("""Jack gets jealous and rebels. He and his hunters become more and more uncivilised until they become savages and split from the group. Eventually, out of revenge, Jack and his choir come back and convince your crew that you are a misleading chief. Your group and Jack’s group both set out and rip you apart, until all your remains are washed out into the sea. The End.""");
def function_v3a1():
       v3a1 = input(print("""Accept (1) or decline (2)? """))
       if v3a1 == "1":
           print("""You learn to blow the conch, and when you finally succeed in making a sound, the deep note resonates through the entire island. Over the course of one hour, boys ranging from 6 year olds to 19 year olds stream out of the forest, until eventually an entire choir of boys come out, with a redhead leading the way. All the boys want you to become their leader, but the redhead, Jack, seems to want to be leader too. """);
           print(function_v3a11())
       if v3a1 == "2":
           print("""You and Piggy decide to stay and create a fire, but a wild boar stumbles towards your source of light. """);
           print(function_v3a12())


def funct_game():
    vBeginning= input("You are stuck on a deserted island, "
                       "known to be filled with mysteries of both "
                       "the past and present. You wake up on the beach "
                       "of the island with a chill up your back, and a mysterious "
                       "feeling that you are being followed. You brush yourself off,"
                       " and look around the island. Your stomach is growling, but y"
                       "ou try to think clearly about your next options. You scratch "
                       "your options into the sand:"
                       "\n" " 1. Go to the faraway abandoned hut"
                       "\n" " 2. Go into the forest "
                       "\n" " 3. Search for people.")
    while vBeginning != "1" or "2" or "3":
        if vBeginning == "1":
            print (" After long contemplation, "
                   " seeing dark clouds hovering over "
                   "the island, bursting to rain, you decide to go "
                   "to the abandoned hut and seek shelter. You enter the "
                   "hut, and notice that it looks empty.")
            vhut= input ("Explore the house (1), or hide in one "
                     "of the rooms and seek refuge just for the night? (2) ")
            if vhut== "2":
                print ("You take refuge in the kitchen and hear a man walk down the "
                        "steps of the hut.")
                vhide= input("Do you greet the man(1), or do you continue to hide.(2)")
                if vhide == "2":
                    print ("You hide, and go to the backyard of his hut. But you walk into a pit of thorns, and bleed to death. You die. The End ")
                    print (function_startagain())
                    break
                else:
                    print("The man greets you with a smile and hugs you- a weird embrace especially since you have never met him. However, during the embrace, you still don’t completely trust him, and feel his pocket. A gun shaped indent. ")
                    vgun=input ("Do you take the gun (1), or do you run for your life (2)")
                    if vgun == "2":
                        print (" You try to run, but realise this was all a dream. The hut had been latched close since you arrived. The man was watching you since you came on the island. "
                               "He chuckles softly, and whispers like the madman he is. Tears streaming down your face, you see him take a knife, and say something about adding you to his pretty collection. "
                               "You stare around the room, and realise all the monuments are dead humans. You have a panic attack, and he kills you when you have fainted. The end, you die.")
                        print (function_startagain())
                        break
                    else:
                        print ("When you take the gun you feel victorious. But as you look around, and see human heads hanging as prizes on the walls, you paralyse. "
                               "You look around, suddenly forgetting that you just stole a gun from a madman. As you look at the room, you realise that the entire room not only has bloody "
                               "human heads but also guns. Not just one gun, but many guns. Too many for your liking. But before you know it, the man shoot you five times. You die. The End.")
                        print (function_startagain())
                        break
            else:
                print ("You start to explore the rooms of the house, "
                           "and notice a lot of guns hung up on the walls. "
                           "After exploring all the rooms, and notice that the "
                           "hut is empty, you finally start to relax. You sit in "
                           "one of the lounge chairs in the main part of the hut, "
                           "but the wind blares a chilly breath of air, and you shiver. "
                           "You walk over to the window, and try to close it, but you aren’t "
                           "tall enough. You reach on your tippy-toes and try to close the "
                           "latch. Whilst doing it, you fall out the window, into a pit of "
                           "thorns. The thorns dig deep into your skin, and you bleed to "
                           "death. You die. The End.")
                print (function_startagain())
                break
        if vBeginning == "2":
            print("""You get lost. You are scared, and darkness is falling. Suddenly, you fall into a pit with poisonous vipers. You die. The End.""")
            print (function_startagain())
            break
        elif vBeginning == "3":
            print("""You pick up a conch shell on the beach. Suddenly, you hear someone calling for you. """)
            v3a = input("""Do you go towards the sound (1), or ignore the call (2)?""")
            while v3a != "1" or "2":
                if v3a == "1":
                    print("""You find a chubby boy with thick spectacles stuck in brambles. You help him out, and discover his name is PIggy. He sees that you have a conch shell, and asks if you know how to blow it. You don’t, and he offers to teach you. """)
                    print(function_v3a1())
                    break
                elif v3a == "2":
                    print("You try to live alone, but you cannot manage to suffice on your own. You eventually die from starvation. ")
                    print (function_startagain())
                    break
            break
print (funct_game())

 

 

 


 

Leave a Reply