Advertisement
DrAungWinHtut

adventure4update.py

Mar 26th, 2023
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. hx = 6
  2. hy = 3
  3.  
  4. sbx1 = 1
  5. sby1 = 3
  6. stx1 = 2
  7. sty1 = 1
  8.  
  9. sbx2 = 1
  10. sby2 = 8
  11. stx2 = 2
  12. sty2 = 6
  13.  
  14. dbx1 = 3
  15. dby1 = 3
  16. dtx1 = 4
  17. dty1 = 1
  18.  
  19. dbx2 = 5
  20. dby2 = 5
  21. dtx2 = 6
  22. dty2 = 1
  23.  
  24. ux = 5
  25. uy = 5
  26.  
  27. ans = 'start'
  28.  
  29. marks = 100
  30.  
  31. filename = 'd:\\gamedata.txt'
  32. log_file = open(filename, 'a')
  33. print("Game is Starting...")
  34. print("Game Control a-left,d-right,w-up,s-down,q-quit...")
  35. print("Your Starting Position is x={} and y={}".format(ux, uy))
  36. log_file.write('x={},y={}\n'.format(ux, uy))
  37. print()
  38. print()
  39.  
  40. while ans != 'q':
  41.  
  42.     ans = input(">>>")
  43.     marks = marks - 1
  44.     if ans == 'a':
  45.         ux = ux - 1
  46.         if ux < 1:
  47.             ux = 1
  48.     elif ans == 'd':
  49.         ux = ux + 1
  50.         if ux > 10:
  51.             ux = 10
  52.     elif ans == 'w':
  53.         uy = uy - 1
  54.         if uy < 1:
  55.             uy = 1
  56.     elif ans == 's':
  57.         uy = uy + 1
  58.         if uy > 10:
  59.             uy = 10
  60.  
  61.     print("Your Current Position is x={} and y={}".format(ux, uy))
  62.     log_file.write(
  63.         'Your Current Position is x={} and y={}\n'.format(ux, uy))
  64.  
  65.     if (ux == sbx1) and (uy == sby1):
  66.         ux = stx1
  67.         uy = sty1
  68.         print("Wow Stair!!!!\nYour Current Position is x={} and y={}".format(ux, uy))
  69.         log_file.write(
  70.             "Wow Stair!!!!\nYour Current Position is x={} and y={}\n".format(ux, uy))
  71.  
  72.     elif (ux == sbx2) and (uy == sby2):
  73.         ux = stx2
  74.         uy = sty2
  75.         print("Wow Stair!!!!\nYour Current Position is x={} and y={}".format(ux, uy))
  76.         log_file.write(
  77.             "Wow Stair!!!!\nYour Current Position is x={} and y={}\n".format(ux, uy))
  78.     elif (ux == dtx1) and (uy == dty1):
  79.         ux = dbx1
  80.         uy = dby1
  81.         print("Ahhh Snake!!!!\nYour Current Position is x={} and y={}".format(ux, uy))
  82.         log_file.write(
  83.             "Ahhh Snake!!!!\nYour Current Position is x={} and y={}\n".format(ux, uy))
  84.     elif (ux == dtx2) and (uy == dty2):
  85.         ux = dbx2
  86.         uy = dby2
  87.         print("Ahhh Snake!!!!\nYour Current Position is x={} and y={}".format(ux, uy))
  88.         log_file.write(
  89.             "Ahhh Snake!!!!\nYour Current Position is x={} and y={}\n".format(ux, uy))
  90.     elif (ux == hx) and (uy == hy):
  91.         print("Finally, Home Sweet Home!!!")
  92.         log_file.write("Finally, Home Sweet Home!!!\n")
  93.         print("your mark is {}".format(marks))
  94.         log_file.write("your mark is {}\n".format(marks))
  95.         log_file.close()
  96.         exit()
  97.  
  98. log_file.close()
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement