Exemplo n.º 1
0
def main():
    game = Game()
    game.register_player('goshko')
    game.register_player('kirakis')
    FPS = 15
    picx = go_player_picturex
    picy = go_player_picturey
    global DISPLAYSURF, fpsClock
    pygame.init()
    fpsClock = pygame.time.Clock()
    DISPLAYSURF = pygame.display.set_mode((760, 580), 0, 32)
    #windowSurface = pygame.display.set_mode((500, 400),0,32)
    pygame.display.set_caption('Monopoly Standard Edition')
    background = pygame.image.load('pictures/resized.bmp')
    DISPLAYSURF.blit(background, (0, 0))
    pygame.display.update()
    bg_color = (255, 255, 255)
    text_color = (255,   0,   0)
    #windowBgColor = WHITE
    x_position = 600
    y_position = 0
    text_lenght = 150
    x_text_border = 30
    y_text_border = 40

    roll_button = Button()
    roll_button.create_button(DISPLAYSURF, bg_color, x_position, y_position,
                              text_lenght, x_text_border, y_text_border, 'Roll', text_color)
    #                       range(start, end)   step
    y_position = (i for i in range(10, 550) if i % 45 == 0)

    end_turn = Button()
    end_turn.create_button(DISPLAYSURF, bg_color, x_position, next(
        y_position), text_lenght, x_text_border, y_text_border, 'end_turn', text_color)
    mourtage = Button()
    mourtage.create_button(DISPLAYSURF, bg_color, x_position, next(
        y_position), text_lenght, x_text_border, y_text_border, 'mourtage', text_color)
    unmourtage = Button()
    unmourtage.create_button(DISPLAYSURF, bg_color, x_position, next(
        y_position), text_lenght, x_text_border, y_text_border, 'unmourtage', text_color)
    trade = Button()
    trade.create_button(DISPLAYSURF, bg_color, x_position, next(y_position),
                        text_lenght, x_text_border, y_text_border, 'trade', text_color)
    sell = Button()
    sell.create_button(DISPLAYSURF, bg_color, x_position, next(y_position),
                       text_lenght, x_text_border, y_text_border, 'sell', text_color)
    build = Button()
    build.create_button(DISPLAYSURF, bg_color, x_position, next(y_position),
                        text_lenght, x_text_border, y_text_border, 'build', text_color)
    rules = Button()
    rules.create_button(DISPLAYSURF, bg_color, x_position, next(
        y_position), text_lenght, x_text_border, y_text_border, 'rules', text_color)
    register = Button()
    register.create_button(DISPLAYSURF, bg_color, x_position, next(
        y_position), text_lenght, x_text_border, y_text_border, 'register', text_color)
    bancrupt = Button()
    bancrupt.create_button(DISPLAYSURF, bg_color, x_position, next(
        y_position), text_lenght, x_text_border, y_text_border, 'bancrupt', text_color)
    # pygame.image.save(pygame.display.get_surface(),'C:/Python33/pictures/resized.bmp')
    pygame.display.update()

    mousex = 0
    mousey = 0
    #move_icon(0, 30,0,DISPLAYSURF)
    # move_icon(0,5,0,DISPLAYSURF)
    while True:
        for event in pygame.event.get():

            if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()
            elif event.type == MOUSEMOTION:
                mousex, mousey = event.pos
            elif event.type == MOUSEBUTTONUP:
                display_current_player(
                    DISPLAYSURF, game, (600, 500), (600, 530))
                mousex, mousey = event.pos

                if game.has_winner():
                    winner(DISPLAYSURF, game)  # ne znam kak da zavurshi

                if roll_button.pressed([mousex, mousey]):
                    roll_dices(game, DISPLAYSURF)
                    game.take_fee()
                    print('izleze ot roll ')
                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)

                if end_turn.pressed([mousex, mousey]):
                    end_turner(DISPLAYSURF)
                    display_centre(DISPLAYSURF)
                    game.end_turn()
                    players_render(DISPLAYSURF, game)
                    f(game)
                    print('end_turn pressed')

                if mourtage.pressed([mousex, mousey]):
                    print('mourtage pressed')
                    mourtager(game, DISPLAYSURF)
                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)

                if unmourtage.pressed([mousex, mousey]):
                    print('unmourtage pressed')
                    unmourtager(game, DISPLAYSURF)
                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)

                if trade.pressed([mousex, mousey]):
                    print('trade pressed')
                    trader(game, 'kirakis', DISPLAYSURF)
                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)

                if sell.pressed([mousex, mousey]):
                    print('sell pressed')
                    sell_houser(game, "player_name", DISPLAYSURF)
                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)

                if build.pressed([mousex, mousey]):
                    print('build pressed')
                    build_houser(game, "player_name", DISPLAYSURF)
                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)

                if rules.pressed([mousex, mousey]):
                    print('rules pressed')

                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)

                if register.pressed([mousex, mousey]):  # works but buggy
                    print('register pressed', register.stat)
                    register_player(game, DISPLAYSURF)
                    pygame.display.update()
                    display_centre(DISPLAYSURF)
                    players_render(DISPLAYSURF, game)
                    f(game)
                    print(game.all_player())

                    # da dobavq centralna kartinka

                if bancrupt.pressed([mousex, mousey]):  # works but buggy
                    print('bancrupt pressed', register.stat)
                    game.bancrupt()
                    players_render(DISPLAYSURF, game)
                    f(game)
                    # self.other(DISPLAYSURF,game)
                    # display_centre(DISPLAYSURF)
                    # register_player()
                    # register.status(False)
                pygame.display.update()
                mouseClicked = True

        pygame.display.update()
Exemplo n.º 2
0
    def testGame(self):
        game = Game()
        # self.assertNotEqual(game.roll_dice(),[range(2,2),(True|False)])
        self.assertEqual(game.register_player('goshko'), True)
        self.assertEqual(game.register_player('peshko'), True)
        self.assertEqual(game.register_player('goshko'), False)
        self.assertEqual(game.register_player('pesh'), False)
        self.assertEqual(len(game.all_player()), 2)
        self.assertEqual(game.current_player, 0)
        self.assertEqual(game.current_position(), 0)
        self.assertEqual(game.player_Free(), True)
        game.end_turn()

        self.assertEqual(game.current_player, 1)
        self.assertEqual(game.current_player_index(), 1)
        self.assertEqual(game.icon(), 1)
        self.assertEqual(game.render_name_and_budget(), ['peshko', 1500])
        self.assertEqual(game.at(3), 'Baltic Ave.')

        self.assertEqual(game.buy_building(1, False), True)
        self.assertEqual(len(game.players[1].get_items()), 1)
        self.assertEqual(len(game.players[0].get_items()), 0)
        game.end_turn()
        self.assertEqual(game.current_player, 0)
        self.assertEqual(game.buy_building(3, False), True)
        self.assertEqual(len(game.players[0].get_items()), 1)

        # trader
        self.assertEqual(game.players[1].player_budget(), 1440)
        self.assertEqual(game.trade_buildings(
            1, [1], 2, 'peshko', [23], 123), False)
        self.assertEqual(game.trade_buildings(
            1, [3], 1000, 'peshko', [0], 123), True)
        self.assertEqual(len(game.players[1].get_items()), 2)
        self.assertEqual(game.players[1].player_budget(), 2317)
        self.assertEqual(game.players[0].player_budget(), 563)
        self.assertEqual(len(game.players[0].get_items()), 0)
        # mourtage
        self.assertEqual(game.mourtage(1), False)
        game.end_turn()
        self.assertEqual(game.mourtage(1), True)
        self.assertEqual(game.players[1].player_budget(), 2341)
        self.assertEqual(game.unmourtage(1), True)
        self.assertEqual(game.players[1].player_budget(), 2311)
        # build sell
        self.assertEqual(game.build_house(1), True)
        self.assertEqual(game.build_house(3), True)
        self.assertEqual(game.build_house(33), False)
        self.assertEqual(game.sell_house(3), True)
        self.assertEqual(game.sell_house(3), False)
        # jail test posle

        # community chest
        self.assertEqual(game.players[1].player_budget(), 2231)
        self.assertEqual(game.community_chest(
            game.players[1]), 'Advance to Go (collect $200)')
        self.assertEqual(game.current_player, 1)
        self.assertEqual(game.players[1].player_budget(), 2431)
        self.assertEqual(game.players[1].position, 0)
        self.assertEqual(game._comunity_chest_index, 1)
        #
        game._comunity_chest_index = 3
        self.assertEqual(game.community_chest(
            game.players[1]), 'Get out of jail free')
        self.assertEqual(game.players[0].player_budget(), 563)
        self.assertEqual(game.community_chest(
            game.players[1]), 'It is your birthday Collect $10 from each player')
        self.assertEqual(game.players[0].player_budget(), 553)
        self.assertEqual(game.players[1].player_budget(), 2441)  # t,n
        # chance
        self.assertEqual(
            game.Chance(game.players[1]), 'Advance to Go (collect $200)')
        self.assertEqual(game.players[1].player_budget(), 2641)

        self.assertEqual(game.move_player_by_rolled(11)[1], 11)