Advertisement
DrAungWinHtut

gui.py

Apr 8th, 2023
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. def showGui(x,y,max_x,max_y):
  2.     if y >= max_y or x >= max_x:
  3.         print('Error, beyound the screen')
  4.     # strar line creation
  5.     str = ''
  6.     for i in range(max_x):
  7.         str += '*'
  8.  
  9.     # boundary line creation
  10.     str1 ='*'
  11.     for i in range(max_x-2):
  12.         str1+=' '
  13.     str1+='*'
  14.  
  15.     # boundary line + avater creation
  16.     # *space#space*
  17.     avater='*'
  18.     for i in range(x-2):
  19.         avater+=' '
  20.     avater+='#'
  21.     for i in range(max_x-x-1):
  22.         avater+=' '
  23.     avater+='*'
  24.  
  25.     print(str) # first star line
  26.     for i in range(y-2):
  27.         print(str1)
  28.     print(avater)
  29.     for i in range(max_y-y-1):
  30.         print(str1)
  31.     print(str) # last star line
  32. #showGui end here
  33.  
  34.  
  35. # Main program start here
  36.  
  37. max_x=40
  38. max_y=20
  39. x = 3
  40. y = 3
  41. ans = ''
  42.  
  43. showGui(x,y,max_x,max_y)
  44.  
  45. while ans!='q':
  46.     ans = input()
  47.     if ans == 'q':
  48.         exit()
  49.     elif ans == 'a':
  50.         x-=1
  51.         if x < 2:
  52.             x = 2
  53.     elif ans == 'd':
  54.         x+=1
  55.         if x > max_x-1:
  56.             x = max_x-1
  57.     elif ans == 'w':
  58.         y-=1
  59.         if y < 2:
  60.             y = 2
  61.     elif ans == 's':
  62.         y+=1
  63.         if y > max_y-1:
  64.             y = max_y-1
  65.    
  66.     showGui(x,y,max_x,max_y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement