Exemplo n.º 1
0
def handle_build(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects):

    # adding static part
    
    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    create_player_info(screen,Players,Cards,cur_player)

    for player in Players:
        player.move_player(screen,player.cur_position)


    # check if property is available for building house/hotel

    Mark = []

    player = Players[cur_player]

    for color_list in player.color_cards_owned:
        Mark.extend(color_list)
    
    # display build window

    if Mark != []:
        update_game_build(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark)

    # show the state after update


    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    roll_dice(screen,4,2)
    
    for player in Players:
        player.move_player(screen,player.cur_position)

    create_player_info(screen,Players,Cards,cur_player)

    return cur_player
Exemplo n.º 2
0
def handle_sell(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects):

    # adding static part

    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    create_player_info(screen,Players,Cards,cur_player)

    for player in Players:
        player.move_player(screen,player.cur_position)

    # create cards available for selling

    Mark = []

    player = Players[cur_player]

    Mark.extend(player.property_owned)

    Mark.extend(player.property_mortgaged)

    if Mark != []:
        update_game_sell(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark)

    # show the state after update


    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    roll_dice(screen,4,2)
    
    for player in Players:
        player.move_player(screen,player.cur_position)

    create_player_info(screen,Players,Cards,cur_player)

    return cur_player
Exemplo n.º 3
0
def handle_rules(screen,Players,Cards,cur_player):

    display_rules_window(screen)


    # show the state after update
    
    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    roll_dice(screen,4,2)
    
    for player in Players:
        player.move_player(screen,player.cur_position)

    create_player_info(screen,Players,Cards,cur_player)

    return cur_player
Exemplo n.º 4
0
def handle_quit(screen,Players,Cards,cur_player):

    done = display_quit_window(screen)

    if done == True:
        pygame.quit()
    else:

        screen.fill(BACKGROUND_COLOR)

        create_board(screen,Cards)

        create_game_options(screen)

        roll_dice(screen,4,2)
        
        for player in Players:
            player.move_player(screen,player.cur_position)

        create_player_info(screen,Players,Cards,cur_player)

        return cur_player
Exemplo n.º 5
0
    def run(self):
        pg.init()
        self.screen = pg.display.set_mode(SCREEN_RES)
        pg.display.set_caption('Sudoku solver')

        display = Display_board(self.screen)

        flag1 = 0
        val = 0

        self.board = create_board().board
        while 1:
            for event in pg.event.get():
                if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
                    exit()
                
                if event.type == pg.KEYDOWN:
                    Input_handler.event_keys(event.key)
                if event.type == pg.MOUSEBUTTONDOWN:
                    flag1 = 1
                    pos = pg.mouse.get_pos()
                    get_cord(pos)

            if val != 0:
                display.draw_val(val, x, y)

                if valid(grid, int(x), int(y), val) == True:
                    grid[int(x)][int(y)] = val
                else:
                    grid[int(x)][int(y)] = 0
                    raise_error2()
                val = 0

            pg.draw.rect(self.screen, BLACK, (0, 0, self.screen.get_width(), self.screen.get_height()))
            self.screen.fill(BEIGE)

            display.draw(self.board)
            # display.draw_box()

            pg.display.update()


        self.solution = solve_board(self.board)

        self.solution.assign_flags(self.board)
Exemplo n.º 6
0
def process_fifth_level(dutifulness, inventory, log):
    """Handle game's second level game."""
    os.system("clear")
    x_hero = 1
    y_hero = 1
    board = create_board("boss.csv")
    previous_sign = board[y_hero][x_hero]
    log = "OMG I'm so anxious, what does the boss want?"

    obstacles = ["▓"]
    clock = "⏰"

    input_key = getch()  #control

    while dutifulness != 0:
        x_diff = 0
        y_diff = 0

        input_key = getch()
        x_diff, y_diff = control_position(input_key)
        board[y_hero][x_hero] = previous_sign

        if is_move_possible(y_hero + y_diff, x_hero + x_diff, obstacles,
                            board):
            y_hero, x_hero = move_by(y_hero, x_hero, y_diff, x_diff)

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], clock):
            hot_and_cold_game()
            return dutifulness, inventory, log

        if input_key == "q":
            sys.exit()

        previous_sign = board[y_hero][x_hero]
        print_board_and_insert_player(board, y_hero, x_hero, inventory,
                                      dutifulness, log)
Exemplo n.º 7
0
def run_game():

    pygame.init()

    WINDOW_SIZE = [SCREEN_WIDTH, SCREEN_HEIGHT]
    screen = pygame.display.set_mode(WINDOW_SIZE)

    screen.fill(BACKGROUND_COLOR)

    pygame.display.set_caption("MONOPOLY")

    # ask for game details

    no_of_players, player_names, player_colors = ask_for_game_details(screen)

    # handle game details

    # creating the players

    Players = []

    for i in range(0, no_of_players):
        Players.append(Player(player_names[i], player_colors[i], 1000))

    # creating the cards

    Cards = []

    # id_no,name,color,cost,rent,mortgage_value,house_cost,hotel_cost,house_rent,hotel_rent,board_pos,info_pos

    card = Card(0, "GO", "", 0, 0, 0, 0, 0, [], 0, (1001, 701), ())
    Cards.append(card)

    card = Card(1, "MEDITARREANEAN AVENUE", "BROWN", 60, 2, 30, 50, 50,
                [10, 30, 90, 160], 250, (901, 701), (1380, 350))
    Cards.append(card)

    card = Card(2, "COMMUNITY CHEST", "", 0, 0, 0, 0, 0, [], 0, (801, 701), ())
    Cards.append(card)

    card = Card(3, "BALTIC AVENUE", "BROWN", 80, 4, 30, 50, 50,
                [20, 60, 80, 320], 450, (701, 701), (1330, 350))
    Cards.append(card)

    card = Card(4, "INCOME TAX", "", 0, 0, 0, 0, 0, [], 0, (601, 701), ())
    Cards.append(card)

    card = Card(5, "READING RAILROAD", "BLACK", 200, 25, 100, 0, 0, [], 0,
                (501, 701), (1280, 350))
    Cards.append(card)

    card = Card(6, "ORIENTAL AVENUE", "LIGHT_BLUE", 100, 6, 50, 50, 50,
                [30, 90, 270, 400], 450, (401, 701), (1255, 350))
    Cards.append(card)

    card = Card(7, "CHANCE", "", 0, 0, 0, 0, 0, [], 0, (301, 701), ())
    Cards.append(card)

    card = Card(8, "VERMONT AVENUE", "LIGHT_BLUE", 100, 6, 50, 50, 50,
                [30, 90, 270, 400], 450, (201, 701), (1205, 350))
    Cards.append(card)

    card = Card(9, "CONNECTICUT AVENUE", "LIGHT_BLUE", 120, 8, 60, 50, 50,
                [40, 100, 300, 450], 600, (101, 701), (1180, 350))
    Cards.append(card)

    card = Card(10, "IN JAIL", "", 0, 0, 0, 0, 0, [], 0, (1, 701), ())
    Cards.append(card)

    card = Card(11, "ST. CHARLES PLACE", "PINK", 140, 10, 70, 100, 100,
                [50, 150, 450, 625], 750, (1, 631), (1155, 325))
    Cards.append(card)

    card = Card(12, "ELECTIC COMPANY", "WHITE", 150, 10, 75, 0, 0, [], 0,
                (1, 561), (1155, 300))
    Cards.append(card)

    card = Card(13, "STATES AVENUE", "PINK", 140, 10, 70, 100, 100,
                [50, 150, 450, 625], 750, (1, 491), (1155, 275))
    Cards.append(card)

    card = Card(14, "VIRGINIA AVENUE", "PINK", 160, 12, 80, 100, 100,
                [60, 180, 500, 700], 900, (1, 421), (1155, 250))
    Cards.append(card)

    card = Card(15, "PENNSYLVANIA RAILROAD", "BLACK", 200, 25, 100, 0, 0, [],
                0, (1, 351), (1155, 225))
    Cards.append(card)

    card = Card(16, "ST. JAMES PLACE", "ORANGE", 180, 14, 90, 100, 100,
                [70, 200, 550, 750], 950, (1, 281), (1155, 200))
    Cards.append(card)

    card = Card(17, "COMMUNITY CHEST", "", 0, 0, 0, 0, 0, [], 0, (1, 211), ())
    Cards.append(card)

    card = Card(18, "TENNESSEE AVENUE", "ORANGE", 180, 14, 90, 100, 100,
                [70, 200, 550, 750], 950, (1, 141), (1155, 150))
    Cards.append(card)

    card = Card(19, "NEW YORK AVENUE", "ORANGE", 200, 16, 100, 100, 100,
                [80, 220, 600, 800], 1000, (1, 71), (1155, 125))
    Cards.append(card)

    card = Card(20, "FREE PARKING", "", 0, 0, 0, 0, 0, [], 0, (1, 1), ())
    Cards.append(card)

    card = Card(21, "KENTUCKY AVENUE", "RED", 220, 18, 110, 150, 150,
                [90, 250, 700, 875], 1050, (101, 1), (1180, 100))
    Cards.append(card)

    card = Card(22, "CHANCE", "", 0, 0, 0, 0, 0, [], 0, (201, 1), ())
    Cards.append(card)

    card = Card(23, "INDIANA AVENUE", "RED", 220, 18, 110, 150, 150,
                [90, 250, 700, 875], 1050, (301, 1), (1230, 100))
    Cards.append(card)

    card = Card(24, "ILLINOIS AVENUE", "RED", 240, 20, 120, 150, 150,
                [100, 300, 750, 925], 1100, (401, 1), (1255, 100))
    Cards.append(card)

    card = Card(25, "B. & O. RAILROAD", "BLACK", 200, 25, 100, 0, 0, [], 0,
                (501, 1), (1280, 100))
    Cards.append(card)

    card = Card(26, "ATLANTIC AVENUE", "YELLOW", 260, 22, 130, 150, 150,
                [110, 330, 800, 975], 1150, (601, 1), (1305, 100))
    Cards.append(card)

    card = Card(27, "VENTORA AVENUE", "YELLOW", 260, 22, 130, 150, 150,
                [110, 330, 800, 975], 1150, (701, 1), (1330, 100))
    Cards.append(card)

    card = Card(28, "WATER WORKS", "WHITE", 150, 10, 75, 0, 0, [], 0, (801, 1),
                (1355, 100))
    Cards.append(card)

    card = Card(29, "MARVIN GARDENS", "YELLOW", 280, 24, 140, 150, 150,
                [120, 360, 850, 1025], 1200, (901, 1), (1380, 100))
    Cards.append(card)

    card = Card(30, "GO TO JAIL", "", 0, 0, 0, 0, 0, [], 0, (1001, 1), ())
    Cards.append(card)

    card = Card(31, "PACIFIC AVENUE", "GREEN", 300, 26, 150, 200, 200,
                [130, 390, 900, 1100], 1275, (1001, 71), (1405, 125))
    Cards.append(card)

    card = Card(32, "CAROLINA AVENUE", "GREEN", 300, 26, 150, 200, 200,
                [130, 390, 900, 1100], 1275, (1001, 141), (1405, 150))
    Cards.append(card)

    card = Card(33, "COMMUNITY CHEST", "", 0, 0, 0, 0, 0, [], 0, (1001, 211),
                ())
    Cards.append(card)

    card = Card(34, "PENNSYLVANIA AVENUE", "GREEN", 320, 28, 160, 200, 200,
                [150, 450, 1000, 1200], 1400, (1001, 281), (1405, 200))
    Cards.append(card)

    card = Card(35, "SHORT LANE", "BLACK", 200, 25, 100, 0, 0, [], 0,
                (1001, 351), (1405, 225))
    Cards.append(card)

    card = Card(36, "CHANCE", "", 0, 0, 0, 0, 0, [], 0, (1001, 421), ())
    Cards.append(card)

    card = Card(37, "PARK PLACE", "BLUE", 350, 35, 175, 200, 200,
                [175, 500, 1100, 1300], 1500, (1001, 491), (1405, 275))
    Cards.append(card)

    card = Card(38, "LUXURY TAX", "", 0, 0, 0, 0, 0, [], 0, (1001, 561), ())
    Cards.append(card)

    card = Card(39, "BROADWALK", "BLUE", 400, 50, 200, 200, 200,
                [200, 600, 1400, 1700], 2000, (1001, 631), (1405, 325))
    Cards.append(card)

    # create initial board

    create_board(screen, player_colors)

    # placing the game pieces at the start position for each player

    for player in Players:

        if player.color == "BLUE":
            next_position = (1020, 720)
        elif player.color == "RED":
            next_position = (1060, 720)
        elif player.color == "GREEN":
            next_position = (1020, 750)
        elif player.color == "YELLOW":
            next_position = (1060, 750)
        else:
            next_position = ()

        player.move_player(screen, next_position)

    # create game options

    create_game_options(screen)

    # create player info

    # stores the index of player whose turn it is now

    cur_player = 0

    create_player_info(screen, Players, Cards, cur_player)

    manImg = pygame.image.load('man.png')
    screen.blit(manImg, (400, 315))

    done = False

    clock = pygame.time.Clock()

    #--------------MAIN GAME LOOP------------------
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
            elif event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print(pos)
                #col = pos[0] // (CARD_WIDTH + CARD_MARGIN)
                #row = pos[1] // (CARD_HEIGHT + CARD_MARGIN)

        ####

        clock.tick(60)

        pygame.display.update()

    pygame.quit()
    def run(self):
        pg.init()
        self.screen = pg.display.set_mode(SCREEN_RES)
        pg.display.set_caption('Sudoku solver')

        display = Display_board(self.screen)

        val = 0
        blink = False
        alpha = 1
        a_change = True
        blink_color = GREEN
        candidates = []

        get_cord(INITIAL_CORDS)
        set_highlight(INITIAL_CORDS, INITIAL_CORDS, INITIAL_CORDS,
                      INITIAL_LOCK)

        board = create_board().board

        while 1:
            for event in pg.event.get():
                if event.type == pg.QUIT or (event.type == pg.KEYDOWN
                                             and event.key == pg.K_ESCAPE):
                    exit()
                if event.type == pg.MOUSEBUTTONDOWN and input_lock != 1:
                    pos = pg.mouse.get_pos()
                    get_cord(pos)

                    # Checks if selection is on the board
                    if pos[0] < TOP_LX or pos[1] < TOP_LY or pos[0] > int(
                            BOT_RX) or pos[1] > int(BOT_RY):
                        blink = False
                    else:
                        blink = True
                if event.type == pg.KEYDOWN and input_lock != 1:
                    if event.key == pg.K_1:
                        val = 1
                    if event.key == pg.K_2:
                        val = 2
                    if event.key == pg.K_3:
                        val = 3
                    if event.key == pg.K_4:
                        val = 4
                    if event.key == pg.K_5:
                        val = 5
                    if event.key == pg.K_6:
                        val = 6
                    if event.key == pg.K_7:
                        val = 7
                    if event.key == pg.K_8:
                        val = 8
                    if event.key == pg.K_9:
                        val = 9
                    if event.key == pg.K_BACKSPACE:
                        board[int(box_index_x)][int(box_index_y)] = 0
                elif event.type == pg.KEYDOWN and input_lock == 1:
                    if event.key == pg.K_BACKSPACE:
                        val = 0
                        set_highlight(INITIAL_CORDS, INITIAL_CORDS,
                                      INITIAL_CORDS, INITIAL_LOCK)
                        blink_color = GREEN
                        board[int(box_index_x)][int(box_index_y)] = 0

            if val != 0:
                # display.draw_val(val, box_index_x, box_index_y)
                candidates = []
                print("value: ", val, "occupying position: ",
                      board[box_index_x][box_index_y])

                if valid(board, box_index_x, box_index_y, val):
                    if type(board[box_index_x]
                            [box_index_y]) == 0:  # No candidates
                        board[box_index_x][box_index_y] = val
                    elif type(
                            board[box_index_x]
                        [box_index_y]) == int:  # Switching from number to list
                        candidates.append(val)
                        board[box_index_x][box_index_y] = candidates
                    elif valid_cdt(board[box_index_x][box_index_y],
                                   val):  # Adding candidate to list
                        candidates = board[box_index_x][box_index_y]
                        candidates.append(val)
                        board[box_index_x][box_index_y] = candidates

            # Draws the screen
            pg.draw.rect(
                self.screen, BLACK,
                (0, 0, self.screen.get_width(), self.screen.get_height()))
            self.screen.fill(BEIGE)

            # Draws the board
            display.draw(board)

            # Check if cell is selected
            if blink:
                cell = display.find_cell(box_index_x, box_index_y)
                blink = display.blink(alpha, a_change)
                alpha = blink[0]
                a_change = blink[1]
                myRect = pg.Rect(cell)

                rectSurf = pg.Surface(myRect.size, pg.SRCALPHA)
                rectSurf.fill(blink_color)
                rectSurf.set_alpha(alpha)
                self.screen.blit(rectSurf, (myRect.x, myRect.y))

            # Check if incorrect input
            if input_lock == 1 and val != 0:
                display.update(board, row_index, col_index, blk_index)
                blink_color = RED

            val = 0

            # display.draw_box()

            pg.display.update()

        self.solution = solve_board(board)

        self.solution.assign_flags(board)
