如何解决不能弄清楚如何跳过跳棋
我正在尝试在pygame中制作一个跳棋游戏,并且想不出一种方法,一旦我跳过它,就会杀死一个跳棋。如果您需要更多信息,请告诉我。这是Checker Sprite类中的函数:
# Determine if move is valid,and if so snap to the grid
# and tell the game logic that there is a checker there
def snap_to_grid(self):
global turn
x,y = self.rect.topleft
coord_x = round(x / square_size)
coord_y = round(y / square_size)
new_x = coord_x * square_size + 5
new_y = coord_y * square_size + 5
# get all valid moves from the starting position
valid_moves = self.valid_moves()
# check if it is valid,or if it is going back to the same spot. If either is true,# then reset. If not,move to that spot.
if [new_x,new_y] == self.location or not [coord_x,coord_y] in valid_moves:
self.set_pos(self.location,'topleft')
else:
# move to new position
self.set_pos((new_x,new_y),'topleft')
# tell game data that the checker moved from the old square
board[self.coords[1]][self.coords[0]] = None
# the next few lines are to determine if the checker jumped or not
old_x,old_y = self.coords
self.location = [new_x,new_y]
self.coords = [int(self.location[0]//square_size),int(self.location[1]//square_size)]
distance = abs((old_x - self.coords[0])^2 + (old_y - self.coords[1])*2)
# check if checker jumped
if not distance == 1 and not distance == 5:
print("jumped")
"""
this code here should trigger when a jump happens.
I need to kill the checker it jumped over
"""
# tell game data the checker moved to the new square
board[self.coords[1]][self.coords[0]] = self
# set to be the next turn
if self.color == white:
turn = dark_gray
else:
turn = white
解决方法
好吧,我想我想通了,如果有更好的方法让我知道(如果在特定方向上跳跃,则if语句中的距离为输出):
"This expression is not callable"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。