コード例 #1
0
ファイル: call.py プロジェクト: suzanshakya/callbreak

if __name__ == '__main__':
    card_storage = 'cards.pkl'
    if os.path.exists(card_storage):
        with open(card_storage, 'rb') as f:
            players = pickle.load(f)
    else:
        sujan = Player('Sujan')
        sudeep = Player('Sudeep')
        santosh = Player('Santosh')
        rupa = Player('Rupa')

        # add players in clockwise direction
        players = [sujan, sudeep, santosh, rupa]

        game = CallBreak(players)
        game.ready()

        with open(card_storage, 'wb') as f:
            pickle.dump(players, f, pickle.HIGHEST_PROTOCOL)

    total = 0
    for player in players:
        cards = player.cards
        print cards
        call = suggest_call(cards)
        total += call
        print call
    print total
コード例 #2
0
ファイル: main.py プロジェクト: suzanshakya/callbreak
    def MainLoop(self):
        player_default=False

        screen = pygame.display.set_mode((960, 540))

        font = pygame.font.SysFont("monospace", 18)
        gui = pgui.App()

        def btncall():

            print edText
            return edText

        textArea1 = pygame.Rect(517, 358, 20, 20)
        lo = pgui.Container(width=350)

        # btn1 = pgui.Button("Call")
        # btn1.connect(pgui.CLOSE, lambda: btncall())
        # lo.add(btn1,167,202)
       
        num = pgui.Input(None, size=5)
        num.connect(pgui.ScrollArea, logInputAction, num)
        lo.add(num,110,200)
        # import ipdb; ipdb.set_trace();
       

        def set_call():
            return num.value

        gui.init(lo)

        if player_default:       
            player1 = Player(getname1(), is_bot=True)
            player2 = Player(getname2(), is_bot=True)
            player3 = Player(getname3(), is_bot=True)
            player4 = Player(getname4(), is_bot=False)

        else:
            player1 = Player("Ai1", is_bot=True)
            player2 = Player("Ai2", is_bot=True)
            player3 = Player("Ai3", is_bot=True)
            player4 = Player("You", is_bot=False)
        
        player1_ui = PlayerUI(player1, self.screen, self.board, 'left', hide=True)
        player2_ui = PlayerUI(player2, self.screen, self.board, 'top', hide=True)
        player3_ui = PlayerUI(player3, self.screen, self.board, 'right', hide=True)
        player4_ui = PlayerUI(player4, self.screen, self.board, 'bottom', hide=False)

        players = [player1_ui, player2_ui, player3_ui, player4_ui]
        game = CallBreak([ui.player for ui in players])

        score = 0
        while True:
            
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == KEYDOWN and event.key == K_ESCAPE:
                    return

            self.screen.fill(WHITE)
                     
            pygame.display.update() 
            scoretext1 = font.render("Score:{0}".format(score), 1, (0,0,0))
            scoretext2 = font.render("Score:{0}".format(score), 1, (0,0,0))
            scoretext3 = font.render("Score:{0}".format(score), 1, (0,0,0))
            scoretext4 = font.render("Score:{0}".format(score), 1, (0,0,0))

            screen.blit(scoretext1, (20, 20))
            screen.blit(scoretext2, (238, 20))
            screen.blit(scoretext3, (855, 20))
            screen.blit(scoretext4, (20, 380))
            game.ready()
            for player in players:
                player.ready()
                player.unfold_cards()
            
            user_call = False
           
            while not user_call: 

                for event in pygame.event.get():
                    if event.type == QUIT:
                        pygame.quit()
                        sys.exit()
                    elif event.type == KEYDOWN and event.key == K_ESCAPE:
                        return
                    
                    gui.event(event)
                    gui.paint(screen)
                    pygame.display.flip()
                    edText = set_call()
                    call = font.render("{0}".format(edText), 1, (1,1,1))

                    if set_call():
                        user_call = True 
                        screen.blit(call, (400, 358))
                        pygame.display.update()                        
                        pygame.display.flip()

            pygame.display.update()   
            game.start()
            pygame.display.flip()