Exemplo n.º 9
0
def process_second_level(dutifulness, inventory, log):
    """Handle game's second level game."""
    os.system("clear")
    x_hero = 1
    y_hero = 1
    board = create_board("forest.csv")
    previous_sign = board[y_hero][x_hero]
    log = "I need to collect these strange crosses, they can be evidence..."

    obstacles = ["▓", "☘", "༊", "✀", "⛏", "༼", "▯"]
    blood = "~"
    twanas_symbol = "✞"
    twanas = "twanas"
    pickaxe_symbol = "⛏"
    pickaxe = "pickaxe"
    rock = "༼"
    scissors = "scissors"
    enter = "▯"
    scissors_symbol = "✀"

    input_key = getch()  #control

    while dutifulness != 0:
        x_diff = 0
        y_diff = 0

        input_key = getch()
        x_diff, y_diff = control_position(input_key)
        board[y_hero][x_hero] = previous_sign

        if is_move_possible(y_hero + y_diff, x_hero + x_diff, obstacles,
                            board):
            y_hero, x_hero = move_by(y_hero, x_hero, y_diff, x_diff)

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], blood):
            dutifulness = subtract_dutifulness(dutifulness)

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], twanas_symbol):
            board[y_hero + y_diff][x_hero + x_diff] = " "
            add_to_inventory(inventory, twanas)

        if is_touching(board[y_hero + y_diff][x_hero + x_diff],
                       pickaxe_symbol):
            board[y_hero + y_diff][x_hero + x_diff] = " "
            add_to_inventory(inventory, pickaxe)
            log = "Hmmm... pickaxe... I can use it somehow..."

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], rock):
            if is_item_in_inventory(pickaxe, inventory):
                board[y_hero + y_diff][x_hero + x_diff] = " "
                obstacles.remove(rock)
                log = "A bloog-stained scissors? It can be a murder weapon..."
            else:
                log = "I need to find a tool to destroy this rock..."

        if is_taking_item(board[y_hero + y_diff][x_hero + x_diff],
                          scissors_symbol, scissors, inventory):
            board[y_hero + y_diff][x_hero + x_diff] = " "
            add_to_inventory(inventory, scissors)
            log = "I need to go back to police station now."

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], enter):
            if is_item_and_all_twanas_in_inventory(scissors, inventory):
                dutifulness = riddle(dutifulness, "2")
                return dutifulness, inventory, log

        if input_key == "q":
            sys.exit()

        previous_sign = board[y_hero][x_hero]
        print_board_and_insert_player(board, y_hero, x_hero, inventory,
                                      dutifulness, log)

    if dutifulness == 0:
        os.system("clear")
        print_screen("loose.csv")
        sys.exit()
    def run(self):
        pg.init()
        self.screen = pg.display.set_mode(SCREEN_RES)
        pg.display.set_caption('Sudoku solver')

        display = Display_board(self.screen)

        flag1 = 0
        val = 0
        pos = (0, 0)

        input_lock = 0
        get_cord((0, 0))
        set_highlight((0, 0), (0, 0), (0, 0), input_lock)

        board = create_board().board

        while 1:
            for event in pg.event.get():
                if event.type == pg.QUIT or (event.type == pg.KEYDOWN
                                             and event.key == pg.K_ESCAPE):
                    exit()
                if event.type == pg.MOUSEBUTTONDOWN:
                    flag1 = 1
                    pos = pg.mouse.get_pos()
                    get_cord(pos)
                    blink = True
                if event.type == pg.KEYDOWN and input_lock != 1:
                    if event.key == pg.K_1:
                        val = 1
                    if event.key == pg.K_2:
                        val = 2
                    if event.key == pg.K_3:
                        val = 3
                    if event.key == pg.K_4:
                        val = 4
                    if event.key == pg.K_5:
                        val = 5
                    if event.key == pg.K_6:
                        val = 6
                    if event.key == pg.K_7:
                        val = 7
                    if event.key == pg.K_8:
                        val = 8
                    if event.key == pg.K_9:
                        val = 9
                elif event.type == pg.KEYDOWN and input_lock == 1:
                    if event.key == pg.K_BACKSPACE:
                        val = 0
                        set_highlight((0, 0), (0, 0), (0, 0), 0)

            if val != 0:
                display.draw_val(val, box_index_x, box_index_y)

                if valid(board, int(box_index_x), int(box_index_y), val,
                         display):
                    board[int(box_index_x)][int(box_index_y)] = val
                else:
                    board[int(box_index_x)][int(box_index_y)] = 0
                val = 0

            pg.draw.rect(
                self.screen, BLACK,
                (0, 0, self.screen.get_width(), self.screen.get_height()))
            self.screen.fill(BEIGE)

            display.draw(board)
            cell = display.find_cell(box_index_x, box_index_y)
            alpha = display.blink()
            print("start pos x: ", cell[0], "start pos y: ", cell[1],
                  "end pos x: ", cell[2], "end pos y: ", cell[3])
            cell_width = int(cell[2] - cell[0])
            cell_height = int(cell[3] - cell[1])
            print(cell_width, cell_height)
            rect = pg.Surface((cell_width, cell_height))
            rect.set_alpha(alpha)
            self.screen.blit(rect, (int(cell[0]), int(cell, [1])))

            # print(box_index_x, box_index_y)

            if input_lock == 1:
                display.update(board, row_index, col_index, blk_index)

            # display.draw_box()

            pg.display.update()

        self.solution = solve_board(board)

        self.solution.assign_flags(board)
Exemplo n.º 11
0
def handle_trade(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects):

    # adding static part

    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    create_player_info(screen,Players,Cards,cur_player)

    for player in Players:
        player.move_player(screen,player.cur_position)

    other_player = display_select_trade_player_window(screen,Players,Cards,cur_player)

    # create current and other player cards available for trade

    if other_player != -1:

        create_board(screen,Cards)

        create_game_options(screen)

        create_player_info(screen,Players,Cards,cur_player)

        for player in Players:
            player.move_player(screen,player.cur_position)


        player = Players[cur_player]
        other = Players[other_player]

        Cur_Mark = []
        Cur_Other_Mark = []
        Other_Mark = []
        Other_Other_Mark = []
        
        Cur_Mark.extend(player.property_owned)
        
        Cur_Mark.extend(player.property_mortgaged)

        for prop in player.property_owned:
            if Cards[prop].houses_built > 0 or Cards[prop].hotel_built > 0:
                del_color = []           
                for color_cards in player.color_cards_owned:
                    if prop in color_cards:
                        del_color = color_cards
                if del_color != []:
                    for card in del_color:
                        Cur_Mark.remove(card)
                            
        for tmp in Players:
            if tmp != player:
                Cur_Other_Mark.extend(tmp.property_owned)
                Cur_Other_Mark.extend(tmp.property_mortgaged)


        Other_Mark.extend(other.property_owned)

        Other_Mark.extend(other.property_mortgaged)

        for prop in other.property_owned:
            if Cards[prop].houses_built > 0 or Cards[prop].hotel_built > 0:
                del_color = []            
                for color_cards in other.color_cards_owned:
                    if prop in color_cards:
                        del_color = color_cards
                if del_color != []:
                    for card in del_color:
                        Other_Mark.remove(card)

        for tmp in Players:
            if tmp != other:
                Other_Other_Mark.extend(tmp.property_owned)
                Other_Other_Mark.extend(tmp.property_mortgaged)


        if Cur_Mark != None or Other_Mark != None:
            update_game_trade(screen,Players,Cards,cur_player,other_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Cur_Mark,Other_Mark,Cur_Other_Mark,Other_Other_Mark)
            


    # show the state after update


    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    roll_dice(screen,4,2)
    
    for player in Players:
        player.move_player(screen,player.cur_position)

    create_player_info(screen,Players,Cards,cur_player)

    return cur_player


        

            
def handle_dice_roll(screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects):

    # adding static part

    screen.fill(BACKGROUND_COLOR)

    create_board(screen, Cards)

    create_game_options(screen)

    create_player_info(screen, Players, Cards, cur_player)

    # rolling dice

    no1, no2, a, b = roll_dice(screen)
    steps = int(no1) + int(no2)

    player = Players[cur_player]

    initial_card = get_rect_pressed_index(player.cur_position, Cards_Rects)
    final_card = (initial_card + steps) % 40

    # changing the current players' piece position

    final_pos = Cards[final_card].board_pos
    next_position = ()

    if player.color == "BLUE":
        next_position = (final_pos[0] + 19, final_pos[1] + 19)
    elif player.color == "RED":
        next_position = (final_pos[0] + 59, final_pos[1] + 19)
    elif player.color == "GREEN":
        next_position = (final_pos[0] + 19, final_pos[1] + 49)
    elif player.color == "YELLOW":
        next_position = (final_pos[0] + 59, final_pos[1] + 49)
    else:
        next_position = ()

    player.cur_position = next_position
    # player.move_player(screen,next_position)

    # updating the position of all players' piece on the board

    for temp in Players:
        temp.move_player(screen, temp.cur_position)

    # add the necessary actions to be taken due to dice roll
    final_card = update_game_dice(screen, initial_card, final_card, no1, no2, Players, Cards, cur_player)

    # changing the position if there is some related instruction in chance or community card

    final_pos = Cards[final_card].board_pos
    next_position = ()

    if player.color == "BLUE":
        next_position = (final_pos[0] + 19, final_pos[1] + 19)
    elif player.color == "RED":
        next_position = (final_pos[0] + 59, final_pos[1] + 19)
    elif player.color == "GREEN":
        next_position = (final_pos[0] + 19, final_pos[1] + 49)
    elif player.color == "YELLOW":
        next_position = (final_pos[0] + 59, final_pos[1] + 49)
    else:
        next_position = ()

    player.cur_position = next_position

    isBankrupt = False
    quit_player = False

    # check if user is bankrupt or not

    if Players[cur_player].cur_balance < 0:
        Players[cur_player].isBankrupt = True
        isBankrupt = True
    else:
        Players[cur_player].isBankrupt = False

    # run loop till player removes bankruptcy or declares himself as bankrupt

    while not quit_player and isBankrupt:

        # show the state after update

        screen.fill(BACKGROUND_COLOR)

        create_board(screen, Cards)

        create_game_options(screen)

        for player in Players:
            player.move_player(screen, player.cur_position)

        create_player_info(screen, Players, Cards, cur_player)

        quit_player = display_bankrupt_window(
            screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects
        )

        if Players[cur_player].cur_balance < 0:
            Players[cur_player].isBankrupt = True
            isBankrupt = True
        else:
            Players[cur_player].isBankrupt = False
            isBankrupt = False

    # true implies player declares himself as bankrupt and withdraws from the game

    if quit_player == True:
        handle_quit_player(screen, Players, Cards, cur_player)

    # implies player has removed bankruptcy

    else:

        end_turn = False

        while not end_turn:

            # show the state after update

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            end_turn = display_end_turn_window(
                screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects
            )

    # change turn to next player

    screen.fill(BACKGROUND_COLOR)

    create_board(screen, Cards)

    create_game_options(screen)

    roll_dice(screen, 4, 2)

    for player in Players:
        player.move_player(screen, player.cur_position)

    cur_player = (cur_player + 1) % len(Players)

    create_player_info(screen, Players, Cards, cur_player)

    return cur_player
    def run(self):
        pg.init()
        self.screen = pg.display.set_mode(SCREEN_RES)
        pg.display.set_caption('Sudoku solver')

        display = Display_board(self.screen)

        flag1 = 0
        val = 0
        pos = (0, 0)
        blink = False
        alpha = 1
        a_change = True
        blink_color = GREEN

        initial_lock = 0
        get_cord((0, 0))
        set_highlight((0, 0), (0, 0), (0, 0), initial_lock)

        board = create_board().board

        while 1:
            for event in pg.event.get():
                if event.type == pg.QUIT or (event.type == pg.KEYDOWN
                                             and event.key == pg.K_ESCAPE):
                    exit()
                if event.type == pg.MOUSEBUTTONDOWN:
                    flag1 = 1
                    pos = pg.mouse.get_pos()
                    get_cord(pos)

                    # Checks if selection is on the board
                    if pos[0] < TOP_LX or pos[1] < TOP_LY or pos[0] > int(
                            BOT_RX) or pos[1] > int(BOT_RY):
                        blink = False
                    else:
                        blink = True
                if event.type == pg.KEYDOWN and input_lock != 1:
                    if event.key == pg.K_1:
                        val = 1
                    if event.key == pg.K_2:
                        val = 2
                    if event.key == pg.K_3:
                        val = 3
                    if event.key == pg.K_4:
                        val = 4
                    if event.key == pg.K_5:
                        val = 5
                    if event.key == pg.K_6:
                        val = 6
                    if event.key == pg.K_7:
                        val = 7
                    if event.key == pg.K_8:
                        val = 8
                    if event.key == pg.K_9:
                        val = 9
                elif event.type == pg.KEYDOWN and input_lock == 1:
                    if event.key == pg.K_BACKSPACE:
                        val = 0
                        set_highlight((0, 0), (0, 0), (0, 0), initial_lock)
                        blink_color = GREEN

            if val != 0:
                display.draw_val(val, box_index_x, box_index_y)

                if valid(board, int(box_index_x), int(box_index_y), val):
                    board[int(box_index_x)][int(box_index_y)] = val
                else:
                    board[int(box_index_x)][int(box_index_y)] = 0
                val = 0

            # Draws the screen
            pg.draw.rect(
                self.screen, BLACK,
                (0, 0, self.screen.get_width(), self.screen.get_height()))
            self.screen.fill(BEIGE)

            # Draws the board
            display.draw(board)

            # Check if cell is selected
            if blink:
                cell = display.find_cell(box_index_x, box_index_y)
                blink = display.blink(alpha, a_change)
                alpha = blink[0]
                a_change = blink[1]
                myRect = pg.Rect(cell)

                rectSurf = pg.Surface(myRect.size, pg.SRCALPHA)
                rectSurf.fill(blink_color)
                rectSurf.set_alpha(alpha)
                self.screen.blit(rectSurf, (myRect.x, myRect.y))

            # Check if incorrect input
            if input_lock == 1:
                display.update(board, row_index, col_index, blk_index)
                blink_color = RED

            # display.draw_box()

            pg.display.update()

        self.solution = solve_board(board)

        self.solution.assign_flags(board)
Exemplo n.º 14
0
class Main():
    def __init__(self):
        self.board = []
        self.run()

    def run(self):
        pg.init()
        self.screen = pg.display.set_mode(SCREEN_RES)
        pg.display.set_caption('Sudoku solver')

        display = Display_board(self.screen)

        flag1 = 0
        val = 0

        global col_index
        col_index = (x, index)
        global input_lock
        input_lock = 1
        global col_index
            col_index = (x, index)
            global input_lock
            input_lock = 1

        board = create_board().board

        while 1:
            for event in pg.event.get():
                if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
                    exit()
                if event.type == pg.MOUSEBUTTONDOWN:
                    flag1 = 1
                    pos = pg.mouse.get_pos()
                    get_cord(pos)
                    print(pos, box_index_x, box_index_y)
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_1:
                        val = 1
                    if event.key == pg.K_2:
                        val = 2
                    if event.key == pg.K_3:
                        val = 3
                    if event.key == pg.K_4:
                        val = 4
                    if event.key == pg.K_5:
                        val = 5
                    if event.key == pg.K_6:
                        val = 6
                    if event.key == pg.K_7:
                        val = 7
                    if event.key == pg.K_8:
                        val = 8
                    if event.key == pg.K_9:
                        val = 9

            if val != 0:
                display.draw_val(val, box_index_x, box_index_y)

                if valid(board, int(box_index_x), int(box_index_y), val, display):
                    board[int(box_index_x)][int(box_index_y)] = val
                else:
                    board[int(box_index_x)][int(box_index_y)] = 0
                val = 0

                print(input_lock)

            pg.draw.rect(self.screen, BLACK, (0, 0, self.screen.get_width(), self.screen.get_height()))
            self.screen.fill(BEIGE)

            display.draw(board)

            if row_index != (0, 0) or col_index != (0, 0) or blk_index != (0, 0):
                print(row_index, col_index, blk_index)
                display.update(board, row_index, col_index, blk_index)
            # display.draw_box()

            pg.display.update()


        self.solution = solve_board(board)

        self.solution.assign_flags(board)
def handle_decide_winner(screen,Players,Cards,cur_player):

    if cur_player == 0:

        # adding static part

        screen.fill(BACKGROUND_COLOR)

        create_board(screen,Cards)

        create_game_options(screen)

        create_player_info(screen,Players,Cards,cur_player)

        for player in Players:
            player.move_player(screen,player.cur_position)


        # declare winner logic
        # calculate current balance, property value

        Players_Worth = []
        worth = 0

        for player in Players:
            worth = 0

            # adding current balance
            worth += player.cur_balance

            # adding owned property worth
            for own in player.property_owned:
                worth += (Cards[own].houses_built * Cards[own].house_cost)
                worth += (Cards[own].hotel_built * Cards[own].hotel_cost)
                worth += (Cards[own].cost)

            for mort in player.property_mortgaged:
                worth += Cards[mort].mortgage_value

            Players_Worth.append(worth)

        end = display_decide_winner_window(screen,Players,Players_Worth)

        if end == True:
            pygame.quit()
            sys.exit()
        else:

            screen.fill(BACKGROUND_COLOR)

            create_board(screen,Cards)

            create_game_options(screen)

            roll_dice(screen,4,2)
            
            for player in Players:
                player.move_player(screen,player.cur_position)

            create_player_info(screen,Players,Cards,cur_player)


    return cur_player
def update_game_trade(screen,Players,Cards,cur_player,other_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Cur_Mark,Other_Mark,Cur_Other_Mark,Other_Other_Mark):


    send_amount = 0
    receive_amount = 0
    send_property = set()
    receive_property = set()


    offer,send_amount,send_property,receive_amount,receive_property = display_trade_window(screen,Players,Cards,cur_player,other_player,Cur_Mark,Other_Mark,Cur_Other_Mark,Other_Other_Mark,send_amount,receive_amount,send_property,receive_property)


    if offer == True:
        
        if (send_property != set() or receive_property != set()) and (send_property.issubset(set(Cur_Mark)) and receive_property.issubset(set(Other_Mark))):

            Send_Cards = []
            Receive_Cards = []
        
            for send_index in send_property:
                Send_Cards.append(Cards[send_index])

            for receive_index in receive_property:
                Receive_Cards.append(Cards[receive_index])

            
            screen.fill(BACKGROUND_COLOR)

            create_board(screen,Cards)

            create_game_options(screen)
            
            for player in Players:
                player.move_player(screen,player.cur_position)

            create_player_info(screen,Players,Cards,cur_player)

            # confirmation prompt
            # show trade infomation


            

            trade_prop = display_trade_confirm_window(screen,Send_Cards,send_amount,Receive_Cards,receive_amount)


            if trade_prop == True:

                player = Players[cur_player]
                other = Players[other_player]

                # trade property action

                if send_amount > 0:
                    other.cur_balance += send_amount
                    player.cur_balance -= send_amount


                if receive_amount > 0:
                    other.cur_balance -= receive_amount
                    player.cur_balance += receive_amount

                if send_property != set():
                    send_property = list(send_property)

                    for send_index in send_property:

                        if Cards[send_index].status == 1:
                            player.property_owned.remove(send_index)
                            other.property_owned.append(send_index)
                        elif Cards[send_index].status == 2:
                            player.property_mortgaged.remove(send_index)
                            other.property_mortgaged.append(send_index)

                        if send_index in RAILS_CARDS:
                            player.total_rails_owned -= 1
                            other.total_rails_owned += 1
                        elif send_index in UTILITY_CARDS:
                            player.total_utilities_owned -= 1
                            other.total_utilities_owned += 1
                        else:

                            del_color = []

                            for color_cards in player.color_cards_owned:
                                if send_index in color_cards:
                                    del_color = color_cards

                            if del_color != []:
                                player.color_cards_owned.remove(del_color)

                            property_owned = set(other.property_owned)

                            if set(BROWN_CARDS).issubset(property_owned) and BROWN_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(BROWN_CARDS)
                            if set(LIGHT_BLUE_CARDS).issubset(property_owned) and LIGHT_BLUE_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(LIGHT_BLUE_CARDS)
                            if set(PINK_CARDS).issubset(property_owned) and PINK_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(PINK_CARDS)
                            if set(ORANGE_CARDS).issubset(property_owned) and ORANGE_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(ORANGE_CARDS)
                            if set(RED_CARDS).issubset(property_owned) and RED_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(RED_CARDS)
                            if set(YELLOW_CARDS).issubset(property_owned) and YELLOW_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(YELLOW_CARDS)
                            if set(GREEN_CARDS).issubset(property_owned) and GREEN_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(GREEN_CARDS)
                            if set(BLUE_CARDS).issubset(property_owned) and BLUE_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(BLUE_CARDS)    




                if receive_property != set():
                    receive_property = list(receive_property)

                    for receive_index in receive_property:

                        if Cards[receive_index].status == 1:
                            other.property_owned.remove(receive_index)
                            player.property_owned.append(receive_index)
                        elif Cards[receive_index].status == 2:
                            other.property_mortgaged.remove(receive_index)
                            player.property_mortgaged.append(receive_index)

                        if receive_index in RAILS_CARDS:
                            other.total_rails_owned -= 1
                            player.total_rails_owned += 1
                        elif receive_index in UTILITY_CARDS:
                            other.total_utilities_owned -= 1
                            player.total_utilities_owned += 1
                        else:

                            del_color = []

                            for color_cards in other.color_cards_owned:
                                if receive_index in color_cards:
                                    del_color = color_cards

                            if del_color != []:
                                other.color_cards_owned.remove(del_color)

                            property_owned = set(player.property_owned)

                            if set(BROWN_CARDS).issubset(property_owned) and BROWN_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(BROWN_CARDS)
                            if set(LIGHT_BLUE_CARDS).issubset(property_owned) and LIGHT_BLUE_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(LIGHT_BLUE_CARDS)
                            if set(PINK_CARDS).issubset(property_owned) and PINK_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(PINK_CARDS)
                            if set(ORANGE_CARDS).issubset(property_owned) and ORANGE_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(ORANGE_CARDS)
                            if set(RED_CARDS).issubset(property_owned) and RED_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(RED_CARDS)
                            if set(YELLOW_CARDS).issubset(property_owned) and YELLOW_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(YELLOW_CARDS)
                            if set(GREEN_CARDS).issubset(property_owned) and GREEN_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(GREEN_CARDS)
                            if set(BLUE_CARDS).issubset(property_owned) and BLUE_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(BLUE_CARDS)

            else:

                player = Players[cur_player]
                other = Players[other_player]

                Cur_Mark = []
                Other_Mark = []

                for prop in player.property_owned:
                    Cur_Mark.append(prop)

                for prop in player.property_mortgaged:
                    Cur_Mark.append(prop)

                for prop in other.property_owned:
                    Other_Mark.append(prop)

                for prop in other.property_mortgaged:
                    Other_Mark.append(prop)

                if Cur_Mark != None or Other_Mark != None:
                    # adding static part
                    
                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen,Cards)

                    create_game_options(screen)
                    
                    for player in Players:
                        player.move_player(screen,player.cur_position)

                    create_player_info(screen,Players,Cards,cur_player)
                                
                    update_game_trade(screen,Players,Cards,cur_player,other_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Cur_Mark,Other_Mark)


                                                
                
        else:

            player = Players[cur_player]
            other = Players[other_player]

            Cur_Mark = []
            Other_Mark = []

            for prop in player.property_owned:
                Cur_Mark.append(prop)

            for prop in player.property_mortgaged:
                Cur_Mark.append(prop)

            for prop in other.property_owned:
                Other_Mark.append(prop)

            for prop in other.property_mortgaged:
                Other_Mark.append(prop)

            if Cur_Mark != None or Other_Mark != None:
                # adding static part
                
                screen.fill(BACKGROUND_COLOR)

                create_board(screen,Cards)

                create_game_options(screen)
                
                for player in Players:
                    player.move_player(screen,player.cur_position)

                create_player_info(screen,Players,Cards,cur_player)
                            
                update_game_trade(screen,Players,Cards,cur_player,other_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Cur_Mark,Other_Mark)
def update_game_mortgage(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark):

    # removing cards with houses/hotel built on them

    for card in Mark:
        if Cards[card].hotel_built == 1 or Cards[card].houses_built > 0:
            Mark.remove(card)


    # get the card that was selected
    mortgage_card = display_mortgage_window(screen,Players,Cards,cur_player,Mark)

    # check if the card is valid
    # check the card against selling rules

    if mortgage_card != None:
        if mortgage_card in Mark:

            card = Cards[mortgage_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen,Cards)

            create_game_options(screen)
            
            for player in Players:
                player.move_player(screen,player.cur_position)

            create_player_info(screen,Players,Cards,cur_player)

            # confirmation prompt
            # show mortgage infomation

            mortgage_prop = display_mortgage_confirm_window(screen,card)



            # update card status and player balance

            if mortgage_prop == True:

                player = Players[cur_player]
                # mortgage property action

                player.cur_balance += card.mortgage_value
                player.property_owned.remove(card.id_no)
                player.property_mortgaged.append(card.id_no)
                card.status = 2

                
                # check rail,utility or color card
                if card.id_no in RAILS_CARDS:
                    player.total_rails_owned -= 1
                elif card.id_no in UTILITY_CARDS:
                    player.total_utilities_owned -= 1
                else:
                    del_color = []

                    # finding color group to which the card belongs
                    
                    for color_cards in player.color_cards_owned:
                        if card.id_no in color_cards:
                            del_color = color_cards

                    if del_color != []:
                        player.color_cards_owned.remove(del_color)

                     
            else:

                Mark = []

                player = Players[cur_player]

                for prop in player.property_owned:
                    Mark.append(prop)
                
                # display mortgage window

                if Mark != []:
                    # adding static part
                    
                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen,Cards)

                    create_game_options(screen)

                    create_player_info(screen,Players,Cards,cur_player)

                    for player in Players:
                        player.move_player(screen,player.cur_position)


                    update_game_mortgage(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark)


        else:
            Mark = []

            player = Players[cur_player]

            for prop in player.property_owned:
                Mark.append(prop)
           
            # display mortgage window

            if Mark != []:
                # adding static part
                
                screen.fill(BACKGROUND_COLOR)

                create_board(screen,Cards)

                create_game_options(screen)

                create_player_info(screen,Players,Cards,cur_player)

                for player in Players:
                    player.move_player(screen,player.cur_position)


                update_game_mortgage(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark)
