Red Security

Full Version: Let's Code: Making a Text-Based-Adventure Game in Python Part.1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[Image: images?q=tbn:ANd9GcQljivNXYiG-119Ki2aVzC...n5sRRWsNmw]


                  Hello everyone, It is I, the Mad-Architect. Let's Code shall we? Right now, I am working on a personal project, and with that said, it was going to remain personal, until a high number of people on the Discord server started asking for tutorials on Python, granted we do have quite a few in the forum, I felt it was only right that I added my project to the mix, to ensure that you, the users in our community, have what they need to advance their skills. 

        So right now, lets start with a run-down of what this part will look like, once it is finished. 
   
 
        -------------------------------------------------------------------------------
               
Code:
print ("Welcome, we have been waiting for you")

Gender = input("What type of human are you?" )
male = 'male'
female = 'female'

if Gender == male:
print ("Ahh, a man of action, here here!")
elif Gender == female:
print ("A woman, we shall see what you have to bring to the table.")
else:
print ("Please choose a gender.")

                  
        ------------------------------------------------------------------------------


         So of course, at the beginning of this, I mentioned we are making a text-based adventure game. This block of code refers to a starting point in the game, where we can choose our character's gender. So obviously this is not the full program; this is merely a smaller program that we are able to "import" into the larger program when it is needed or "called". 

         Creating smaller files, that help make up the larger program, helps to organize files and assist in making the overall layout less messy. Also helps for debugging. 

         So in the first part, I use *print* to print out a string, this string is greeting the player, stating that they have been waiting for them. Right after this, the program asks for the player's character's gender. I did this, when I typed *Gender = input*.

         
          <<Gender = input("What type of human are you?" )>>


                      So the variable *gender* is equal to user input. At the same time, it is printing a string, a question that asks "What type of human are you?" <<YOUR INPUT WOULD GO HERE>>
           

           Pretty simple, now after this, its only two simple variables that are equal to themselves. These are the way they are, because of the next set of code that we are going to use. 



           male = 'male'

           female = 'female'

          Remember to include the single quotes around the values, otherwise you will spend the next ten to twenty minutes trying to figure out why they're not defined. 
            


           if Gender == male:

                 print ("Ahh, a man of action, here here!")
                 elif Gender == female:
                 print ("A woman, we shall see what you have to bring to the table.")
                 else:
                 print ("Please choose a gender.")





           Now, the *if statements* are fun, a lot can be done with them. In this statement in particular, is for when we are choosing our character's gender. Certain responses have been coded into the game, so that we receive a certain response depending on what gender we choose, also if we don't choose one. Just type everything as it is, and it should work. 
 

            I hope you all found this helpful, if there is anything you need ask to me about it, just hit me up on the Discord server. Also, what I used for this project, was Notepad++ and just the Windows Command Line. 

            Exp: Go to the Search bar in the lower left hand corner, and type in CMD, this will bring up the Windows Command Line, and from here just type [CD/cd Desktop] and it will change to the Desktop directory, from here, type [python Gen_Part_Start.py] That is how the program should be saved, including the python file extension. 




            Again, just let me know if anything goes wrong with the program, I cannot say when the next part will be out, but it is coming, so have a good week folks, and stay safe out there. 


            --Mad-Architect
Nice tutorial bro, I liked it and liked the idea of explaining if statement.
Keep it up.
Thanks Kurd, will do Smile