Загрузка данных


import pygame
import time
def win(a):
    for i in a:
        if ( (i[0],i[1]+1) in a and (i[0],i[1]+2) in a and (i[0],i[1]+3) in a):
            return {(i[0],i[1]+1),(i[0],i[1]),(i[0],i[1]+2),(i[0],i[1]+3)}
        if ( (i[0]+1,i[1]) in a and(i[0]+2,i[1]) in a and(i[0]+3,i[1]) in a):
            return {(i[0]+1,i[1]),(i[0],i[1]),(i[0]+2,i[1]),(i[0]+3,i[1])}
        if ((i[0]+1,i[1]+1) in a and(i[0]+2,i[1]+2) in a and(i[0]+3,i[1]+3) in a):
            return {(i[0]+1,i[1]+1),(i[0],i[1]),(i[0]+2,i[1]+2),(i[0]+3,i[1]+3)}
        if ((i[0]+1,i[1]-1) in a and(i[0]+2,i[1]-2) in a and(i[0]+3,i[1]-3) in a):
            return {(i[0]+1,i[1]-1),(i[0],i[1]),(i[0]+2,i[1]-2),(i[0]+3,i[1]-3)}
screen=pygame.display.set_mode((700,600))
while True:
    screen.fill((21,96,189))
    for x in range(1,8):
        for y in range(1,7):
            pygame.draw.circle(screen,(14,41,75),(100*x-50,100*y-50),40)
    desk=[0,0,0,0,0,0,0]
    pygame.display.flip()
    reds=set()
    yellows=set()
    turn=0
    flag=True
    while flag:
        for event in pygame.event.get():
                if event.type==pygame.QUIT:
                    pygame.quit()
                if event.type==pygame.MOUSEBUTTONDOWN:
                    x=event.pos[0]
                    num=x//100
                    if desk[num]+1<7:
                        if turn%2==0:
                            pygame.draw.circle(screen,(195,0,0),(100*num+50,550-100*desk[num]),40)
                            reds.add((num,desk[num]))
                            if win(reds)!=None:
                                for m in win(reds):
                                    pygame.draw.circle(screen,(255,255,255),(100*m[0]+50,550-100*m[1]),40)
                                    pygame.draw.circle(screen,(255,0,0),(100*m[0]+50,550-100*m[1]),36)
                                pygame.display.flip()
                                pygame.event.clear()
                                time.sleep(2)
                                flag=False
                        else:
                            pygame.draw.circle(screen,(244,224,84),(100*num+50,550-100*desk[num]),40)
                            yellows.add((num,desk[num]))
                            if win(yellows)!=None:
                                for m in win(yellows):
                                    pygame.draw.circle(screen,(255,255,255),(100*m[0]+50,550-100*m[1]),40)
                                    pygame.draw.circle(screen,(255,255,0),(100*m[0]+50,550-100*m[1]),36)
                                pygame.display.flip()
                                pygame.event.clear()
                                time.sleep(2)
                                flag=False
                        desk[num]+=1
                        turn+=1
                        pygame.display.flip()
                        if desk.count(6)==7:
                            time.sleep(2)
                            flag=False
                    else:
                        break

import pygame
import time
screen=pygame.display.set_mode((800,800))
def show(towers):
    screen.fill((255,255,255))
    pygame.draw.line(screen,(0,0,0),(50,600),(250,600),2)
    pygame.draw.line(screen,(0,0,0),(300,600),(500,600),2)
    pygame.draw.line(screen,(0,0,0),(550,600),(750,600),2)
    pygame.draw.line(screen,(0,0,0),(100,600),(200,600),2)
    pygame.draw.line(screen,(0,0,0),(150,600),(150,300),2)
    pygame.draw.line(screen,(0,0,0),(400,600),(400,300),2)
    pygame.draw.line(screen,(0,0,0),(650,600),(650,300),2)
    for i in range(3):
        for j in range(len(towers[i])):
            width=30*towers[i][j]
            height=30
            pygame.draw.rect(screen,(255,0,0),(150+i*250-width/2,600-((len(towers[i])-j)*height),30*towers[i][j],30))
    pygame.display.flip()
    time.sleep(0)
def move(start,fin):
    global towers
    towers[fin].insert(0,towers[start][0])
    towers[start].pop(0)
towers=[list(range(1,7)),[],[]]
show(towers)
buttons=[]
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            x=event.pos[0]
            if x<251 and x>49:
                if len(buttons)==0:
                    if len(towers[0])>0:
                        buttons.append(0)
                else:
                    buttons.append(0)
            elif x<499 and x>299:
                if len(buttons)==0:
                    if len(towers[1])>0:
                        buttons.append(1)
                else:
                    buttons.append(1)
            elif x<751 and x>549:
                if len(buttons)==0:
                    if len(towers[2])>0:
                        buttons.append(2)
                else:
                    buttons.append(2)
    if len(buttons)==2:
        if len(towers[buttons[0]])>0 and (len(towers[buttons[1]])<1 or (towers[buttons[0]])[0]<(towers[buttons[1]])[0]):
            print(towers[buttons[0]],towers[buttons[1]])
            move(buttons[0],buttons[1])
            show(towers)
        buttons=[]