Exemplo n.º 18
0
def run_game():

    pygame.init()

    WINDOW_SIZE = [SCREEN_WIDTH,SCREEN_HEIGHT]
    screen = pygame.display.set_mode(WINDOW_SIZE)

    screen.fill(BACKGROUND_COLOR)

    pygame.display.set_caption("MONOPOLY")


    # ask for game details

    no_of_players,player_names,player_colors = ask_for_game_details(screen)
    

   # handle game details


    # creating the players
    
    Players = []

    for i in range(0,no_of_players):
        Players.append(Player(player_names[i],player_colors[i],1500))



    Cards,Cards_Rects = create_card_rects()

    # create initial board

    create_board(screen,Cards)

    # rolls dice and places them at random position with 4 and 2 number in 1st and 2nd die respectively
    no1,no2,dice1_cord,dice2_cord = roll_dice(screen,4,2)           # Since 42 is the answer to everything :)


    # placing the game pieces at the start position for each player

    for player in Players:
        
        if player.color == "BLUE":
            next_position = (1020,720)
        elif player.color == "RED":
            next_position = (1060,720)
        elif player.color == "GREEN":
            next_position = (1020,750)
        elif player.color == "YELLOW":
            next_position = (1060,750)
        else:
            next_position = ()


        player.move_player(screen,next_position)

    # create game options

    create_game_options(screen)

    Option_Rects = create_option_rects()


    # create player info

    # stores the index of player whose turn it is now
    
    cur_player = 0;


    """
        Test Data
    """

    Players[cur_player].property_owned.append(1)
    Players[cur_player].property_owned.append(3)
    Cards[1].status = 1
    Cards[3].status = 1
    Players[cur_player].color_cards_owned.append(BROWN_CARDS)

    #Players[cur_player].cur_balance = -50

    """
    """

    create_player_info(screen,Players,Cards,cur_player)

    Info_Cards_Rects = create_info_rects()

        
    # adding music

    sound = pygame.mixer.Sound("game.ogg")
    sound.play(loops = -1)

    # START GAME PROMPT

    done = display_start_game_window(screen,Players,Cards,cur_player)

    clock = pygame.time.Clock()

    isRunning = False


    #--------------MAIN GAME LOOP------------------
    while not done:
        
        for event in pygame.event.get():
            
            """
                check_inputs()    #get key/mouse input inputs for this frame
                handle_inputs()    #handle each input that has occurred during this frame
                update_gamestate()    #update the state on the game (who's turn, etc)
                update_display()    #update pygame window graphics (draw stuff, flip display)

            """                

            if event.type == pygame.QUIT:
                done = True
            elif event.type == pygame.MOUSEBUTTONDOWN:

                # check inputs
                
                mouse_pos = pygame.mouse.get_pos()

                # handle inputs

                Rects = get_rect_pressed_type(mouse_pos,Cards_Rects,Option_Rects,Info_Cards_Rects)
                if Rects != None:

                    # rects is option,info or board
                    
                    rect_index = get_rect_pressed_index(mouse_pos,Rects)

                    # take necessary action based on the event that occured in the game
                    # kind of semaphore I think ;)

                    if Rects == Option_Rects and rect_index < len(Rects):

                        # rect is among the Rects
                        
                        if isRunning == False:
                            isRunning = True
                            cur_player,isRunning = handle_game(screen,Rects,rect_index,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,isRunning)
                
            elif event.type == pygame.MOUSEMOTION:

                # check inputs
                
                mouse_pos = pygame.mouse.get_pos()

                # handle inputs

                Rects = get_rect_pressed_type(mouse_pos,Cards_Rects,Option_Rects,Info_Cards_Rects)
                if Rects != None:

                    # rects is option,info or board
                    
                    rect_index = get_rect_pressed_index(mouse_pos,Rects)

                    # take necessary action based on the rect that was hovered in the game

                    if Rects == Option_Rects and rect_index < len(Rects):

                        screen.fill(BACKGROUND_COLOR)

                        create_board(screen,Cards)

                        roll_dice(screen,4,2,dice1_cord,dice2_cord)

                        create_game_options(screen)
                        
                        for player in Players:
                            player.move_player(screen,player.cur_position)
                        
                        create_player_info(screen,Players,Cards,cur_player)


                        pygame.draw.rect(screen,
                                         LIGHT_BLUE,
                                         ((Rects[rect_index].left,
                                          Rects[rect_index].top),
                                         (Rects[rect_index].width,
                                          Rects[rect_index].height)))

                        if rect_index == 0:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 20)
                            font.set_bold(True)
                            screen.blit(font.render('ROLL DICE', True, WHITE), (22, 800))

                        elif rect_index == 1:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 20)
                            font.set_bold(True)
                            screen.blit(font.render('BUILD', True, WHITE), (205, 800))

                        elif rect_index == 2:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 20)
                            font.set_bold(True)
                            screen.blit(font.render('TRADE', True, WHITE), (365, 800))

                        elif rect_index == 3:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 20)
                            font.set_bold(True)
                            screen.blit(font.render('SELL', True, WHITE), (535, 800))

                        elif rect_index == 4:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 20)
                            font.set_bold(True)
                            screen.blit(font.render('MORTGAGE', True, WHITE), (660, 800))

                        elif rect_index == 5:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 15)
                            font.set_bold(True)
                            screen.blit(font.render('UNMORTGAGE', True, WHITE), (820, 800))

                        elif rect_index == 6:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 15)
                            font.set_bold(True)
                            screen.blit(font.render('DEC. WINNER', True, WHITE), (990, 800))

                        elif rect_index == 7:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 20)
                            font.set_bold(True)
                            screen.blit(font.render('RULES(?)', True, WHITE), (1160, 800))

                        elif rect_index == 8:
                            
                            font = pygame.font.SysFont(CARD_TEXT_STYLE, 18)
                            font.set_bold(True)
                            screen.blit(font.render('QUIT GAME', True, WHITE), (1315, 800))


                        pygame.display.update()
                            
            
                    elif Rects == Cards_Rects and rect_index < len(Rects):

                        screen.fill(BACKGROUND_COLOR)

                        create_board(screen,Cards)

                        roll_dice(screen,4,2,dice1_cord,dice2_cord)

                        create_game_options(screen)
                        
                        for player in Players:
                            player.move_player(screen,player.cur_position)
                        
                        create_player_info(screen,Players,Cards,cur_player)

                        pygame.gfxdraw.box(screen,
                                           ((ACTION_SCREEN_LEFT,ACTION_SCREEN_TOP),
                                            (ACTION_SCREEN_WIDTH,ACTION_SCREEN_HEIGHT)),TRANSPARENT)

                        propImg = pygame.image.load(Cards[rect_index].img)
                        propImg = pygame.transform.scale(propImg,(240,280))
                        screen.blit(propImg,(410,240))



                    elif Rects == Info_Cards_Rects and rect_index < len(Rects) and Rects[rect_index] != None:

                        screen.fill(BACKGROUND_COLOR)

                        create_board(screen,Cards)

                        roll_dice(screen,4,2,dice1_cord,dice2_cord)

                        create_game_options(screen)
                        
                        for player in Players:
                            player.move_player(screen,player.cur_position)
                        
                        create_player_info(screen,Players,Cards,cur_player)
                        
                        pygame.gfxdraw.box(screen,
                                           ((ACTION_SCREEN_LEFT,ACTION_SCREEN_TOP),
                                            (ACTION_SCREEN_WIDTH,ACTION_SCREEN_HEIGHT)),TRANSPARENT)

                        propImg = pygame.image.load(Cards[rect_index].img)
                        propImg = pygame.transform.scale(propImg,(240,280))
                        screen.blit(propImg,(410,240))

                    else:
                    
                        screen.fill(BACKGROUND_COLOR)
                        
                        create_board(screen,Cards)

                        roll_dice(screen,4,2,dice1_cord,dice2_cord)

                        create_game_options(screen)
                        
                        for player in Players:
                            player.move_player(screen,player.cur_position)
                        
                        create_player_info(screen,Players,Cards,cur_player)



                else:
                
                    screen.fill(BACKGROUND_COLOR)
                    
                    create_board(screen,Cards)

                    roll_dice(screen,4,2,dice1_cord,dice2_cord)

                    create_game_options(screen)
                    
                    for player in Players:
                        player.move_player(screen,player.cur_position)
                    
                    create_player_info(screen,Players,Cards,cur_player)

            
    

        clock.tick(60)

        pygame.display.update()


    pygame.quit()
Exemplo n.º 19
0
def run_game():

    pygame.init()

    WINDOW_SIZE = [SCREEN_WIDTH,SCREEN_HEIGHT]
    screen = pygame.display.set_mode(WINDOW_SIZE)

    screen.fill(BACKGROUND_COLOR)

    pygame.display.set_caption("MONOPOLY")


    # ask for game details

    no_of_players,player_names,player_colors = ask_for_game_details(screen)
    

   # handle game details


    # creating the players
    
    Players = []

    for i in range(0,no_of_players):
        Players.append(Player(player_names[i],player_colors[i],1000))

    # creating the cards

    Cards = []

    # id_no,name,color,cost,rent,mortgage_value,house_cost,hotel_cost,house_rent,hotel_rent,board_pos,info_pos

    card = Card(0,"GO","",0,0,0,0,0,[],0,(1001,701),())
    Cards.append(card)
    
    card = Card(1,"MEDITARREANEAN AVENUE","BROWN",60,2,30,50,50,[10,30,90,160],250,(901,701),(1380,350))
    Cards.append(card)
    
    card = Card(2,"COMMUNITY CHEST","",0,0,0,0,0,[],0,(801,701),())
    Cards.append(card)

    card = Card(3,"BALTIC AVENUE","BROWN",80,4,30,50,50,[20,60,80,320],450,(701,701),(1330,350))
    Cards.append(card)

    card = Card(4,"INCOME TAX","",0,0,0,0,0,[],0,(601,701),())
    Cards.append(card)

    card = Card(5,"READING RAILROAD","BLACK",200,25,100,0,0,[],0,(501,701),(1280,350))
    Cards.append(card)

    card = Card(6,"ORIENTAL AVENUE","LIGHT_BLUE",100,6,50,50,50,[30,90,270,400],450,(401,701),(1255,350))
    Cards.append(card)
   
    card = Card(7,"CHANCE","",0,0,0,0,0,[],0,(301,701),())
    Cards.append(card)
   
    card = Card(8,"VERMONT AVENUE","LIGHT_BLUE",100,6,50,50,50,[30,90,270,400],450,(201,701),(1205,350))
    Cards.append(card)

    card = Card(9,"CONNECTICUT AVENUE","LIGHT_BLUE",120,8,60,50,50,[40,100,300,450],600,(101,701),(1180,350))
    Cards.append(card)

    card = Card(10,"IN JAIL","",0,0,0,0,0,[],0,(1,701),())
    Cards.append(card)

    card = Card(11,"ST. CHARLES PLACE","PINK",140,10,70,100,100,[50,150,450,625],750,(1,631),(1155,325))
    Cards.append(card)

    card = Card(12,"ELECTIC COMPANY","WHITE",150,10,75,0,0,[],0,(1,561),(1155,300))
    Cards.append(card)

    card = Card(13,"STATES AVENUE","PINK",140,10,70,100,100,[50,150,450,625],750,(1,491),(1155,275))
    Cards.append(card)

    card = Card(14,"VIRGINIA AVENUE","PINK",160,12,80,100,100,[60,180,500,700],900,(1,421),(1155,250))
    Cards.append(card)

    card = Card(15,"PENNSYLVANIA RAILROAD","BLACK",200,25,100,0,0,[],0,(1,351),(1155,225))
    Cards.append(card)

    card = Card(16,"ST. JAMES PLACE","ORANGE",180,14,90,100,100,[70,200,550,750],950,(1,281),(1155,200))
    Cards.append(card)

    card = Card(17,"COMMUNITY CHEST","",0,0,0,0,0,[],0,(1,211),())
    Cards.append(card)

    card = Card(18,"TENNESSEE AVENUE","ORANGE",180,14,90,100,100,[70,200,550,750],950,(1,141),(1155,150))
    Cards.append(card)

    card = Card(19,"NEW YORK AVENUE","ORANGE",200,16,100,100,100,[80,220,600,800],1000,(1,71),(1155,125))
    Cards.append(card)

    card = Card(20,"FREE PARKING","",0,0,0,0,0,[],0,(1,1),())
    Cards.append(card)

    card = Card(21,"KENTUCKY AVENUE","RED",220,18,110,150,150,[90,250,700,875],1050,(101,1),(1180,100))
    Cards.append(card)

    card = Card(22,"CHANCE","",0,0,0,0,0,[],0,(201,1),())
    Cards.append(card)

    card = Card(23,"INDIANA AVENUE","RED",220,18,110,150,150,[90,250,700,875],1050,(301,1),(1230,100))
    Cards.append(card)

    card = Card(24,"ILLINOIS AVENUE","RED",240,20,120,150,150,[100,300,750,925],1100,(401,1),(1255,100))
    Cards.append(card)

    card = Card(25,"B. & O. RAILROAD","BLACK",200,25,100,0,0,[],0,(501,1),(1280,100))
    Cards.append(card)

    card = Card(26,"ATLANTIC AVENUE","YELLOW",260,22,130,150,150,[110,330,800,975],1150,(601,1),(1305,100))
    Cards.append(card)

    card = Card(27,"VENTORA AVENUE","YELLOW",260,22,130,150,150,[110,330,800,975],1150,(701,1),(1330,100))
    Cards.append(card)

    card = Card(28,"WATER WORKS","WHITE",150,10,75,0,0,[],0,(801,1),(1355,100))
    Cards.append(card)

    card = Card(29,"MARVIN GARDENS","YELLOW",280,24,140,150,150,[120,360,850,1025],1200,(901,1),(1380,100))
    Cards.append(card)

    card = Card(30,"GO TO JAIL","",0,0,0,0,0,[],0,(1001,1),())
    Cards.append(card)

    card = Card(31,"PACIFIC AVENUE","GREEN",300,26,150,200,200,[130,390,900,1100],1275,(1001,71),(1405,125))
    Cards.append(card)

    card = Card(32,"CAROLINA AVENUE","GREEN",300,26,150,200,200,[130,390,900,1100],1275,(1001,141),(1405,150))
    Cards.append(card)

    card = Card(33,"COMMUNITY CHEST","",0,0,0,0,0,[],0,(1001,211),())
    Cards.append(card)

    card = Card(34,"PENNSYLVANIA AVENUE","GREEN",320,28,160,200,200,[150,450,1000,1200],1400,(1001,281),(1405,200))
    Cards.append(card)

    card = Card(35,"SHORT LANE","BLACK",200,25,100,0,0,[],0,(1001,351),(1405,225))
    Cards.append(card)

    card = Card(36,"CHANCE","",0,0,0,0,0,[],0,(1001,421),())
    Cards.append(card)
 
    card = Card(37,"PARK PLACE","BLUE",350,35,175,200,200,[175,500,1100,1300],1500,(1001,491),(1405,275))
    Cards.append(card)

    card = Card(38,"LUXURY TAX","",0,0,0,0,0,[],0,(1001,561),())
    Cards.append(card)

    card = Card(39,"BROADWALK","BLUE",400,50,200,200,200,[200,600,1400,1700],2000,(1001,631),(1405,325))
    Cards.append(card)




    # create initial board

    create_board(screen,player_colors)

    # placing the game pieces at the start position for each player

    for player in Players:
        
        if player.color == "BLUE":
            next_position = (1020,720)
        elif player.color == "RED":
            next_position = (1060,720)
        elif player.color == "GREEN":
            next_position = (1020,750)
        elif player.color == "YELLOW":
            next_position = (1060,750)
        else:
            next_position = ()


        player.move_player(screen,next_position)

    # create game options

    create_game_options(screen)
    

    # create player info

    # stores the index of player whose turn it is now
    
    cur_player = 0;

   
    create_player_info(screen,Players,Cards,cur_player)
    

    manImg = pygame.image.load('man.png')
    screen.blit(manImg,(400,315))

    done = False

    clock = pygame.time.Clock()


    #--------------MAIN GAME LOOP------------------
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
            elif event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print(pos)
                #col = pos[0] // (CARD_WIDTH + CARD_MARGIN)
                #row = pos[1] // (CARD_HEIGHT + CARD_MARGIN)
                

        ####

        

        clock.tick(60)

        pygame.display.update()


    pygame.quit()
