Hello, Python Forum I am Prrz and this is my first post here in the interesting land of Python developers.
I've decided recently to start teaching myself how to code, and naturally, I started with python. In my earlier years, I've dabbled with a ton of C, C++, SQL, PHP, HTML, blah blah. Of course, Python was very enticing to start with on my adventure towards learning to truly code. (In the past, I was very young and butchering other peoples works because I found it extremely interesting, copy and pasting code without ever understanding what was going on in the first place. Simply for fun.)
Anyway, I've been writing a simple text based RPG based on a Homework assignment given to me in the book "Learn python the hard way". Here's what I have so far after about two days work, it's very incomplete but I'll post updates as time goes on. Feedback and suggestions are highly appreciated. (Please keep in mind the story is highly a work in progress, I've been more focused on functionality.)
I've decided recently to start teaching myself how to code, and naturally, I started with python. In my earlier years, I've dabbled with a ton of C, C++, SQL, PHP, HTML, blah blah. Of course, Python was very enticing to start with on my adventure towards learning to truly code. (In the past, I was very young and butchering other peoples works because I found it extremely interesting, copy and pasting code without ever understanding what was going on in the first place. Simply for fun.)
Anyway, I've been writing a simple text based RPG based on a Homework assignment given to me in the book "Learn python the hard way". Here's what I have so far after about two days work, it's very incomplete but I'll post updates as time goes on. Feedback and suggestions are highly appreciated. (Please keep in mind the story is highly a work in progress, I've been more focused on functionality.)
# A Game by Prrz in the year 2017 as a self-taught project. from sys import exit # Variables # Must be called using global name = " " gold = 0 player_health = 100 # Weapon Damage damage_base = 0 damage_punch = damage_base + 2 damage_kick = damage_base + 4 damage_bat = damage_base + 8 damage_golfclub = damage_base + 12 damage_knife = damage_base + 15 # Weapons... checks if player has any of them. bat = 0 golfclub = 0 knife = 0 weapons = ['BAT', '9 IRON', 'KNIFE'] # Enemies health_enemy1 = 25 dead_enemy1 = 0 # Items flashlight = 0 downstairs_bathroom_key = 0 # Room instances problem_solved = 0 light_on_downstairs = 0 def check_gold(): global gold print "My Gold = ",gold def check_health(): global health_player print "Current Health = ",health_player def help(): print """ COMMANDS: View (object) (Make sure you use the full name.) North, South, East, West Loot (item) Gold Health Location (Explains where you currently are.) """ print "Examples: View Shelf / Loot Lighter / North or N etc." print "Capitalization of commands doesn't matter.\n" print "Commands are unique to each room, you will be prompted when more become available." def start_room(): print "\n ~~ ENTRANCE ROOM ~~" global light_on_downstairs if light_on_downstairs == 1: print """ The room is much larger than you expected. You can see bookshelves on the southern wall next to the door, hanging chandeliers, a spiral staircase to the North, and doors leading out the East and the West. Despite the home being much plainer than you ever imagined, it makes up for it with spaciousness and perhaps most surprisingly, cleanliness. """ start_prompt() else: print "\nYou find yourself in a large room, it's dark and you can't see anything." print "I should try and find a light switch... Which direction should I go?" print "North, South, East or West." print "Type HELP for more details on commands." start_prompt() def start_prompt(): check_player_health() start_commands = raw_input("\nEntrance Room Command: ").upper() if start_commands == "N" or start_commands == "NORTH": spiral_staircase_up() elif start_commands == "S" or start_commands == "SOUTH": main_door() elif start_commands == "E" or start_commands == "EAST": kitchen() elif start_commands == "W" or start_commands == "WEST": downstairs_bathroom() elif start_commands == "H" or start_commands == "HELP": help() start_prompt() elif start_commands == "G" or start_commands == "GOLD": check_gold() start_prompt() elif start_commands == "HEALTH": check_health() start_prompt() elif start_commands == "VIEW": if light_on_downstairs == 0: print "It's too dark in here to see anything, not much to look at." start_prompt() else: print "Everything is well lit, what a beautiful home..." start_prompt() elif start_commands == "LOCATION": start_room() else: print "I don't think I'm doing this right." start_prompt() def main_door(): check_player_health() global light_on_downstairs if light_on_downstairs == 0: print """ When you examine the door more closely you notice it has no knob or hinges. However you notice a light switch and flick the lights on. """ light_on_downstairs = 1 start_prompt() else: print """ When you examine the door more closely you notice it has no knob or hinges. """ start_prompt() def kitchen(): check_player_health() global light_on_downstairs if light_on_downstairs == 0: print "It's way too dark, no way I'm going anywhere without light." start_prompt() else: kitchen_gateway() def kitchen_gateway(): global name global problem_solved if problem_solved == 0: print "You see a note on the door." print """ Ah, it seems like you've found the light switch %s! Way to go, you're probably wondering who I am and where YOU are by now... you'll find out in due time. At any rate, you'll need to solve this little problem I've given to you! Why? Well frankly it's quite boring in here being all alone...\n """ % name kitchen_problem() else: kitchen_solved() def kitchen_problem(): check_player_health() global problem_solved global player_health print "You're stuck until this is solved!" kitchen = raw_input("Solve: 6 / 2(1 + 2) = ") if kitchen == "9": problem_solved = 1 print "Well done %s, let me open this door for you. " % name print "The door mysteriously starts to open itself." kitchen_solved() elif kitchen == "1": player_health -= 100 kitchen_problem() else: print """ You feel like you've been burned from the inside out. Like someone lit a lighter inside of your stomach. (- 5 hp) """ player_health -= 5 kitchen_problem() def kitchen_solved(): if flashlight == 0: print """ The light creeps through the open doorway just enough for you to see that the kitchen looks impressively well maintained. It has beautiful marble counter-tops, tile floors, and oak cabinets. You don't feel comfortable going much further without a source of light... I really should find a flashlight. """ start_prompt() else: start_prompt() def downstairs_bathroom(): global downstairs_bathroom_key global name if downstairs_bathroom_key == 1: print "You enter the room." else: print """ For whatever reason you decide to knock on the door, from the inside you hear a voice 'Hello again %s, nice to see you mate. I'm a bit busy in here, comeback later.' """ % name print "You notice a keyhole, maybe there's a key somewhere?" start_prompt() def spiral_staircase_up(): check_player_health() global light_on_downstairs if light_on_downstairs == 1: upstairs() else: print """ You knock your shins against something solid and fall flat on your face. Falling down you quickly realize that these are stairs... """ print "It's way too dark, no way I'm going anywhere without light." start_prompt() def upstairs(): check_player_health() global flashlight if flashlight == 0: print """ Unfortunately, the lights are only on downstairs, it's still much too dark to see up here. Maybe I can find something to light the way? """ start_prompt() else: upstairs_prompt() def upstairs_prompt(): print "Blah" def check_player_health(): global player_health if player_health <= 0: dead() else: return def dead(): print "Filler text. You died.\n" restart = raw_input("Try Again? Y / N ").upper() if restart == "Y": start() else: exit(0) def start(): global name print """ ~~ March 23rd, 2171 ~~ The birds are chirping... oh what a beautiful morning. I rub my eyes as sit up in my bed, rubbing the sleepiness out of them with each motion. As my eyes adjust and the room comes into focus I realize immediately that something is wrong with this scene... Why am I outside? Everything around me is DARK, very dark actually. Is it still nighttime? Hmm.. my phone says 8:00AM, the sun should have very well risen by this time. My phone isn't working beyond telling the time, none of its functions are... functional. As I step off my bed it disappears like it was never real in the first place. All that I can see is a door and a small light illuminating the surrounding area. Everything else around me is utterly blank as if something is directing me straight to this door... As I approach the door I find a small note on it, it reads:\n Hello... uhm. What's your name? Just write it on the note, I'll be able to read it.""" name = raw_input("\n My name is: ") print "Great, thanks %s" % name print """The door opens automatically' and you feel drawn to it. \nThis is where it all began.""" start_room() start()