本文整理汇总了Python中File.File.error方法的典型用法代码示例。如果您正苦于以下问题:Python File.error方法的具体用法?Python File.error怎么用?Python File.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File.File
的用法示例。
在下文中一共展示了File.error方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ask_piece
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import error [as 别名]
def ask_piece(self, board, player_x, player_y, remain):
File.prompt("ADD PIECE TO BOARD?")
i = 0
for p in remain:
i += 1
File.print(str(i) + ") " + p)
n = len(remain)
option = input("Select [1-" + str(n) + "]: ")
try:
option = int(option)
except ValueError: self.ask_piece(board, player_x, player_y, remain)
if option <= n and option > 0 and n > 1:
piece_name = remain[option-1]
self.insert_piece(board, piece_name, player_x, player_y)
remain.pop(option-1)
self.ask_piece(board, player_x, player_y, remain)
elif option <= n and option > 0:
piece_name = remain[option-1]
self.insert_piece(board, piece_name, player_x, player_y)
remain.pop(option-1)
else:
File.error("Try again")
self.ask_piece(board, player_x, player_y, remain)
示例2: parse_entry
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import error [as 别名]
def parse_entry(self, entry, game, board, player_x, player_y, num):
if re.match(r"x\.K\([1-8],[1-8]\)", entry):
moveH, moveV = game.split_entry(entry)
game.add_or_move(board, player_x, 'K', moveH, moveV, num)
elif re.match(r"x\.R\([1-8],[1-8]\)", entry):
moveH, moveV = game.split_entry(entry)
game.add_or_move(board, player_x, 'R', moveH, moveV, num)
elif re.match(r"y\.K\([1-8],[1-8]\)", entry):
moveH, moveV = game.split_entry(entry)
game.add_or_move(board, player_y, 'K', moveH, moveV, num)
else:
File.error("invalid entry from file")
示例3: insert_piece
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import error [as 别名]
def insert_piece(self, board, piece_name, player_x, player_y):
File.prompt("STARTING POSITION FOR " + piece_name + " ?")
moveH = input("Horizontal [1-8]: ")
moveH = int(moveH)
while moveH < 1 or moveH > 8:
File.error("expected [1-8]")
moveH = input("Horizontal [1-8]: ")
moveH = int(moveH)
moveV = input("Vertical [1-8]: ")
moveV = int(moveV)
while moveV < 1 or moveV > 8:
File.error("expected [1-8]")
moveV = input("Vertical [1-8]: ")
moveV = int(moveV)
if board.state[moveH][moveV] != '*':
File.error("space occupied")
exit(2)
if piece_name == "PlayerX King":
piece_id = Piece(player_x, 'K', moveH, moveV)
player_x.add_piece(piece_id)
elif piece_name == "PlayerX Rook":
piece_id = Piece(player_x, 'R', moveH, moveV)
player_x.add_piece(piece_id)
elif piece_name == "PlayerY King":
piece_id = Piece(player_y, 'K', moveH, moveV)
player_y.add_piece(piece_id)
else:
File.error("expected valid piece")
exit(3)
File.prompt("OK " + piece_name + " to " + str(moveH) + "-" + str(moveV))
示例4: add_or_move
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import error [as 别名]
def add_or_move(self, board, player, piece_id, moveH, moveV, num):
if num == 1:
new_piece = Piece(player, piece_id, moveH, moveV)
if player.id == 'x':
player.add_piece(new_piece)
elif player.id == 'y':
player.add_piece(new_piece)
else:
File.error("invalid player")
else:
if board.state[moveH][moveV] != player.id + piece_id:
print('\n\n')
File.prompt("MOVE " + player.id + piece_id + " to " + str(moveH) + "," + str(moveV))
board.player_move(player, piece_id, moveH, moveV)
示例5: player_move
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import error [as 别名]
def player_move(self, player, piece_id, new_row, new_col):
hero, opponent = self.identify_players(player)
piece = hero.pieces[piece_id]
self.state[piece.row][piece.col] = "*"
if piece_id == "K" and not self.tile_is_safe(opponent, new_row, new_col):
print("\n")
File.error("Illegal move.")
self.state[piece.row][piece.col] = piece.player + piece.type
elif not self.legal_move(piece, new_row, new_col):
print("\n")
File.error("Illegal move.")
self.state[piece.row][piece.col] = piece.player + piece.type
else:
self.make_move(player, piece, (new_row, new_col))
self.move_log = piece.player + piece.type + " to " + str(new_row) + "," + str(new_col)
示例6: opponent_move
# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import error [as 别名]
def opponent_move(self, player, board):
horizontal = 0
vertical = 0
piece = player.pieces['K']
if player.id == 'x':
File.prompt("Move which PlayerX piece?")
File.print("1) Rook")
File.print("2) King")
option = input("Select [1-2]: ")
try:
option = int(option)
except ValueError:
File.error("Try again")
self.opponent_move(player, board)
if option == 1:
piece = player.pieces['R']
elif option == 2:
piece = player.pieces['K']
else:
File.error("Try again")
self.opponent_move(player, board)
legal_moves = board.find_legal_moves(piece)
if len(legal_moves) == 0:
File.print('')
File.prompt("No legal moves for " + player.id + piece.type)
board.display()
File.prompt("Game Over")
exit(0)
for move in legal_moves: #put X's where valid moves are
horizontal, vertical = move
board.state[horizontal][vertical] = '+'
board.display()
validInput = False
while not validInput:
if piece.type == 'K':
name = "King"
elif piece.type == 'R':
name = "Rook"
File.prompt("Move " + name + " to coordinates")
horizontal= input("Horizontal [1-8]: ")
vertical= input("Vertical [1-8]: ")
try: #validate input
horizontal = int(horizontal)
vertical = int(vertical)
except ValueError: validInput = False
for move in legal_moves: #check if moves match a legal move
temp_hor, temp_vert = move
if horizontal == temp_hor and vertical == temp_vert:
validInput = True
if validInput != True:
File.error("Please select a legal move.")
for move in legal_moves: #put *'s back where X's were
temp_hor, temp_vert = move
board.state[temp_hor][temp_vert] = '*'
board.make_move(player,piece, (horizontal, vertical))
board.move_log = piece.player + piece.type + ' to ' + \
str(horizontal) + ',' + str(vertical)