# Introduction narration of game
# https://github.com/iamjawa/zork-py/blob/master/zork.py
# Do What The F*ck You Want To Public License
fromtimeimportsleepdefcenter_texte(texte,sep=""):'''Cette fonction affiche un texte dans la console et le centre'''f=max(0,(30-len(texte))//2-2)print(sep*f+""+texte+""+sep*f)defsplit_text(text):'''Cette fonction coupe un texte en phrase de longueur <30'''words=text.split()split_text=[]current_string=""forwordinwords:iflen(current_string+""+word)<=30:current_string+=""+wordifword[-1]in("!",":",",","?",".")andlen(current_string)>15:#print("******")
split_text.append(current_string.strip())current_string=""else:split_text.append(current_string.strip())current_string=wordsplit_text.append(current_string.strip())returnsplit_textdefscroll_text(text):'''Cette fonction affiche des lignes de texte avec des pauses'''forligneinsplit_text(text):ifligne!="":print(ligne)#sleep(1.42)
defhelp():print("*"*28)center_texte(" help","*")print("*"*28)scroll_text("To play, you must describe the player's actions. An action is generally composed of a verb followed by a direction, a place, an object.")# Ne pas lire le code sous cette ligne sinon le jeu n'aura plus aucun intérêt.
# todo : Chiffrer le texte. Ecrire une fontion de chiffrage / déchiffrage.
defgame():loop=4print("*"*28)center_texte(" Welcome to Zork I","*")center_texte(" nsi.xyz/zork ","*")center_texte("text-based adventure game","*")whileTrue:# First Input Loop
whileloop==4:print("-"*28)ifloop==4:scroll_text("You are standing in an open field west of a white house, with a boarded front door.")scroll_text("(A secret path leads southwest into the forest.)")scroll_text("There is a Small Mailbox.")inp=input("What do you do?\n> ").lower()ifinp==("take mailbox"):scroll_text("It is securely anchored.")elifinp==("open mailbox"):scroll_text("Opening the small mailbox reveals a leaflet.")elifinp==("go east"):scroll_text("The door is boarded and you cannot remove the boards.")elifinp==("open door"):scroll_text("The door cannot be opened.")elifinp==("take boards"):scroll_text("The boards are securely fastened.")elifinp==("look at house"):scroll_text("The house is a beautiful colonial house which is painted white. It is clear that the owners must have been extremely wealthy.")elifinp==("go southwest"):loop=8elifinp==("read leaflet"):scroll_text("Welcome to the Unofficial Python Version of Zork. Your mission is to find a Jade Statue.")elifinp==("help"):help()else:scroll_text("# invalid action")# Southwest Loop
whileloop==8:print("-"*28)ifloop==8:scroll_text("This is a forest, with trees in all directions. To the east, there appears to be sunlight.")forest_inp=input("What do you do?\n> ")ifforest_inp==("go west"):scroll_text("You would need a machete to go further west.")elifforest_inp==("go north"):scroll_text("The forest becomes impenetrable to the North.")elifforest_inp==("go south"):scroll_text("Storm-tossed trees block your way.")elifforest_inp==("go east"):loop=9elifinp==("help"):help()elifinp==("go back"):loop=4else:scroll_text("# invalid action")# East Loop and Grating Input
whileloop==9:print("-"*28)ifloop==9:scroll_text("You are in a clearing, with a forest surrounding you on all sides. A path leads south.")scroll_text("There is an open grating, descending into darkness.")grating_inp=input("What do you do?\n> ")ifgrating_inp==("go south"):scroll_text("You see a large ogre and turn around.")elifgrating_inp==("descend grating"):loop=10elifinp==("help"):help()elifinp==("go back"):loop=8else:scroll_text("# invalid action")# Grating Loop and Cave Input
whileloop==10:print("-"*28)ifloop==10:scroll_text("You are in a tiny cave with a dark, forbidding staircase leading down.")scroll_text("There is a skeleton of a human male in one corner.")cave_inp=input("What do you do?\n> ")ifcave_inp==("descend staircase"):loop=11elifcave_inp==("take skeleton"):scroll_text("Why would you do that? Are you some sort of sicko?")elifcave_inp==("smash skeleton"):scroll_text("Sick person. Have some respect mate.")elifcave_inp==("light up room"):scroll_text("You would need a torch or lamp to do that.")elifcave_inp==("break skeleton"):scroll_text("I have two questions: Why and With What?")elifcave_inp==("go down staircase"):loop=11elifcave_inp==("scale staircase"):loop=11elifcave_inp==("suicide"):scroll_text("You throw yourself down the staircase as an attempt at suicide. You die.")print("-"*28)suicide_inp=input("Do you want to continue? Y/N\n> ")ifsuicide_inp==("n"):exit()ifsuicide_inp==("y"):loop=4elifcave_inp==("scale staircase"):loop=11elifinp==("help"):help()elifinp==("go back"):loop=9else:scroll_text("# invalid action")# End of game
whileloop==11:print("-"*28)ifloop==11:scroll_text("You have entered a mud-floored room.")scroll_text("Lying half buried in the mud is an old trunk, bulging with jewels.")last_inp=input("What do you do?\n> ")iflast_inp==("open trunk"):scroll_text("You have found the Jade Statue and have completed your quest!")exit()elifinp==("help"):help()elifinp==("go back"):loop=10else:scroll_text("# invalid action")game()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.