Exemplo n.º 20
0
def update_game_unmortgage(screen, Players, Cards, cur_player, Cards_Rects,
                           Option_Rects, Info_Cards_Rects, Mark):

    # get the card that was selected
    unmortgage_card = display_unmortgage_window(screen, Players, Cards,
                                                cur_player, Mark)

    # check if the card is valid
    # check the card against selling rules
    # check if card's unmortgage cost is less than player's current balance

    if unmortgage_card != None:
        if unmortgage_card in Mark and int(
                Cards[unmortgage_card].mortgage_value *
                1.1) <= Players[cur_player].cur_balance:

            card = Cards[unmortgage_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            # confirmation prompt
            # show unmortgage infomation

            unmortgage_prop = display_unmortgage_confirm_window(screen, card)

            # update card status and player balance

            if unmortgage_prop == True:

                player = Players[cur_player]
                # unmortgage property action

                player.cur_balance -= int(card.mortgage_value * 1.1)
                player.property_mortgaged.remove(card.id_no)
                player.property_owned.append(card.id_no)
                card.status = 1

                # check rail,utility or color card
                if card.id_no in RAILS_CARDS:
                    player.total_rails_owned += 1
                elif card.id_no in UTILITY_CARDS:
                    player.total_utilities_owned += 1
                else:

                    # finding color group to which the card belongs

                    property_owned = set(player.property_owned)

                    if set(BROWN_CARDS).issubset(
                            property_owned
                    ) and BROWN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BROWN_CARDS)
                    if set(LIGHT_BLUE_CARDS).issubset(
                            property_owned
                    ) and LIGHT_BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(LIGHT_BLUE_CARDS)
                    if set(PINK_CARDS).issubset(
                            property_owned
                    ) and PINK_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(PINK_CARDS)
                    if set(ORANGE_CARDS).issubset(
                            property_owned
                    ) and ORANGE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(ORANGE_CARDS)
                    if set(RED_CARDS).issubset(
                            property_owned
                    ) and RED_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(RED_CARDS)
                    if set(YELLOW_CARDS).issubset(
                            property_owned
                    ) and YELLOW_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(YELLOW_CARDS)
                    if set(GREEN_CARDS).issubset(
                            property_owned
                    ) and GREEN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(GREEN_CARDS)
                    if set(BLUE_CARDS).issubset(
                            property_owned
                    ) and BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BLUE_CARDS)

            else:

                Mark = []

                player = Players[cur_player]

                for prop in player.property_mortgaged:
                    Mark.append(prop)

                # display unmortgage window

                if Mark != []:
                    # adding static part

                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen, Cards)

                    create_game_options(screen)

                    create_player_info(screen, Players, Cards, cur_player)

                    for player in Players:
                        player.move_player(screen, player.cur_position)

                    update_game_unmortgage(screen, Players, Cards, cur_player,
                                           Cards_Rects, Option_Rects,
                                           Info_Cards_Rects, Mark)

        else:
            Mark = []

            player = Players[cur_player]

            for prop in player.property_mortgaged:
                Mark.append(prop)

            # display unmortgage window

            if Mark != []:
                # adding static part

                screen.fill(BACKGROUND_COLOR)

                create_board(screen, Cards)

                create_game_options(screen)

                create_player_info(screen, Players, Cards, cur_player)

                for player in Players:
                    player.move_player(screen, player.cur_position)

                update_game_unmortgage(screen, Players, Cards, cur_player,
                                       Cards_Rects, Option_Rects,
                                       Info_Cards_Rects, Mark)
def update_game_unmortgage(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark):


    # get the card that was selected
    unmortgage_card = display_unmortgage_window(screen,Players,Cards,cur_player,Mark)

    # check if the card is valid
    # check the card against selling rules
    # check if card's unmortgage cost is less than player's current balance

    if unmortgage_card != None:
        if unmortgage_card in Mark and int(Cards[unmortgage_card].mortgage_value*1.1) <= Players[cur_player].cur_balance:

            card = Cards[unmortgage_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen,Cards)

            create_game_options(screen)
            
            for player in Players:
                player.move_player(screen,player.cur_position)

            create_player_info(screen,Players,Cards,cur_player)

            # confirmation prompt
            # show unmortgage infomation

            unmortgage_prop = display_unmortgage_confirm_window(screen,card)



            # update card status and player balance

            if unmortgage_prop == True:

                player = Players[cur_player]
                # unmortgage property action

                player.cur_balance -= int(card.mortgage_value*1.1)
                player.property_mortgaged.remove(card.id_no)
                player.property_owned.append(card.id_no)
                card.status = 1

                
                # check rail,utility or color card
                if card.id_no in RAILS_CARDS:
                    player.total_rails_owned += 1
                elif card.id_no in UTILITY_CARDS:
                    player.total_utilities_owned += 1
                else:
                    
                    # finding color group to which the card belongs

                    property_owned = set(player.property_owned)
                    
                    if set(BROWN_CARDS).issubset(property_owned) and BROWN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BROWN_CARDS)
                    if set(LIGHT_BLUE_CARDS).issubset(property_owned) and LIGHT_BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(LIGHT_BLUE_CARDS)
                    if set(PINK_CARDS).issubset(property_owned) and PINK_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(PINK_CARDS)
                    if set(ORANGE_CARDS).issubset(property_owned) and ORANGE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(ORANGE_CARDS)
                    if set(RED_CARDS).issubset(property_owned) and RED_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(RED_CARDS)
                    if set(YELLOW_CARDS).issubset(property_owned) and YELLOW_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(YELLOW_CARDS)
                    if set(GREEN_CARDS).issubset(property_owned) and GREEN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(GREEN_CARDS)
                    if set(BLUE_CARDS).issubset(property_owned) and BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BLUE_CARDS)    

                     
            else:

                Mark = []

                player = Players[cur_player]

                for prop in player.property_mortgaged:
                    Mark.append(prop)
                
                # display unmortgage window

                if Mark != []:
                    # adding static part
                    
                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen,Cards)

                    create_game_options(screen)

                    create_player_info(screen,Players,Cards,cur_player)

                    for player in Players:
                        player.move_player(screen,player.cur_position)


                    update_game_unmortgage(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark)


        else:
            Mark = []

            player = Players[cur_player]

            for prop in player.property_mortgaged:
                Mark.append(prop)
           
            # display unmortgage window

            if Mark != []:
                # adding static part
                
                screen.fill(BACKGROUND_COLOR)

                create_board(screen,Cards)

                create_game_options(screen)

                create_player_info(screen,Players,Cards,cur_player)

                for player in Players:
                    player.move_player(screen,player.cur_position)


                update_game_unmortgage(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Mark)
Exemplo n.º 22
0
def handle_decide_winner(screen, Players, Cards, cur_player):

    if cur_player == 0:

        # adding static part

        screen.fill(BACKGROUND_COLOR)

        create_board(screen, Cards)

        create_game_options(screen)

        create_player_info(screen, Players, Cards, cur_player)

        for player in Players:
            player.move_player(screen, player.cur_position)

        # declare winner logic
        # calculate current balance, property value

        Players_Worth = []
        worth = 0

        for player in Players:
            worth = 0

            # adding current balance
            worth += player.cur_balance

            # adding owned property worth
            for own in player.property_owned:
                worth += (Cards[own].houses_built * Cards[own].house_cost)
                worth += (Cards[own].hotel_built * Cards[own].hotel_cost)
                worth += (Cards[own].cost)

            for mort in player.property_mortgaged:
                worth += Cards[mort].mortgage_value

            Players_Worth.append(worth)

        end = display_decide_winner_window(screen, Players, Players_Worth)

        if end == True:
            pygame.quit()
            sys.exit()
        else:

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            roll_dice(screen, 4, 2)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

    return cur_player
Exemplo n.º 23
0
def update_game_mortgage(screen, Players, Cards, cur_player, Cards_Rects,
                         Option_Rects, Info_Cards_Rects, Mark):

    # removing cards with houses/hotel built on them

    for card in Mark:
        if Cards[card].hotel_built == 1 or Cards[card].houses_built > 0:
            Mark.remove(card)

    # get the card that was selected
    mortgage_card = display_mortgage_window(screen, Players, Cards, cur_player,
                                            Mark)

    # check if the card is valid
    # check the card against selling rules

    if mortgage_card != None:
        if mortgage_card in Mark:

            card = Cards[mortgage_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            # confirmation prompt
            # show mortgage infomation

            mortgage_prop = display_mortgage_confirm_window(screen, card)

            # update card status and player balance

            if mortgage_prop == True:

                player = Players[cur_player]
                # mortgage property action

                player.cur_balance += card.mortgage_value
                player.property_owned.remove(card.id_no)
                player.property_mortgaged.append(card.id_no)
                card.status = 2

                # check rail,utility or color card
                if card.id_no in RAILS_CARDS:
                    player.total_rails_owned -= 1
                elif card.id_no in UTILITY_CARDS:
                    player.total_utilities_owned -= 1
                else:
                    del_color = []

                    # finding color group to which the card belongs

                    for color_cards in player.color_cards_owned:
                        if card.id_no in color_cards:
                            del_color = color_cards

                    if del_color != []:
                        player.color_cards_owned.remove(del_color)

            else:

                Mark = []

                player = Players[cur_player]

                for prop in player.property_owned:
                    Mark.append(prop)

                # display mortgage window

                if Mark != []:
                    # adding static part

                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen, Cards)

                    create_game_options(screen)

                    create_player_info(screen, Players, Cards, cur_player)

                    for player in Players:
                        player.move_player(screen, player.cur_position)

                    update_game_mortgage(screen, Players, Cards, cur_player,
                                         Cards_Rects, Option_Rects,
                                         Info_Cards_Rects, Mark)

        else:
            Mark = []

            player = Players[cur_player]

            for prop in player.property_owned:
                Mark.append(prop)

            # display mortgage window

            if Mark != []:
                # adding static part

                screen.fill(BACKGROUND_COLOR)

                create_board(screen, Cards)

                create_game_options(screen)

                create_player_info(screen, Players, Cards, cur_player)

                for player in Players:
                    player.move_player(screen, player.cur_position)

                update_game_mortgage(screen, Players, Cards, cur_player,
                                     Cards_Rects, Option_Rects,
                                     Info_Cards_Rects, Mark)
def update_game_sell(screen, Players, Cards, cur_player, Cards_Rects,
                     Option_Rects, Info_Cards_Rects, Mark):

    card_list = []
    flag = 0
    # removing cards with houses one less than the remaining houses in same color

    for color_cards in Players[cur_player].color_cards_owned:
        # color_cards = [1,3]
        for card in color_cards:
            card_list.append(Cards[card])
        # card_list(Card[1],Card[3])
        min_house_card = min(card_list, key=attrgetter('houses_built'))
        if min_house_card.houses_built == 4:  # hotel
            for crd in color_cards:
                if Cards[crd].hotel_built == 1:
                    flag = 1
            if flag == 1:  # hotel built on any card ; flag = 0 -> 4 houses on all cards
                for crd in color_cards:
                    if Cards[crd].hotel_built == 0:
                        if crd in Mark:
                            Mark.remove(crd)
        else:  # house
            for crd in color_cards:
                if Cards[crd].houses_built != min_house_card.houses_built:
                    flag = 1
            if flag == 1:  #extra house built on some card ; flag = 0 -> all card have 0 houses
                for crd in color_cards:
                    if Cards[crd].houses_built == min_house_card.houses_built:
                        if crd in Mark:
                            Mark.remove(crd)

    # get the card that was selected
    sell_card = display_sell_window(screen, Players, Cards, cur_player, Mark)

    # check if the card is valid
    # check the card against selling rules

    if sell_card != None:
        if sell_card in Mark:

            card = Cards[sell_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            # confirmation prompt
            # show sell infomation

            sell_prop = display_sell_confirm_window(screen, card)

            # update card status and player balance

            if sell_prop == True:

                player = Players[cur_player]
                # sell property action

                if card.hotel_built == 1:  # selling hotel

                    player.cur_balance += (card.hotel_cost // 2)
                    card.hotel_built = 0
                elif card.houses_built > 0:  # selling house

                    player.cur_balance += (card.house_cost // 2)
                    card.houses_built -= 1
                elif card.status == 2:  # mortgaged property

                    player.cur_balance -= card.mortgage_value
                    player.cur_balance += int(card.cost * 0.9)
                    card.status = 0
                    player.property_mortgaged.remove(card.id_no)
                else:  # owned property
                    player.cur_balance += int(card.cost * 0.9)
                    card.status = 0
                    player.property_owned.remove(card.id_no)

                    # check rail,utility or color card
                    if card.id_no in RAILS_CARDS:
                        player.total_rails_owned -= 1
                    elif card.id_no in UTILITY_CARDS:
                        player.total_utilities_owned -= 1
                    else:
                        del_color = []

                        # finding color group to which the card belongs

                        for color_cards in player.color_cards_owned:
                            if card.id_no in color_cards:
                                del_color = color_cards

                        if del_color != []:
                            player.color_cards_owned.remove(del_color)

            else:

                Mark = []

                player = Players[cur_player]

                for prop in player.property_owned:
                    Mark.append(prop)

                for prop in player.property_mortgaged:
                    Mark.append(prop)

                # display sell window

                if Mark != []:
                    # adding static part

                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen, Cards)

                    create_game_options(screen)

                    create_player_info(screen, Players, Cards, cur_player)

                    for player in Players:
                        player.move_player(screen, player.cur_position)

                    update_game_sell(screen, Players, Cards, cur_player,
                                     Cards_Rects, Option_Rects,
                                     Info_Cards_Rects, Mark)

        else:
            Mark = []

            player = Players[cur_player]

            for prop in player.property_owned:
                Mark.append(prop)

            for prop in player.property_mortgaged:
                Mark.append(prop)

            # display build window

            if Mark != []:
                # adding static part

                screen.fill(BACKGROUND_COLOR)

                create_board(screen, Cards)

                create_game_options(screen)

                create_player_info(screen, Players, Cards, cur_player)

                for player in Players:
                    player.move_player(screen, player.cur_position)

                update_game_sell(screen, Players, Cards, cur_player,
                                 Cards_Rects, Option_Rects, Info_Cards_Rects,
                                 Mark)
def update_game_build(screen, Players, Cards, cur_player, Cards_Rects,
                      Option_Rects, Info_Cards_Rects, Mark):

    card_list = []

    # removing card which have hotels built on them
    # removing cards which have greater no of houses than other cards of same color

    for color_cards in Players[cur_player].color_cards_owned:
        # color_cards = [1,3]
        for card in color_cards:
            card_list.append(Cards[card])
        # card_list(Card[1],Card[3])
        min_house_card = min(card_list, key=attrgetter('houses_built'))
        if min_house_card.houses_built == 4:  # hotel
            for crd in color_cards:
                if Cards[crd].hotel_built == 1:
                    if crd in Mark:
                        Mark.remove(crd)
        else:  # house
            for crd in color_cards:
                if Cards[crd].houses_built != min_house_card.houses_built:
                    if crd in Mark:
                        Mark.remove(crd)

    # get the card index that was clicked
    build_card = display_build_window(screen, Players, Cards, cur_player, Mark)

    # check if the card is valid
    # none implies user clicked cancel
    # check if card is in mark
    # check if card's house cost is less than player's balance

    if build_card != None:
        if build_card in Mark and Cards[build_card].house_cost <= Players[
                cur_player].cur_balance:

            card = Cards[build_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            # confirmation prompt
            # show build infomation

            build_prop = display_build_confirm_window(screen, card)

            # update card status and player balance

            if build_prop == True:

                player = Players[cur_player]

                # build hotel
                if card.houses_built == 4 and card.hotel_built == 0:
                    if player.cur_balance > card.hotel_cost:
                        player.cur_balance -= card.hotel_cost
                        card.hotel_built = 1
                    else:
                        player.cur_balance -= card.hotel_cost
                        card.hotel_built = 1
                        player.isBankrupt = True
                else:
                    if player.cur_balance > card.house_cost:
                        player.cur_balance -= card.house_cost
                        card.houses_built += 1
                    else:
                        player.cur_balance -= card.house_cost
                        card.hotel_built += 1
                        player.isBankrupt = True
            else:
                Mark = []

                player = Players[cur_player]

                for color_list in player.color_cards_owned:
                    Mark.extend(color_list)

                # display build window

                if Mark != []:
                    # adding static part

                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen, Cards)

                    create_game_options(screen)

                    create_player_info(screen, Players, Cards, cur_player)

                    for player in Players:
                        player.move_player(screen, player.cur_position)

                    update_game_build(screen, Players, Cards, cur_player,
                                      Cards_Rects, Option_Rects,
                                      Info_Cards_Rects, Mark)

        else:
            Mark = []

            player = Players[cur_player]

            for color_list in player.color_cards_owned:
                Mark.extend(color_list)

            # display build window

            if Mark != []:
                # adding static part

                screen.fill(BACKGROUND_COLOR)

                create_board(screen, Cards)

                create_game_options(screen)

                create_player_info(screen, Players, Cards, cur_player)

                for player in Players:
                    player.move_player(screen, player.cur_position)

                update_game_build(screen, Players, Cards, cur_player,
                                  Cards_Rects, Option_Rects, Info_Cards_Rects,
                                  Mark)
Exemplo n.º 26
0
def update_game_dice(screen, initial_card, final_card, no1, no2, Players,
                     Cards, cur_player):

    player = Players[cur_player]
    steps = no1 + no2

    # passed go
    # show go window

    if final_card < initial_card and not (initial_card == 7
                                          and final_card == 4):

        display_pass_go_window(screen)

        player.cur_balance += 200

        screen.fill(BACKGROUND_COLOR)

        create_board(screen, Cards)

        create_game_options(screen)

        create_player_info(screen, Players, Cards, cur_player)

        for temp in Players:
            temp.move_player(screen, temp.cur_position)

    # chance cards
    # display card information
    # execute card detail

    if final_card == 7 or final_card == 22 or final_card == 36:
        new_card = execute_chance(screen, final_card, Players, Cards,
                                  cur_player)
        if new_card != final_card:

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            create_player_info(screen, Players, Cards, cur_player)

            for player in Players:
                player.move_player(screen, player.cur_position)

            final_card = update_game_dice(screen, final_card, new_card, no1,
                                          no2, Players, Cards, cur_player)

    # community chest cards
    # display card information
    # execute card detail

    elif final_card == 2 or final_card == 17 or final_card == 33:
        new_card = execute_community(screen, final_card, Players, Cards,
                                     cur_player)
        if new_card != final_card:

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            create_player_info(screen, Players, Cards, cur_player)

            for player in Players:
                player.move_player(screen, player.cur_position)

            final_card = update_game_dice(screen, final_card, new_card, no1,
                                          no2, Players, Cards, cur_player)

    # jail or go to jail
    # go to jail - display go to jail window
    # allow player to use jail card if he has it
    # else pay $50 value

    elif final_card == 10 or final_card == 30:

        if final_card == 30:

            display_go_to_jail_window(screen)

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            create_player_info(screen, Players, Cards, cur_player)

            for player in Players:
                player.move_player(screen, player.cur_position)

        if player.jail_card == True:
            # if he wants to use jail card
            use_card = display_jail_card_window(screen)

            #does not uses the jail card hence pay fine pressed cancel

            if use_card == False:
                if player.cur_balance > 50:
                    player.cur_balance -= 50
                else:
                    player.cur_balance -= 50
                    player.isBankrupt = True
            else:
                player.jail_card = False
        else:
            display_jail_fine_window(screen)
            if player.cur_balance > 50:
                player.cur_balance -= 50
            else:
                player.cur_balance -= 50
                player.isBankrupt = True

        final_card = 10

    # income or luxury tax
    # display tax window
    # deduct $200 balance from his account

    elif final_card == 4 or final_card == 38:

        display_tax_pay_window(screen, final_card)

        if player.cur_balance > 200:
            player.cur_balance -= 200
        else:
            player.cur_balance -= 200
            player.isBankrupt = True

    # property cards

    elif final_card != 20 and final_card != 0:

        # check status
        # 0 - available 1 - bought 2 - mortgaged

        if Cards[final_card].status == 0:

            buy_prop = display_buy_property_window(screen, final_card, Players,
                                                   Cards, cur_player)

            # buys property
            # pay cost
            # update card status
            # update player property
            # if utility or railroad update count

            if buy_prop == True:
                player.cur_balance -= Cards[final_card].cost
                Cards[final_card].status = 1

                player.property_owned.append(final_card)
                if final_card == 12 or final_card == 28:
                    player.total_utilities_owned += 1
                elif final_card == 5 or final_card == 15 or final_card == 25 or final_card == 35:
                    player.total_rails_owned += 1
                else:
                    property_owned = set(player.property_owned)

                    if set(BROWN_CARDS).issubset(
                            property_owned
                    ) and BROWN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BROWN_CARDS)
                    if set(LIGHT_BLUE_CARDS).issubset(
                            property_owned
                    ) and LIGHT_BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(LIGHT_BLUE_CARDS)
                    if set(PINK_CARDS).issubset(
                            property_owned
                    ) and PINK_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(PINK_CARDS)
                    if set(ORANGE_CARDS).issubset(
                            property_owned
                    ) and ORANGE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(ORANGE_CARDS)
                    if set(RED_CARDS).issubset(
                            property_owned
                    ) and RED_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(RED_CARDS)
                    if set(YELLOW_CARDS).issubset(
                            property_owned
                    ) and YELLOW_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(YELLOW_CARDS)
                    if set(GREEN_CARDS).issubset(
                            property_owned
                    ) and GREEN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(GREEN_CARDS)
                    if set(BLUE_CARDS).issubset(
                            property_owned
                    ) and BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BLUE_CARDS)

        elif Cards[final_card].status == 1:

            prop_holder = None

            player = Players[cur_player]

            for temp in Players:
                if player != temp and final_card in temp.property_owned:
                    prop_holder = temp
                    break

            # none implies property is mortgaged

            if prop_holder != None:

                # railroads

                if final_card == 5 or final_card == 15 or final_card == 25 or final_card == 35:
                    rent = 25 * 2**(prop_holder.total_rails_owned - 1)

                # utilities

                elif final_card == 12 or final_card == 28:
                    rent = 4 * steps
                    if prop_holder.total_utilities_owned == 2:
                        rent = 10 * steps

                else:
                    rent = Cards[final_card].rent

                    if Cards[final_card].houses_built > 0:
                        rent = Cards[final_card].house_rent[
                            Cards[final_card].houses_built - 1]

                    if Cards[final_card].hotel_built > 0:
                        rent = Cards[final_card].hotel_rent

                display_rent_payment_window(screen, rent, player, prop_holder)

                if player.cur_balance > rent:
                    player.cur_balance -= rent
                else:
                    player.cur_balance -= rent
                    player.isBankrupt = True
                    Players[holder].cur_balance += rent

    return final_card
Exemplo n.º 27
0
def handle_trade(screen,Players,Cards,cur_player,Cards_Rects,Option_Rects,Info_Cards_Rects):

    # adding static part

    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    create_player_info(screen,Players,Cards,cur_player)

    for player in Players:
        player.move_player(screen,player.cur_position)

    other_player = display_select_trade_player_window(screen,Players,Cards,cur_player)

    # create current and other player cards available for trade

    if other_player != -1:

        create_board(screen,Cards)

        create_game_options(screen)

        create_player_info(screen,Players,Cards,cur_player)

        for player in Players:
            player.move_player(screen,player.cur_position)


        player = Players[cur_player]
        other = Players[other_player]

        Cur_Mark = []
        Cur_Other_Mark = []
        Other_Mark = []
        Other_Other_Mark = []
        
        Cur_Mark.extend(player.property_owned)
        
        Cur_Mark.extend(player.property_mortgaged)

        for prop in player.property_owned:
            if Cards[prop].houses_built > 0 or Cards[prop].hotel_built > 0:
                del_color = []           
                for color_cards in player.color_cards_owned:
                    if prop in color_cards:
                        del_color = color_cards
                if del_color != []:
                    for card in del_color:
                        Cur_Mark.remove(card)
                            
        for tmp in Players:
            if tmp != player:
                Cur_Other_Mark.extend(tmp.property_owned)
                Cur_Other_Mark.extend(tmp.property_mortgaged)


        Other_Mark.extend(other.property_owned)

        Other_Mark.extend(other.property_mortgaged)

        for prop in other.property_owned:
            if Cards[prop].houses_built > 0 or Cards[prop].hotel_built > 0:
                del_color = []            
                for color_cards in other.color_cards_owned:
                    if prop in color_cards:
                        del_color = color_cards
                if del_color != []:
                    for card in del_color:
                        Other_Mark.remove(card)

        for tmp in Players:
            if tmp != other:
                Other_Other_Mark.extend(tmp.property_owned)
                Other_Other_Mark.extend(tmp.property_mortgaged)


        if Cur_Mark != None or Other_Mark != None:
            update_game_trade(screen,Players,Cards,cur_player,other_player,Cards_Rects,Option_Rects,Info_Cards_Rects,Cur_Mark,Other_Mark,Cur_Other_Mark,Other_Other_Mark)
            


    # show the state after update


    screen.fill(BACKGROUND_COLOR)

    create_board(screen,Cards)

    create_game_options(screen)

    roll_dice(screen,4,2)
    
    for player in Players:
        player.move_player(screen,player.cur_position)

    create_player_info(screen,Players,Cards,cur_player)

    return cur_player
def update_game_dice(screen,initial_card,final_card,no1,no2,Players,Cards,cur_player):

    player = Players[cur_player]
    steps = no1 + no2

    # passed go
    # show go window

    

    if final_card < initial_card and not (initial_card == 7 and final_card == 4):
        
        display_pass_go_window(screen)
        
        player.cur_balance += 200

        screen.fill(BACKGROUND_COLOR)

        create_board(screen,Cards)

        create_game_options(screen)

        create_player_info(screen,Players,Cards,cur_player)

        for temp in Players:
            temp.move_player(screen,temp.cur_position)


    # chance cards
    # display card information
    # execute card detail

    if final_card == 7 or final_card == 22 or final_card == 36:
        new_card = execute_chance(screen,final_card,Players,Cards,cur_player)
        if new_card != final_card:
            
            screen.fill(BACKGROUND_COLOR)

            create_board(screen,Cards)

            create_game_options(screen)

            create_player_info(screen,Players,Cards,cur_player)

            for player in Players:
                player.move_player(screen,player.cur_position)


            final_card = update_game_dice(screen,final_card,new_card,no1,no2,Players,Cards,cur_player)
            

    # community chest cards
    # display card information
    # execute card detail
    
    elif final_card == 2 or final_card == 17 or final_card == 33:
        new_card = execute_community(screen,final_card,Players,Cards,cur_player)
        if new_card != final_card:
            
            screen.fill(BACKGROUND_COLOR)

            create_board(screen,Cards)

            create_game_options(screen)

            create_player_info(screen,Players,Cards,cur_player)

            for player in Players:
                player.move_player(screen,player.cur_position)


            final_card = update_game_dice(screen,final_card,new_card,no1,no2,Players,Cards,cur_player)

    # jail or go to jail
    # go to jail - display go to jail window
    # allow player to use jail card if he has it
    # else pay $50 value
    
    elif final_card == 10 or final_card == 30:

        if final_card == 30:

            display_go_to_jail_window(screen)

            screen.fill(BACKGROUND_COLOR)

            create_board(screen,Cards)

            create_game_options(screen)

            create_player_info(screen,Players,Cards,cur_player)

            for player in Players:
                player.move_player(screen,player.cur_position)

            

        if player.jail_card == True:
            # if he wants to use jail card
            use_card = display_jail_card_window(screen)

            #does not uses the jail card hence pay fine pressed cancel

            if use_card == False:
                if player.cur_balance > 50:
                    player.cur_balance -= 50
                else:
                    player.cur_balance -= 50
                    player.isBankrupt = True
            else:
                player.jail_card = False
        else:
            display_jail_fine_window(screen)
            if player.cur_balance > 50:
                player.cur_balance -= 50
            else:
                player.cur_balance -= 50
                player.isBankrupt = True
        
        final_card = 10

        

    # income or luxury tax
    # display tax window
    # deduct $200 balance from his account

    elif final_card == 4 or final_card == 38:

        display_tax_pay_window(screen,final_card)
        
        if player.cur_balance > 200:
            player.cur_balance -= 200
        else:
            player.cur_balance -= 200
            player.isBankrupt = True


    # property cards

    elif final_card != 20 and final_card != 0:


        # check status
        # 0 - available 1 - bought 2 - mortgaged
            

        if Cards[final_card].status == 0:
            
            buy_prop = display_buy_property_window(screen,final_card,Players,Cards,cur_player)

            # buys property
            # pay cost
            # update card status
            # update player property
            # if utility or railroad update count
            
            if buy_prop == True:
                player.cur_balance -= Cards[final_card].cost
                Cards[final_card].status = 1
                
                player.property_owned.append(final_card)
                if final_card == 12 or final_card == 28:
                    player.total_utilities_owned += 1
                elif final_card == 5 or final_card == 15 or final_card == 25 or final_card == 35:
                    player.total_rails_owned += 1
                else:
                    property_owned = set(player.property_owned)
                    
                    if set(BROWN_CARDS).issubset(property_owned) and BROWN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BROWN_CARDS)
                    if set(LIGHT_BLUE_CARDS).issubset(property_owned) and LIGHT_BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(LIGHT_BLUE_CARDS)
                    if set(PINK_CARDS).issubset(property_owned) and PINK_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(PINK_CARDS)
                    if set(ORANGE_CARDS).issubset(property_owned) and ORANGE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(ORANGE_CARDS)
                    if set(RED_CARDS).issubset(property_owned) and RED_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(RED_CARDS)
                    if set(YELLOW_CARDS).issubset(property_owned) and YELLOW_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(YELLOW_CARDS)
                    if set(GREEN_CARDS).issubset(property_owned) and GREEN_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(GREEN_CARDS)
                    if set(BLUE_CARDS).issubset(property_owned) and BLUE_CARDS not in player.color_cards_owned:
                        player.color_cards_owned.append(BLUE_CARDS)
                    

                        
                        
                    
                    
                
        elif Cards[final_card].status == 1:
            
            prop_holder = None

            player = Players[cur_player]

            for temp in Players:
                if player != temp and final_card in temp.property_owned:
                    prop_holder = temp
                    break

            # none implies property is mortgaged
            
            if prop_holder != None:

                # railroads

                if final_card == 5 or final_card == 15 or final_card == 25 or final_card == 35:
                    rent = 25 * 2**(prop_holder.total_rails_owned-1)

                # utilities

                elif final_card == 12 or final_card == 28:
                    rent = 4*steps
                    if prop_holder.total_utilities_owned == 2:
                        rent = 10*steps

                else:
                    rent = Cards[final_card].rent

                    if Cards[final_card].houses_built > 0:
                        rent = Cards[final_card].house_rent[Cards[final_card].houses_built-1]

                    if Cards[final_card].hotel_built > 0:
                        rent = Cards[final_card].hotel_rent
                    
                display_rent_payment_window(screen,rent,player,prop_holder)

                if player.cur_balance > rent:
                    player.cur_balance -= rent
                else:
                    player.cur_balance -= rent
                    player.isBankrupt = True
                    Players[holder].cur_balance += rent                    

                                   


    
        
    return final_card
    def run(self):
        pg.init()
        self.screen = pg.display.set_mode(SCREEN_RES)
        pg.display.set_caption('Sudoku solver')

        display = Display_board(self.screen)

        flag1 = 0
        val = 0

        board = create_board().board

        while 1:
            for event in pg.event.get():
                if event.type == pg.QUIT or (event.type == pg.KEYDOWN
                                             and event.key == pg.K_ESCAPE):
                    exit()
                if event.type == pg.MOUSEBUTTONDOWN:
                    flag1 = 1
                    pos = pg.mouse.get_pos()
                    get_cord(pos)
                    print(pos, box_index_x, box_index_y)
                if event.type == pg.KEYDOWN:
                    if event.key == pg.K_1:
                        val = 1
                    if event.key == pg.K_2:
                        val = 2
                    if event.key == pg.K_3:
                        val = 3
                    if event.key == pg.K_4:
                        val = 4
                    if event.key == pg.K_5:
                        val = 5
                    if event.key == pg.K_6:
                        val = 6
                    if event.key == pg.K_7:
                        val = 7
                    if event.key == pg.K_8:
                        val = 8
                    if event.key == pg.K_9:
                        val = 9

            if val != 0:
                display.draw_val(val, box_index_x, box_index_y, NUMBER_SIZE)

                if valid(board, int(box_index_x), int(box_index_y), val,
                         display):
                    board[int(box_index_x)][int(box_index_y)] = val
                else:
                    board[int(box_index_x)][int(box_index_y)] = 0
                    display.draw(board, BOLD)
                val = 0

            pg.draw.rect(
                self.screen, BLACK,
                (0, 0, self.screen.get_width(), self.screen.get_height()))
            self.screen.fill(BEIGE)

            display.draw(board, NUMBER_SIZE)
            # display.draw_box()

            pg.display.update()

        self.solution = solve_board(board)

        self.solution.assign_flags(board)
def handle_dice_roll(screen, Players, Cards, cur_player, Cards_Rects,
                     Option_Rects, Info_Cards_Rects):

    # adding static part

    screen.fill(BACKGROUND_COLOR)

    create_board(screen, Cards)

    create_game_options(screen)

    create_player_info(screen, Players, Cards, cur_player)

    # rolling dice

    no1, no2, a, b = roll_dice(screen)
    steps = int(no1) + int(no2)

    player = Players[cur_player]

    initial_card = get_rect_pressed_index(player.cur_position, Cards_Rects)
    final_card = (initial_card + steps) % 40

    # changing the current players' piece position

    final_pos = Cards[final_card].board_pos
    next_position = ()

    if player.color == "BLUE":
        next_position = (final_pos[0] + 19, final_pos[1] + 19)
    elif player.color == "RED":
        next_position = (final_pos[0] + 59, final_pos[1] + 19)
    elif player.color == "GREEN":
        next_position = (final_pos[0] + 19, final_pos[1] + 49)
    elif player.color == "YELLOW":
        next_position = (final_pos[0] + 59, final_pos[1] + 49)
    else:
        next_position = ()

    player.cur_position = next_position
    #player.move_player(screen,next_position)

    # updating the position of all players' piece on the board

    for temp in Players:
        temp.move_player(screen, temp.cur_position)

    # add the necessary actions to be taken due to dice roll
    final_card = update_game_dice(screen, initial_card, final_card, no1, no2,
                                  Players, Cards, cur_player)

    # changing the position if there is some related instruction in chance or community card

    final_pos = Cards[final_card].board_pos
    next_position = ()

    if player.color == "BLUE":
        next_position = (final_pos[0] + 19, final_pos[1] + 19)
    elif player.color == "RED":
        next_position = (final_pos[0] + 59, final_pos[1] + 19)
    elif player.color == "GREEN":
        next_position = (final_pos[0] + 19, final_pos[1] + 49)
    elif player.color == "YELLOW":
        next_position = (final_pos[0] + 59, final_pos[1] + 49)
    else:
        next_position = ()

    player.cur_position = next_position

    isBankrupt = False
    quit_player = False

    # check if user is bankrupt or not

    if Players[cur_player].cur_balance < 0:
        Players[cur_player].isBankrupt = True
        isBankrupt = True
    else:
        Players[cur_player].isBankrupt = False

    # run loop till player removes bankruptcy or declares himself as bankrupt

    while not quit_player and isBankrupt:

        # show the state after update

        screen.fill(BACKGROUND_COLOR)

        create_board(screen, Cards)

        create_game_options(screen)

        for player in Players:
            player.move_player(screen, player.cur_position)

        create_player_info(screen, Players, Cards, cur_player)

        quit_player = display_bankrupt_window(screen, Players, Cards,
                                              cur_player, Cards_Rects,
                                              Option_Rects, Info_Cards_Rects)

        if Players[cur_player].cur_balance < 0:
            Players[cur_player].isBankrupt = True
            isBankrupt = True
        else:
            Players[cur_player].isBankrupt = False
            isBankrupt = False

    # true implies player declares himself as bankrupt and withdraws from the game

    if quit_player == True:
        handle_quit_player(screen, Players, Cards, cur_player)

    # implies player has removed bankruptcy

    else:

        end_turn = False

        while not end_turn:

            # show the state after update

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            end_turn = display_end_turn_window(screen, Players, Cards,
                                               cur_player, Cards_Rects,
                                               Option_Rects, Info_Cards_Rects)

    # change turn to next player

    screen.fill(BACKGROUND_COLOR)

    create_board(screen, Cards)

    create_game_options(screen)

    roll_dice(screen, 4, 2)

    for player in Players:
        player.move_player(screen, player.cur_position)

    cur_player = (cur_player + 1) % len(Players)

    create_player_info(screen, Players, Cards, cur_player)

    return cur_player
Exemplo n.º 31
0
    def run(self):
        pg.init()
        self.screen = pg.display.set_mode(SCREEN_RES)
        pg.display.set_caption('Sudoku solver')

        display = Display_board(self.screen)

        flag1 = 0
        val = 0
        pos = (0, 0)

        input_lock = 0
        set_highlight((0, 0), (0, 0), (0, 0), 0)

        board = create_board().board

        while 1:
            for event in pg.event.get():
                if event.type == pg.QUIT or (event.type == pg.KEYDOWN
                                             and event.key == pg.K_ESCAPE):
                    exit()
                if event.type == pg.MOUSEBUTTONDOWN:
                    flag1 = 1
                    pos = pg.mouse.get_pos()
                    get_cord(pos)
                if event.type == pg.KEYDOWN and input_lock != 1:
                    if event.key == pg.K_1:
                        val = 1
                    if event.key == pg.K_2:
                        val = 2
                    if event.key == pg.K_3:
                        val = 3
                    if event.key == pg.K_4:
                        val = 4
                    if event.key == pg.K_5:
                        val = 5
                    if event.key == pg.K_6:
                        val = 6
                    if event.key == pg.K_7:
                        val = 7
                    if event.key == pg.K_8:
                        val = 8
                    if event.key == pg.K_9:
                        val = 9
                elif event.type == pg.KEYDOWN and input_lock == 1:
                    if event.key == pg.K_BACKSPACE:
                        val = 0
                        input_lock = 0
                        set_highlight((0, 0), (0, 0), (0, 0), 0)

            if val != 0:
                display.draw_val(val, box_index_x, box_index_y)

                if valid(board, int(box_index_x), int(box_index_y), val,
                         display):
                    board[int(box_index_x)][int(box_index_y)] = val
                else:
                    board[int(box_index_x)][int(box_index_y)] = 0
                val = 0

            pg.draw.rect(
                self.screen, BLACK,
                (0, 0, self.screen.get_width(), self.screen.get_height()))
            self.screen.fill(BEIGE)

            display.draw(board)
            display.glow(box_index_x, box_index_y)

            if input_lock == 1:
                display.update(board, row_index, col_index, blk_index)

            # display.draw_box()

            pg.display.update()

        self.solution = solve_board(board)

        self.solution.assign_flags(board)
def update_game_build(screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects, Mark):

    card_list = []

    # removing card which have hotels built on them
    # removing cards which have greater no of houses than other cards of same color

    for color_cards in Players[cur_player].color_cards_owned:
        # color_cards = [1,3]
        for card in color_cards:
            card_list.append(Cards[card])
        # card_list(Card[1],Card[3])
        min_house_card = min(card_list, key=attrgetter("houses_built"))
        if min_house_card.houses_built == 4:  # hotel
            for crd in color_cards:
                if Cards[crd].hotel_built == 1:
                    if crd in Mark:
                        Mark.remove(crd)
        else:  # house
            for crd in color_cards:
                if Cards[crd].houses_built != min_house_card.houses_built:
                    if crd in Mark:
                        Mark.remove(crd)

    # get the card index that was clicked
    build_card = display_build_window(screen, Players, Cards, cur_player, Mark)

    # check if the card is valid
    # none implies user clicked cancel
    # check if card is in mark
    # check if card's house cost is less than player's balance

    if build_card != None:
        if build_card in Mark and Cards[build_card].house_cost <= Players[cur_player].cur_balance:

            card = Cards[build_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            # confirmation prompt
            # show build infomation

            build_prop = display_build_confirm_window(screen, card)

            # update card status and player balance

            if build_prop == True:

                player = Players[cur_player]

                # build hotel
                if card.houses_built == 4 and card.hotel_built == 0:
                    if player.cur_balance > card.hotel_cost:
                        player.cur_balance -= card.hotel_cost
                        card.hotel_built = 1
                    else:
                        player.cur_balance -= card.hotel_cost
                        card.hotel_built = 1
                        player.isBankrupt = True
                else:
                    if player.cur_balance > card.house_cost:
                        player.cur_balance -= card.house_cost
                        card.houses_built += 1
                    else:
                        player.cur_balance -= card.house_cost
                        card.hotel_built += 1
                        player.isBankrupt = True
            else:
                Mark = []

                player = Players[cur_player]

                for color_list in player.color_cards_owned:
                    Mark.extend(color_list)

                # display build window

                if Mark != []:
                    # adding static part

                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen, Cards)

                    create_game_options(screen)

                    create_player_info(screen, Players, Cards, cur_player)

                    for player in Players:
                        player.move_player(screen, player.cur_position)

                    update_game_build(
                        screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects, Mark
                    )

        else:
            Mark = []

            player = Players[cur_player]

            for color_list in player.color_cards_owned:
                Mark.extend(color_list)

            # display build window

            if Mark != []:
                # adding static part

                screen.fill(BACKGROUND_COLOR)

                create_board(screen, Cards)

                create_game_options(screen)

                create_player_info(screen, Players, Cards, cur_player)

                for player in Players:
                    player.move_player(screen, player.cur_position)

                update_game_build(screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects, Mark)
Exemplo n.º 33
0
def process_third_level(dutifulness, inventory, log):
    """Handle game's first level game."""
    os.system("clear")
    x_hero = 1
    y_hero = 1
    board = create_board('city.csv')
    previous_sign = board[y_hero][x_hero]
    log = "This city is mad! \nI need to find a way to the police station..."

    obstacles = ["▓", "▆", "⛔", "@", "⟧"]
    gate = "⛔"
    friend = "@"
    greenery = "☘"
    gate_key = "gate key"
    police_station_door = "⟧"
    greenery = "☘"

    input_key = getch()  #control

    while dutifulness != 0:
        x_diff = 0
        y_diff = 0

        input_key = getch()
        x_diff, y_diff = control_position(input_key)
        board[y_hero][x_hero] = previous_sign

        if is_move_possible(y_hero + y_diff, x_hero + x_diff, obstacles,
                            board):
            y_hero, x_hero = move_by(y_hero, x_hero, y_diff, x_diff)

        if is_taking_item(board[y_hero + y_diff][x_hero + x_diff], friend,
                          gate_key, inventory):
            add_to_inventory(inventory, gate_key)
            log = "Now I can enter the gate!"

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], greenery):
            dutifulness = subtract_dutifulness(dutifulness)

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], gate):
            if is_item_in_inventory(gate_key, inventory):
                board[y_hero + y_diff][x_hero + x_diff] = " "
                log = "Ok, let's go to police station!"
            else:
                log = "I need to find Michael to borrow a key from him."

        if is_touching(board[y_hero + y_diff][x_hero + x_diff],
                       police_station_door):
            dutifulness = riddle(dutifulness, "3")
            return dutifulness, inventory, log

        if input_key == "q":
            sys.exit()

        previous_sign = board[y_hero][x_hero]
        print_board_and_insert_player(board, y_hero, x_hero, inventory,
                                      dutifulness, log)

    if dutifulness == 0:
        os.system("clear")
        print_screen("loose.csv")
        sys.exit()
def update_game_trade(screen, Players, Cards, cur_player, other_player,
                      Cards_Rects, Option_Rects, Info_Cards_Rects, Cur_Mark,
                      Other_Mark, Cur_Other_Mark, Other_Other_Mark):

    send_amount = 0
    receive_amount = 0
    send_property = set()
    receive_property = set()

    offer, send_amount, send_property, receive_amount, receive_property = display_trade_window(
        screen, Players, Cards, cur_player, other_player, Cur_Mark, Other_Mark,
        Cur_Other_Mark, Other_Other_Mark, send_amount, receive_amount,
        send_property, receive_property)

    if offer == True:

        if (send_property != set() or receive_property != set()) and (
                send_property.issubset(set(Cur_Mark))
                and receive_property.issubset(set(Other_Mark))):

            Send_Cards = []
            Receive_Cards = []

            for send_index in send_property:
                Send_Cards.append(Cards[send_index])

            for receive_index in receive_property:
                Receive_Cards.append(Cards[receive_index])

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            # confirmation prompt
            # show trade infomation

            trade_prop = display_trade_confirm_window(screen, Send_Cards,
                                                      send_amount,
                                                      Receive_Cards,
                                                      receive_amount)

            if trade_prop == True:

                player = Players[cur_player]
                other = Players[other_player]

                # trade property action

                if send_amount > 0:
                    other.cur_balance += send_amount
                    player.cur_balance -= send_amount

                if receive_amount > 0:
                    other.cur_balance -= receive_amount
                    player.cur_balance += receive_amount

                if send_property != set():
                    send_property = list(send_property)

                    for send_index in send_property:

                        if Cards[send_index].status == 1:
                            player.property_owned.remove(send_index)
                            other.property_owned.append(send_index)
                        elif Cards[send_index].status == 2:
                            player.property_mortgaged.remove(send_index)
                            other.property_mortgaged.append(send_index)

                        if send_index in RAILS_CARDS:
                            player.total_rails_owned -= 1
                            other.total_rails_owned += 1
                        elif send_index in UTILITY_CARDS:
                            player.total_utilities_owned -= 1
                            other.total_utilities_owned += 1
                        else:

                            del_color = []

                            for color_cards in player.color_cards_owned:
                                if send_index in color_cards:
                                    del_color = color_cards

                            if del_color != []:
                                player.color_cards_owned.remove(del_color)

                            property_owned = set(other.property_owned)

                            if set(BROWN_CARDS).issubset(
                                    property_owned
                            ) and BROWN_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(BROWN_CARDS)
                            if set(LIGHT_BLUE_CARDS).issubset(
                                    property_owned
                            ) and LIGHT_BLUE_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(
                                    LIGHT_BLUE_CARDS)
                            if set(PINK_CARDS).issubset(
                                    property_owned
                            ) and PINK_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(PINK_CARDS)
                            if set(ORANGE_CARDS).issubset(
                                    property_owned
                            ) and ORANGE_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(ORANGE_CARDS)
                            if set(RED_CARDS).issubset(
                                    property_owned
                            ) and RED_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(RED_CARDS)
                            if set(YELLOW_CARDS).issubset(
                                    property_owned
                            ) and YELLOW_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(YELLOW_CARDS)
                            if set(GREEN_CARDS).issubset(
                                    property_owned
                            ) and GREEN_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(GREEN_CARDS)
                            if set(BLUE_CARDS).issubset(
                                    property_owned
                            ) and BLUE_CARDS not in other.color_cards_owned:
                                other.color_cards_owned.append(BLUE_CARDS)

                if receive_property != set():
                    receive_property = list(receive_property)

                    for receive_index in receive_property:

                        if Cards[receive_index].status == 1:
                            other.property_owned.remove(receive_index)
                            player.property_owned.append(receive_index)
                        elif Cards[receive_index].status == 2:
                            other.property_mortgaged.remove(receive_index)
                            player.property_mortgaged.append(receive_index)

                        if receive_index in RAILS_CARDS:
                            other.total_rails_owned -= 1
                            player.total_rails_owned += 1
                        elif receive_index in UTILITY_CARDS:
                            other.total_utilities_owned -= 1
                            player.total_utilities_owned += 1
                        else:

                            del_color = []

                            for color_cards in other.color_cards_owned:
                                if receive_index in color_cards:
                                    del_color = color_cards

                            if del_color != []:
                                other.color_cards_owned.remove(del_color)

                            property_owned = set(player.property_owned)

                            if set(BROWN_CARDS).issubset(
                                    property_owned
                            ) and BROWN_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(BROWN_CARDS)
                            if set(LIGHT_BLUE_CARDS).issubset(
                                    property_owned
                            ) and LIGHT_BLUE_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(
                                    LIGHT_BLUE_CARDS)
                            if set(PINK_CARDS).issubset(
                                    property_owned
                            ) and PINK_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(PINK_CARDS)
                            if set(ORANGE_CARDS).issubset(
                                    property_owned
                            ) and ORANGE_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(ORANGE_CARDS)
                            if set(RED_CARDS).issubset(
                                    property_owned
                            ) and RED_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(RED_CARDS)
                            if set(YELLOW_CARDS).issubset(
                                    property_owned
                            ) and YELLOW_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(YELLOW_CARDS)
                            if set(GREEN_CARDS).issubset(
                                    property_owned
                            ) and GREEN_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(GREEN_CARDS)
                            if set(BLUE_CARDS).issubset(
                                    property_owned
                            ) and BLUE_CARDS not in player.color_cards_owned:
                                player.color_cards_owned.append(BLUE_CARDS)

            else:

                player = Players[cur_player]
                other = Players[other_player]

                Cur_Mark = []
                Other_Mark = []

                for prop in player.property_owned:
                    Cur_Mark.append(prop)

                for prop in player.property_mortgaged:
                    Cur_Mark.append(prop)

                for prop in other.property_owned:
                    Other_Mark.append(prop)

                for prop in other.property_mortgaged:
                    Other_Mark.append(prop)

                if Cur_Mark != None or Other_Mark != None:
                    # adding static part

                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen, Cards)

                    create_game_options(screen)

                    for player in Players:
                        player.move_player(screen, player.cur_position)

                    create_player_info(screen, Players, Cards, cur_player)

                    update_game_trade(screen, Players, Cards, cur_player,
                                      other_player, Cards_Rects, Option_Rects,
                                      Info_Cards_Rects, Cur_Mark, Other_Mark)

        else:

            player = Players[cur_player]
            other = Players[other_player]

            Cur_Mark = []
            Other_Mark = []

            for prop in player.property_owned:
                Cur_Mark.append(prop)

            for prop in player.property_mortgaged:
                Cur_Mark.append(prop)

            for prop in other.property_owned:
                Other_Mark.append(prop)

            for prop in other.property_mortgaged:
                Other_Mark.append(prop)

            if Cur_Mark != None or Other_Mark != None:
                # adding static part

                screen.fill(BACKGROUND_COLOR)

                create_board(screen, Cards)

                create_game_options(screen)

                for player in Players:
                    player.move_player(screen, player.cur_position)

                create_player_info(screen, Players, Cards, cur_player)

                update_game_trade(screen, Players, Cards, cur_player,
                                  other_player, Cards_Rects, Option_Rects,
                                  Info_Cards_Rects, Cur_Mark, Other_Mark)
Exemplo n.º 35
0
def process_first_level(dutifulness, inventory, log):
    """Handle game's first level game."""
    x_hero = 1
    y_hero = 1
    lives = 3
    log = "Hmm... I'm on the crime scene. \nI need to collect the evidence."
    board = create_board('home.csv')
    previous_sign = board[y_hero][x_hero]

    obstacles = ["⟧", "▆", "▓", "ߛ", "☎", "Ր", "♨", "இ", "☘", "□", "▯"]
    table_symbol = "▆"
    door = "⟧"
    box = "ߛ"
    blood = "~"
    answerphone = "□"
    front_door = "▯"
    record = "record"
    note = "note"
    door_key = "door key"

    input_key = getch()  #control

    while dutifulness != 0:
        x_diff = 0
        y_diff = 0

        input_key = getch()
        x_diff, y_diff = control_position(input_key)
        board[y_hero][x_hero] = previous_sign

        if is_move_possible(y_hero + y_diff, x_hero + x_diff, obstacles,
                            board):
            y_hero, x_hero = move_by(y_hero, x_hero, y_diff, x_diff)

        if is_taking_item(board[y_hero + y_diff][x_hero + x_diff], box,
                          door_key, inventory):
            add_to_inventory(inventory, door_key)
            log = "Now I can open the door!"

        if is_taking_item(board[y_hero + y_diff][x_hero + x_diff],
                          table_symbol, note, inventory):
            add_to_inventory(inventory, note)
            log = "Note: +48500 000 000 - Michael Brown \nI hear an answering machine from another room..."

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], blood):
            dutifulness = subtract_dutifulness(dutifulness)

        if is_taking_item(board[y_hero + y_diff][x_hero + x_diff], answerphone,
                          record, inventory):
            add_to_inventory(inventory, record)
            log = "Record: Come join us on get-together at my cabin in Nashville!"

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], door):
            if is_item_in_inventory(door_key, inventory):
                board[y_hero + y_diff][x_hero + x_diff] = " "
                log = "There is something lying on the table..."
            else:
                log = "I need to find a key!"

        if is_touching(board[y_hero + y_diff][x_hero + x_diff], front_door):
            if are_items_in_inventory(note, record, inventory):
                dutifulness = riddle(dutifulness, "1")
                return dutifulness, inventory, log

        if input_key == "q":
            sys.exit()

        previous_sign = board[y_hero][x_hero]
        print_board_and_insert_player(board, y_hero, x_hero, inventory,
                                      dutifulness, log)

    if dutifulness == 0:
        os.system("clear")
        print_screen("loose.csv")
        sys.exit()
def update_game_sell(screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects, Mark):

    card_list = []
    flag = 0
    # removing cards with houses one less than the remaining houses in same color

    for color_cards in Players[cur_player].color_cards_owned:
        # color_cards = [1,3]
        for card in color_cards:
            card_list.append(Cards[card])
        # card_list(Card[1],Card[3])
        min_house_card = min(card_list, key=attrgetter("houses_built"))
        if min_house_card.houses_built == 4:  # hotel
            for crd in color_cards:
                if Cards[crd].hotel_built == 1:
                    flag = 1
            if flag == 1:  # hotel built on any card ; flag = 0 -> 4 houses on all cards
                for crd in color_cards:
                    if Cards[crd].hotel_built == 0:
                        if crd in Mark:
                            Mark.remove(crd)
        else:  # house
            for crd in color_cards:
                if Cards[crd].houses_built != min_house_card.houses_built:
                    flag = 1
            if flag == 1:  # extra house built on some card ; flag = 0 -> all card have 0 houses
                for crd in color_cards:
                    if Cards[crd].houses_built == min_house_card.houses_built:
                        if crd in Mark:
                            Mark.remove(crd)

    # get the card that was selected
    sell_card = display_sell_window(screen, Players, Cards, cur_player, Mark)

    # check if the card is valid
    # check the card against selling rules

    if sell_card != None:
        if sell_card in Mark:

            card = Cards[sell_card]

            screen.fill(BACKGROUND_COLOR)

            create_board(screen, Cards)

            create_game_options(screen)

            for player in Players:
                player.move_player(screen, player.cur_position)

            create_player_info(screen, Players, Cards, cur_player)

            # confirmation prompt
            # show sell infomation

            sell_prop = display_sell_confirm_window(screen, card)

            # update card status and player balance

            if sell_prop == True:

                player = Players[cur_player]
                # sell property action

                if card.hotel_built == 1:  # selling hotel

                    player.cur_balance += card.hotel_cost // 2
                    card.hotel_built = 0
                elif card.houses_built > 0:  # selling house

                    player.cur_balance += card.house_cost // 2
                    card.houses_built -= 1
                elif card.status == 2:  # mortgaged property

                    player.cur_balance -= card.mortgage_value
                    player.cur_balance += int(card.cost * 0.9)
                    card.status = 0
                    player.property_mortgaged.remove(card.id_no)
                else:  # owned property
                    player.cur_balance += int(card.cost * 0.9)
                    card.status = 0
                    player.property_owned.remove(card.id_no)

                    # check rail,utility or color card
                    if card.id_no in RAILS_CARDS:
                        player.total_rails_owned -= 1
                    elif card.id_no in UTILITY_CARDS:
                        player.total_utilities_owned -= 1
                    else:
                        del_color = []

                        # finding color group to which the card belongs

                        for color_cards in player.color_cards_owned:
                            if card.id_no in color_cards:
                                del_color = color_cards

                        if del_color != []:
                            player.color_cards_owned.remove(del_color)

            else:

                Mark = []

                player = Players[cur_player]

                for prop in player.property_owned:
                    Mark.append(prop)

                for prop in player.property_mortgaged:
                    Mark.append(prop)

                # display sell window

                if Mark != []:
                    # adding static part

                    screen.fill(BACKGROUND_COLOR)

                    create_board(screen, Cards)

                    create_game_options(screen)

                    create_player_info(screen, Players, Cards, cur_player)

                    for player in Players:
                        player.move_player(screen, player.cur_position)

                    update_game_sell(
                        screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects, Mark
                    )

        else:
            Mark = []

            player = Players[cur_player]

            for prop in player.property_owned:
                Mark.append(prop)

            for prop in player.property_mortgaged:
                Mark.append(prop)

            # display build window

            if Mark != []:
                # adding static part

                screen.fill(BACKGROUND_COLOR)

                create_board(screen, Cards)

                create_game_options(screen)

                create_player_info(screen, Players, Cards, cur_player)

                for player in Players:
                    player.move_player(screen, player.cur_position)

                update_game_sell(screen, Players, Cards, cur_player, Cards_Rects, Option_Rects, Info_Cards_Rects, Mark)