i made a code that helped me in the exercise that aske to make lots of rooms for a game .
the code simply is a programe that let you make files write a class on them i called it a room and also excute the files
it is simple and can ease things for you if you wanna make that zork kind of games it will make modeles and excute them also
this is the full code . you code i made , you can edit it to make it better such as when writing in a file a could not figure out how to start the file modles from the beging of every line
her you are:"please try it and give me feedbacks:
from os.path import exists class Files(object): def files(self): print " what you wanna do" do = raw_input('sentance command:') if do == 'make a new file': print 'please add the file\'s format .py .txt ... at the end of the file' file_name = raw_input('file_name:') print 'checking if %s exists already:%s'% (file_name , exists(file_name)) print 'making the file' openf = open(file_name, 'w+') openf.close() print 'the file %s is successfuly created' % file_name run = Files().files() elif do == 'write in a file': file_name = raw_input('file_name:') # here the translation process should take place #for example : print"if you wanna make this room inheritce from an other ( a base)" print" enter the name of the base " print"othrwise enter object" BaseClass = raw_input('base name:') # after asking for the room name let it be %s in this ex ClassName = raw_input("enter room name:") # the program gonna ask for the datails to make a class as the user desire . description = raw_input('enter one word dedcripton for what is gonna hapen first (exmple enter for enter the room):') what_to_do = raw_input('enter a message to show to the player:') conditon = raw_input('enter what is the rigiht choice for the player to pass this stage, one word is preferable:') say_when_sacceed = raw_input('enter ta message to show to the player if he made the right choice:') where_to_go_after = raw_input('enter an exicting room that the player will go to after passing this one:') when_wrong_go_to = raw_input('enter an exicting room that the player will go to if his choice is wrong:') room ='''class %s(%s): def %s(self): print '%s' entry = raw_input(":") if entry == '%s': print '%s' return '%s' else: return '%s' clas = %s() ''' % (ClassName, BaseClass, description ,what_to_do ,conditon ,say_when_sacceed, where_to_go_after, when_wrong_go_to, ClassName) openf= open(file_name,'w') openf.write(room) print 'room created' openf.close() run = Files().files() elif do == 'excute a file': file_name = raw_input('enter a file name to excute:') if exists('%s.py'% file_name) == True : a=__import__(file_name) while True: play = a.clas.enter() print 'moving to level %s' %play a = __import__(play) else: print 'the file you want to excut does not exist' run = Files().files() run = Files().files() else: print 'santence command not availble' print '''availble commands are : 1- make a new file 2- write in a file : this may make the the file if it does'nt exist already 3- excute a file : excuting existing files ''' run = Files().files() run = Files().files()
if you are using pythn3 just change raw_input into input() and print"" to print("")
i think then it will work
i copy past it to you so you can copy past it to your editor and edit it and send me what you did in it to make it better and what bugs did you find in it .