Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.75 KB | None | 0 0
  1. import os, sys, tty, termios
  2.  
  3. def key_pressed(char_width=1):
  4.     fd = sys.stdin.fileno()
  5.     old_settings = termios.tcgetattr(fd)
  6.     try:
  7.         tty.setraw(sys.stdin.fileno())
  8.         ch = sys.stdin.read(char_width)
  9.     finally:
  10.         termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
  11.     return ch
  12.  
  13. def print_board(town_size,message=""):
  14.   print("\n"*75)
  15.   print(message)
  16.  
  17.   for row in range(town_size):
  18.     for col in range(town_size):
  19.         token = board[row][col]
  20.         if not token:
  21.             token = ""
  22.         print(token,end="")
  23.     print()
  24.  
  25.  
  26. def in_ariel(town_size):
  27.     board = []
  28.     for row_num in range(town_size):
  29.         row = []
  30.         for col_num in range(town_size):
  31.             row.append(". ")
  32.         board.append(row)
  33.  
  34.   #{Alliance HQ
  35.     for x in range(35,44):
  36.         board[0][x] = "--"
  37.         board[10][x] = "--"
  38.     for x in range(0,10):
  39.         board[x][35] = "|"
  40.         board[x][44] = "|"  
  41.     for x in range(39,40):
  42.         board[10][x] = "^^"            
  43.     for x in range(1,10):
  44.         for y in range(36,44):
  45.             board[x][y] = "  "
  46.   # }
  47.        
  48.     return board
  49.  
  50.  
  51. def in_ariel_hq(town_size):
  52.     board = []
  53.     for row_num in range(town_size):
  54.         row = []
  55.         for col_num in range(town_size):
  56.             row.append(". ")
  57.         board.append(row)
  58.  
  59.     board[town_size -1][9] ="| "
  60.     board[town_size -1][11] ="| "
  61.     board[town_size -2][9] ="| "
  62.     board[town_size -2][11] ="| "
  63.  
  64.     for x in range(town_size):
  65.         board[13][x] = "##"
  66.     board[13][10] = "~"
  67.        
  68.     return board
  69.  
  70.  
  71. def control(current_row,current_col,old_row,old_col,town_size):
  72.     kp = key_pressed()
  73.  
  74.     if kp == "j" or kp == "s":
  75.         if current_row <town_size -1:
  76.             if board[current_row + 1][current_col] == empty:
  77.                 current_row +=1
  78.     if kp == "k" or kp == "w":
  79.         if current_row > 0:
  80.             if board[current_row -1][current_col] == empty:
  81.                 current_row -=1
  82.     if kp == "h" or kp == "a":
  83.         if current_col >0:
  84.             if board[current_row][current_col - 1] == empty:
  85.                 current_col -=1
  86.     if kp == "l" or kp == "d":
  87.         if current_col < town_size -1:
  88.             if board[current_row][current_col +1] == empty:
  89.                 current_col +=1
  90.     return current_row,current_col
  91.  
  92. def start_pos(town_size):
  93.     old_row,old_col = 0,0
  94.     current_row = town_size -2
  95.     current_col = int(town_size/2)
  96.     return current_row,current_col,old_row,old_col
  97.  
  98.  
  99. player = "@ "
  100. empty = ". "
  101.  
  102.  
  103. ariel = 45
  104.  
  105. ariel_hq = 20
  106. hq_cords = [11,39]
  107.  
  108.  
  109. old_row = 0
  110. old_col = 0
  111. current_row = 44  
  112. current_col = 20
  113.  
  114.  
  115.  
  116. playing = True
  117. while playing == True:
  118.  
  119.     board = in_ariel(ariel)
  120.     board[old_row][old_col] = empty    
  121.     board[current_row][current_col] = player      
  122.  
  123.     print_board(ariel,"ARIEL CITY")
  124.     old_row,old_col, = current_row,current_col
  125.  
  126.  
  127.     if current_row == hq_cords[0] and current_col == hq_cords[1]:
  128.         current_row, current_col,old_row,old_col = start_pos(ariel_hq)
  129.  
  130.  
  131.         inplace = True
  132.         while inplace == True:
  133.             board = in_ariel_hq(ariel_hq)
  134.             board[old_row][old_col] = empty    
  135.             board[current_row][current_col] = player
  136.  
  137.             print_board(ariel_hq,"ALLIENCE HQ")
  138.             old_row,old_col, = current_row,current_col
  139.  
  140.             if current_row == 19 and current_col == 10:
  141.                 current_row,current_col = 12,39
  142.                 break
  143.             else:
  144.                 current_row,current_col = control(current_row,current_col,old_row,old_col,ariel_hq)
  145.  
  146.            
  147.     else:
  148.         current_row,current_col = control(current_row,current_col,old_row,old_col,ariel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement