Advertisement
DrAungWinHtut

advanturegame.py

Jul 20th, 2023
781
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 1 0
  1. import os
  2. import random
  3. import msvcrt
  4.  
  5. def advanture_game():
  6.     x_min = 0
  7.     x_max = 10
  8.     y_min = 0
  9.     y_max = 10
  10.     player_x = 5
  11.     player_y = 5
  12.  
  13.     # q = quit
  14.     while 1:
  15.         key = msvcrt.getch().decode()
  16.         if key == 'a':
  17.             player_x = player_x - 1
  18.             if player_x < x_min:
  19.                 player_x = x_min
  20.        
  21.         if key == 'd':
  22.             player_x = player_x + 1
  23.             if player_x > x_max:
  24.                 player_x = x_max
  25.        
  26.         if key == 'w':
  27.             player_y = player_y - 1
  28.             if player_y < y_min:
  29.                 player_y = y_min
  30.        
  31.         if key == 's':
  32.             player_y = player_y + 1
  33.             if player_y > y_max:
  34.                 player_y = y_max
  35.        
  36.         if key == 'q':
  37.             print('Exiting advanture game')
  38.             start()
  39.        
  40.         print(f'Player location is x={player_x},y={player_y}')
  41.         for i in range(0,player_y):
  42.             print()
  43.         avater = ''
  44.         for i in range(0,player_x):
  45.             avater = avater + '  '
  46.         avater = avater + '*'
  47.         print(avater)
  48.        
  49.  
  50.  
  51.    
  52.  
  53. def lucky_test():
  54.     os.system('cls')
  55.     day = eval(input('please enter the day: '))
  56.     month = eval(input('please enter the month: '))
  57.     year = eval(input('please enter the year: '))
  58.     num =  day + (month*12) + (year * 365)
  59.     ans = num % 3
  60.    
  61.     if ans == 0:
  62.         print("Bad Luck")
  63.     elif ans == 1:
  64.         print("Normal")
  65.     else:
  66.         print("Lucky")
  67.     os.system('pause')
  68.  
  69. def dice_game():
  70.     os.system('cls')    
  71.     player = random.randint(1,6)
  72.     computer = random.randint(1,6)
  73.     print('Press any key to roll the dice')
  74.     os.system('pause')
  75.     print(f'player: {player}')
  76.     print('Press any key to roll the dice for computer')
  77.     os.system('pause')
  78.     print(f'computer: {computer}')
  79.     if player > computer:
  80.         print('You win!')
  81.     elif computer > player:
  82.         print('You lose!')
  83.     else:
  84.         print('Draw')
  85.     os.system('pause')
  86.  
  87.    
  88.  
  89.  
  90. def start():
  91.     os.system('cls')
  92.     print('0-exit')
  93.     print('1-baydin app')
  94.     print('2-dice game')
  95.     print('3-advanture game')
  96.    
  97.     choice = input('what is your choice? ')
  98.     if choice == '0':
  99.         print('exiting...')
  100.         os.system('cls')
  101.         exit()        
  102.     elif choice == '1':
  103.         lucky_test()
  104.        
  105.     elif choice == '2':
  106.         dice_game()
  107.     elif choice == '3':
  108.         advanture_game()
  109.     start()
  110.        
  111.    
  112.  
  113.    
  114. # Start here
  115. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement