如何解决如何取消我的循环正在执行的操作并重新开始循环
我是 Python 新手,基本上是编程方面的。 我决定挑战自己并制作一个“Draughts”游戏,其中两个玩家将相互对抗。 在我将棋子向左移动的功能中,我想添加让玩家后悔并重新开始的选项,有没有什么简单的方法可以取消主循环的所有操作? 如果有任何拼写错误,也很抱歉,英语不是我的第一语言...... 另外,如果有任何其他改进建议,我肯定有,如果您也能注意到,我会很高兴!
def move_left(gameboard):
# main loop of the function
while True:
# getting the position of the wanted piece to play with:
raw = int(input('please select the row of the wanted piece to move: '))
colum = int(input('please select the column of the wanted piece to move: '))
# check if the piece can move to left obliquely:
if (raw == 8) or (column == 8) or (type(gameboard[raw][column]) == __main__.black_piece):
print("Sorry,can't complete the move. Try another move.")
continue
# moves the peice to the wanted square:
gameboard[raw+1][column+1] = gameboard[raw][column]
gameboard[raw][column]= ''
# asking the player if he is sure about the move:
while True:
end_move = input("Are you sure do you want to make this move and end it? type 'Y' for yes,or type 'N' for no: " ).upper()
if end_move != 'Y' and end_move != 'N':
print("Wrong input! Please type 'Y' or 'N' ")
continue
else:
break
if end_move == 'Y':
break
else:
# don't know what to write from now on...
我想了想,我认为这会奏效。有人可以检查我吗? *注意:修复了“和”而不是“或”的问题,谢谢。
if end_move == 'Y':
break
else:
# don't know what to write from now on...
gameboard[raw][column] = gameboard[raw+1][column+1]
gameboard[raw+1][column+1] = ''
continue
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。