Advertisement
DrAungWinHtut

adventure4.py

Apr 1st, 2023
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1.  
  2. import os
  3. gx = 55
  4. gy = 45
  5.  
  6. tx = 48
  7. ty = 40
  8.  
  9. ux = 50
  10. uy = 50
  11.  
  12. ans = 'start'
  13.  
  14. marks = 100
  15.  
  16. name = input('What is your name (no space please): ')
  17. file_name = 'D:\\game\\'+name+'.txt'
  18. command = 'notepad '+file_name
  19.  
  20. game_file = open('d:\\gamedata.txt', 'a')
  21. leader_board = open(file_name, 'a')
  22.  
  23. print("Game is Starting...")
  24. print("Game Control a-left,d-right,w-up,s-down,q-quit...")
  25. print("Your Starting Position is x={} and y={}".format(ux, uy))
  26. game_file.write("Your Starting Position is x={} and y={}\n".format(ux, uy))
  27. print()
  28. print()
  29.  
  30. while ans != 'q':
  31.  
  32.     ans = input(">>>")
  33.     game_file.write(ans+'\n')
  34.     marks = marks - 1
  35.     if ans == 'a':
  36.         ux = ux - 1
  37.     elif ans == 'd':
  38.         ux = ux + 1
  39.     elif ans == 'w':
  40.         uy = uy - 1
  41.     elif ans == 's':
  42.         uy = uy + 1
  43.     elif ans == 'q':
  44.         leader_board.write(str(marks)+'\n')
  45.         game_file.close()
  46.         leader_board.close()
  47.         os.system(command)
  48.         exit()
  49.  
  50.     print("Your Current Position is x={} and y={}".format(ux, uy))
  51.     game_file.write("Your Current Position is x={} and y={}\n".format(ux, uy))
  52.  
  53.     if (ux == gx) and (uy == gy):
  54.         print("you found the gold bag!!!")
  55.         game_file.write("you found the gold bag!!!\n")
  56.         print("your marks is {}".format(marks))
  57.         game_file.write("your marks is {}\n".format(marks))
  58.         leader_board.write(str(marks)+'\n')
  59.         leader_board.close()
  60.         game_file.close()
  61.         os.system(command)
  62.         exit()
  63.     elif (ux == tx) and (uy == ty):
  64.         print("you fall into the trap, GAME OVER!!!")
  65.         game_file.write("you fall into the trap, GAME OVER!!!\n")
  66.         print("your marks is {}".format(marks))
  67.         game_file.write("your marks is {}\n".format(marks))
  68.         leader_board.write(str(marks)+'\n')
  69.         leader_board.close()
  70.         game_file.close()
  71.         os.system(command)
  72.         exit()
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement