Python 河内塔(移动圆盘)

Python 河内塔(移动圆盘),python,pygame,towers-of-hanoi,Python,Pygame,Towers Of Hanoi,我想用pygame制作河内的游戏塔。 我最大的困难是现在我必须移动磁盘,这是我到目前为止的代码,但它没有移动磁盘,我不知道为什么。我想它也只记录了第一次鼠标点击,而不是第二次。但它也没有取出光盘 import pygame, sys from pygame.locals import* pygame.init() screen = pygame.display.set_mode((500, 300)) pygame.display.set_caption("Towers of Hanoi")

我想用pygame制作河内的游戏塔。 我最大的困难是现在我必须移动磁盘,这是我到目前为止的代码,但它没有移动磁盘,我不知道为什么。我想它也只记录了第一次鼠标点击,而不是第二次。但它也没有取出光盘

import pygame, sys
from pygame.locals import*


pygame.init()
screen = pygame.display.set_mode((500, 300))
pygame.display.set_caption("Towers of Hanoi")

# Colours
BLACK = (  0,   0,   0)
WHITE = (255, 255, 255)
RED = (255,   0,   0)
GREEN = (  0, 255,   0)
BLUE = (  0,   0, 255)
SILVER = (192, 192, 192)
AQUA = (0, 255, 255)
PURPLE = (128, 0, 128)

# Background
background = screen.fill(WHITE)


# Platform
pygame.draw.rect(screen, BLUE,(50, 250, 400, 20))


# Towers
tower_left = pygame.draw.line(screen, SILVER,(125, 100), (125, 249), 20)
tower_middle = pygame.draw.line(screen, SILVER,(250, 100), (250, 249), 20)
tower_right = pygame.draw.line(screen, SILVER,(375, 100), (375, 249), 20)


# Discs
big = pygame.draw.ellipse(screen, RED,(70, 235, 115, 15))

middle = pygame.draw.ellipse(screen, GREEN,(75, 220, 105, 15))

small = pygame.draw.ellipse(screen, BLACK,(85, 205, 85, 15))


# List of towers (3 being the biggest)
left_tower = [big, middle, small]
middle_tower = []
right_tower = []

count = 0

# Click locations
clicks = []
for c in range(0, 1):
    for event in pygame.event.get():
        if event.type == MOUSEBUTTONDOWN:
            x, y = pygame.mouse.get_pos()
            clicks.append([x, y])


# Main game loop
while True:

    for event in pygame.event.get():

        if event.type == QUIT:
        pygame.quit()
        sys.quit()

        # Getting the mouseposition and moving the disc
        elif event.type == MOUSEBUTTONDOWN:
            x, y = pygame.mouse.get_pos()
            first_click = x, y

            # Remove the disc if it is in the range of the first tower
            if (x > 100) and (x < 140) and (y > 150) and (y < 250):
                if len(left_tower) == 0:
                    print "That's not valid"

            elif len(left_tower) in (big, middle, small):
                upper_disc = left_tower[-1]
                left_tower.remove(upper_disc)

                if event.type == MOUSEBUTTONDOWN:
                    x, y = pygame.mouse.get_pos()
                    second_click = x, y

                    # Add the upper disc to the tower where the second click was
                    if (x > 140) and (x < 220) and (y > 150) and (y < 250):
                        middle_tower.append(upper_disc)
                    elif (x > 350) and (x < 450) and (y > 150) and (y < 250):
                        right_tower.append(upper_disc)
                    else:
                        left_tower.append(upper_disc)



    pygame.display.update()

pygame.time.wait(10)
import pygame,sys
从pygame.locals导入*
pygame.init()
screen=pygame.display.set_模式((500300))
pygame.display.set_标题(“河内之塔”)
#颜色
黑色=(0,0,0)
白色=(255,255,255)
红色=(255,0,0)
绿色=(0,255,0)
蓝色=(0,0255)
银=(192192192)
水=(0,255,255)
紫色=(128,0,128)
#背景
背景=屏幕填充(白色)
#平台
pygame.draw.rect(屏幕,蓝色,(5025040020))
#塔楼
塔左=pygame.draw.line(银幕,(125100),(125249),20)
塔楼中间=pygame.draw.line(银幕,银幕,(250100),(250249),20)
塔右=pygame.draw.line(银幕,(375100),(375249),20)
#圆盘
大=pygame.draw.ellipse(屏幕,红色,(702351515))
中间=pygame.draw.ellipse(屏幕,绿色,(7522010515))
small=pygame.draw.ellipse(屏幕,黑色,(85205,85,15))
#塔楼列表(3座为最大)
左_塔=[大、中、小]
中塔=[]
右_塔=[]
计数=0
#单击位置
点击次数=[]
对于范围(0,1)内的c:
对于pygame.event.get()中的事件:
如果event.type==MOUSEBUTTONDOWN:
x、 y=pygame.mouse.get_pos()
单击。追加([x,y])
#主游戏循环
尽管如此:
对于pygame.event.get()中的事件:
如果event.type==退出:
pygame.quit()
sys.quit()
#获取鼠标位置并移动光盘
elif event.type==MOUSEBUTTONDOWN:
x、 y=pygame.mouse.get_pos()
第一次单击=x,y
#如果圆盘在第一个塔架的范围内,则移除圆盘
如果(x>100)和(x<140)和(y>150)和(y<250):
如果len(左_塔)==0:
打印“那是无效的”
elif len(左_塔)位于(大、中、小):
上圆盘=左塔架[-1]
左_塔。拆除(上_盘)
如果event.type==MOUSEBUTTONDOWN:
x、 y=pygame.mouse.get_pos()
第二次单击=x,y
#将上部光盘添加到第二次单击的塔中
如果(x>140)和(x<220)以及(y>150)和(y<250):
中间塔。附加(上部盘)
elif(x>350)和(x<450)和(y>150)和(y<250):
右_塔。附加(上_盘)
其他:
左_塔。附加(上_盘)
pygame.display.update()
pygame.时间.等等(10)

我看到了几件事。代码中似乎存在一些缩进问题。当我修复这个问题时,我认为它应该被修复,它永远不会落入最后一个
elif
所以
elif len(左塔)在(大、中、小):
永远不会返回
True

谁刚刚投了反对票,有什么原因吗?请务必提及一个。可能的副本