Ejemplo n.º 1
0
 elif event.type == pygame.MOUSEBUTTONDOWN:
     press_btn = pygame.mouse.get_pressed()
     if press_btn[0] == 1:   # 左键
         point = pygame.mouse.get_pos()
         if pygame.Rect(menu0).collidepoint(point):
             draw.reset()
             ai_first = False
             gameover = False
             clearstatusbar()
             continue
         elif pygame.Rect(menu1).collidepoint(point):
             draw.reset()
             ai_first = True
             gameover = False
             clearstatusbar()
             remove_list = core.caculate(draw.getmap())
             draw.remove(remove_list)
         else:
             pos = draw.getpos(point)
             if pos != (-1, -1):
                 if draw.isfree(pos):
                     draw.set(pos)
                 else:
                     draw.unset(pos)
     elif press_btn[2] == 1: # 右键移除棋子
         if draw.remove() == True: #有棋子移除
             if core.gameover(draw.getmap()) == True:
                 gameover = True
                 setstatusbar('you win!')
             else:
                 remove_list = core.caculate(draw.getmap())
Ejemplo n.º 2
0
while end == False:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: end = True
        elif event.type == pygame.MOUSEBUTTONDOWN:
            point = pygame.mouse.get_pos()
            if pygame.Rect(menu0).collidepoint(point):
                draw.reset()
                ai_first = False
                gameover = False
                clearstatusbar()
            elif pygame.Rect(menu1).collidepoint(point):
                draw.reset()
                clearstatusbar()
                ai_first = True
                gameover = False
                (x, y) = core.caculate(draw.getmap())
                draw.setai((x, y))
                draw.drawX((x, y), red, 4)

            else:

                if ai_first == False:  # player first
                    pos = draw.getpos(point)
                    #print "get (%d, %d)" %(pos[0], pos[1])
                    if draw.isfree(pos) == True and gameover == False:
                        draw.setplayer(pos)
                        draw.drawcircle(pos, green, -1, 4)
                        #print "setplayer"
                        if core.iswin(draw.getmap(), pos[0], pos[1]):
                            #print "player win!"
                            gameover = True
Ejemplo n.º 3
0
 elif event.type == pygame.MOUSEBUTTONDOWN:
     press_btn = pygame.mouse.get_pressed()
     if press_btn[0] == 1:  # 左键
         point = pygame.mouse.get_pos()
         if pygame.Rect(menu0).collidepoint(point):
             draw.reset()
             ai_first = False
             gameover = False
             clearstatusbar()
             continue
         elif pygame.Rect(menu1).collidepoint(point):
             draw.reset()
             ai_first = True
             gameover = False
             clearstatusbar()
             remove_list = core.caculate(draw.getmap())
             draw.remove(remove_list)
         else:
             pos = draw.getpos(point)
             if pos != (-1, -1):
                 if draw.isfree(pos):
                     draw.set(pos)
                 else:
                     draw.unset(pos)
     elif press_btn[2] == 1:  # 右键移除棋子
         if draw.remove() == True:  # 有棋子移除
             if core.gameover(draw.getmap()) == True:
                 gameover = True
                 setstatusbar("you win!")
             else:
                 remove_list = core.caculate(draw.getmap())
Ejemplo n.º 4
0
while end == False:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: end = True
        elif event.type == pygame.MOUSEBUTTONDOWN:
            point = pygame.mouse.get_pos()
            if pygame.Rect(menu0).collidepoint(point):
                draw.reset()
                ai_first = False
                gameover = False
                clearstatusbar()
            elif pygame.Rect(menu1).collidepoint(point):
                draw.reset()
                clearstatusbar()
                ai_first = True
                gameover = False
                (x, y) = core.caculate(draw.getmap())
                draw.setai((x, y))
                draw.drawX((x, y), red, 4)

            else:

                if ai_first == False:           # player first
                    pos = draw.getpos(point)
                    #print "get (%d, %d)" %(pos[0], pos[1])
                    if draw.isfree(pos) == True and gameover == False:
                        draw.setplayer(pos)
                        draw.drawcircle(pos, green, -1, 4)
                        #print "setplayer"
                        if core.iswin(draw.getmap(), pos[0], pos[1]):
                            #print "player win!"
                            gameover = True