Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys, tty, termios
- def key_pressed(char_width=1):
- fd = sys.stdin.fileno()
- old_settings = termios.tcgetattr(fd)
- try:
- tty.setraw(sys.stdin.fileno())
- ch = sys.stdin.read(char_width)
- finally:
- termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
- return ch
- def print_board(town_size,message=""):
- print("\n"*75)
- print(message)
- for row in range(town_size):
- for col in range(town_size):
- token = board[row][col]
- if not token:
- token = ""
- print(token,end="")
- print()
- def in_ariel(town_size):
- board = []
- for row_num in range(town_size):
- row = []
- for col_num in range(town_size):
- row.append(". ")
- board.append(row)
- #{Alliance HQ
- for x in range(35,44):
- board[0][x] = "--"
- board[10][x] = "--"
- for x in range(0,10):
- board[x][35] = "|"
- board[x][44] = "|"
- for x in range(39,40):
- board[10][x] = "^^"
- for x in range(1,10):
- for y in range(36,44):
- board[x][y] = " "
- # }
- return board
- def in_ariel_hq(town_size):
- board = []
- for row_num in range(town_size):
- row = []
- for col_num in range(town_size):
- row.append(". ")
- board.append(row)
- board[town_size -1][9] ="| "
- board[town_size -1][11] ="| "
- board[town_size -2][9] ="| "
- board[town_size -2][11] ="| "
- for x in range(town_size):
- board[13][x] = "##"
- board[13][10] = "~"
- return board
- def control(current_row,current_col,old_row,old_col,town_size):
- kp = key_pressed()
- if kp == "j" or kp == "s":
- if current_row <town_size -1:
- if board[current_row + 1][current_col] == empty:
- current_row +=1
- if kp == "k" or kp == "w":
- if current_row > 0:
- if board[current_row -1][current_col] == empty:
- current_row -=1
- if kp == "h" or kp == "a":
- if current_col >0:
- if board[current_row][current_col - 1] == empty:
- current_col -=1
- if kp == "l" or kp == "d":
- if current_col < town_size -1:
- if board[current_row][current_col +1] == empty:
- current_col +=1
- return current_row,current_col
- def start_pos(town_size):
- old_row,old_col = 0,0
- current_row = town_size -2
- current_col = int(town_size/2)
- return current_row,current_col,old_row,old_col
- player = "@ "
- empty = ". "
- ariel = 45
- ariel_hq = 20
- hq_cords = [11,39]
- old_row = 0
- old_col = 0
- current_row = 44
- current_col = 20
- playing = True
- while playing == True:
- board = in_ariel(ariel)
- board[old_row][old_col] = empty
- board[current_row][current_col] = player
- print_board(ariel,"ARIEL CITY")
- old_row,old_col, = current_row,current_col
- if current_row == hq_cords[0] and current_col == hq_cords[1]:
- current_row, current_col,old_row,old_col = start_pos(ariel_hq)
- inplace = True
- while inplace == True:
- board = in_ariel_hq(ariel_hq)
- board[old_row][old_col] = empty
- board[current_row][current_col] = player
- print_board(ariel_hq,"ALLIENCE HQ")
- old_row,old_col, = current_row,current_col
- if current_row == 19 and current_col == 10:
- current_row,current_col = 12,39
- break
- else:
- current_row,current_col = control(current_row,current_col,old_row,old_col,ariel_hq)
- else:
- current_row,current_col = control(current_row,current_col,old_row,old_col,ariel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement