Beispiel #1
0
def accept_negocjacje(mouse_pos, c):
    global flaga
    if flaga == 5:
        if rules.button_clicked(mouse_pos, c.akceptuj_rect):
            data = {
                "function": "change_owners",
                "game_name": c.game_name,
                "player": c.player.name,
                "nr_oferty": c.nr_oferty
            }
            confirm = c.network.send(data)

            update_negocjacje(c)
        elif rules.button_clicked(mouse_pos, c.odrzuc_rect):
            update_negocjacje(c)
Beispiel #2
0
def show_status(mouse_pos, c):
    x, y = mouse_pos
    global flaga
    if x >= c.player_tab[0] and x <= (c.player_tab[0] + c.player_tab[2]
                                      ) and y >= c.player_tab[1] and y <= (
                                          c.player_tab[1] + c.player_tab[3]):
        flaga = 1
    elif x >= c.negotiations_tab[0] and x <= (
            c.negotiations_tab[0] +
            c.negotiations_tab[2]) and y >= c.negotiations_tab[1] and y <= (
                c.negotiations_tab[1] + c.negotiations_tab[3]):
        flaga = 2
    elif x >= c.buy_tab[0] and x <= (
            c.buy_tab[0] + c.buy_tab[2]) and y >= c.buy_tab[1] and y <= (
                c.buy_tab[1] + c.buy_tab[3]):
        flaga = 3
    elif rules.button_clicked(mouse_pos, c.wyswietl_otrzymane_oferty_rect):
        flaga = 4
        c.oferty_rect = []
        for i in range(len(c.player.oferty)):
            #sa to prostokaty, ktore wykorzystamy do wyswietlania ofert
            c.oferty_rect.append(
                (c.right_square[0], c.right_square[1] + (i + 1) * c.block_size,
                 c.win_width - c.right_square[0], c.block_size))

    if show_oferta(mouse_pos, c):
        flaga = 5
Beispiel #3
0
def accept_offer(mouse_pos, c):
    #print("wchodze do accept_offer: juz_sprawdzone: ", c.player.juz_sprawdzone)
    #global juz_sprawdzone
    global flaga

    if flaga == 3 and c.player.interested:
        x, y = mouse_pos
        czy_do_kupienia = check_belongs(c.n[c.player.pos], c.player)
        #tak_rect = (c.right_square[0] + 2*c.block_size, 2*c.block_size)
        #nie_rect = (c.right_square[0] + 4*c.block_size, 2*c.block_size)
        #if x >= c.tak_rect[0] and x <= (c.tak_rect[0] + 100) and y >= c.tak_rect[1] and y <= (c.tak_rect[1] + 50):
        if rules.button_clicked(mouse_pos, c.tak_rect):
            #print("functionality2-accept_offer- tekst powinien zniknac")
            print("functionality2-accept_offer-akceptuj")

            #player.interested = False
            c.player.juz_sprawdzone = True
            c.player.money -= c.n[c.player.pos].value
            print("c.player.interested: ", c.player.interested,
                  ", c.player.juz_sprawdzone: ", c.player.juz_sprawdzone,
                  ", check_belongs: ", czy_do_kupienia)
            #c.n[c.player.pos].belongs = c.player.name
            data = {
                "function": "update_nieruchomosci",
                "game_name": c.game_name,
                "nieruchomosc": c.player.pos,  #nr nieruchomosci
                "gracz": c.player.name,
                "domki": 0
            }
            c.network.send(data)

            spend_money(c)
            #juz_sprawdzone = True

        #elif x >= nie_rect[0] and x <= (nie_rect[0] + 100) and y >= nie_rect[1] and y <= (nie_rect[1] + 50):
        elif rules.button_clicked(mouse_pos, c.nie_rect):
            c.player.juz_sprawdzone = True
            print("functionality2-accept_offer-odrzuc")
            czy_do_kupienia = check_belongs(c.n[c.player.pos], c.player)
            print("c.player.interested: ", c.player.interested,
                  ", c.player.juz_sprawdzone: ", c.player.juz_sprawdzone,
                  ", check_belongs: ", czy_do_kupienia)
Beispiel #4
0
def show_oferta(mouse_pos, c):
    global flaga
    if flaga == 4:
        nr_oferty = [
            index for index, elem in enumerate(c.player.oferty)
            if rules.button_clicked(mouse_pos, c.oferty_rect[index])
        ]
        print("show_oferta: nr oferty to: ", nr_oferty)
        if len(nr_oferty) != 0:
            c.nr_oferty = nr_oferty[0]
            return True

    return False
Beispiel #5
0
def negocjuj(mouse_pos, c):
    global flaga
    if flaga == 2:
        for i in range(len(c.n)):
            rect = (c.n[i].x, c.n[i].y, c.block_size, c.block_size)
            czy_dodac = rules.button_clicked(mouse_pos, rect)
            if czy_dodac:
                if c.n[i].belongs == c.player.name:
                    if c.n[i] not in c.lista_sprzedazy:
                        c.lista_sprzedazy.append(c.n[i])
                    else:
                        c.lista_sprzedazy = [
                            premise for premise in c.lista_sprzedazy
                            if premise != c.n[i]
                        ]

                elif negocjacje_check_belongs(c.n[i], c.player):
                    if c.n[i] not in c.lista_zakupow:
                        if c.lista_zakupow == []:
                            c.lista_zakupow.append(c.n[i])
                        else:
                            if c.lista_zakupow[0].belongs == c.n[i].belongs:
                                c.lista_zakupow.append(c.n[i])
                    else:
                        c.lista_zakupow = [
                            premise for premise in c.lista_zakupow
                            if premise != c.n[i]
                        ]

        czy_wyslij = rules.button_clicked(mouse_pos, c.wyslij_oferte_rect)
        if czy_wyslij:
            #zaimplementuj wyslanie oferty przez serwer do danego gracza
            sprzedaz = []
            kupno = []
            for i in range(len(c.lista_sprzedazy)):
                item = c.lista_sprzedazy[i].name
                sprzedaz.append(item)

            for i in range(len(c.lista_zakupow)):
                item = c.lista_zakupow[i].name
                kupno.append(item)

            if len(c.lista_zakupow) > 0:
                data = {
                    "function": "przeslij_oferte",
                    "game_name": c.game_name,
                    "kupno": kupno,  #lista obiektow ktore zamierzamy kupic
                    "sprzedaz":
                    sprzedaz,  #lista obiektow ktore zamierzamy sprzedac
                    "negocjowana_kwota": c.
                    negocjowana_kwota,  #dodatkowa kwota jaka chcielibysmy doplacic
                    "oferujacy": c.player.name,  #kto oferuje
                    "do_kogo": c.lista_zakupow[0].
                    belongs  #dla kogo jest przeznaczona oferta
                }

                zwrot = c.network.send(data)
                print(zwrot)

                c.lista_sprzedazy = []
                c.lista_zakupow = []
                c.negocjowana_kwota = ""
Beispiel #6
0
def manage_draw_window(mouse_pos, c):
    #central_square = (s.block_size+2, s.block_size+2, 9*s.block_size-3, 9*s.block_size-3)
    #font = pygame.font.SysFont("comicsans", 60)
    font = c.font
    mouse_x, mouse_y = mouse_pos
    #field = None

    #zaktualizuj pola: kto je posiada, ile maja domkow
    data = {
        "function":"get_nieruchomosci",
        "game_name":c.game_name
    }
    nieruchomosci = c.network.send(data)

    for i in range(len(c.n)):
        c.n[i].belongs = nieruchomosci[i][0]
        c.n[i].domki = nieruchomosci[i][1]

    previous_field = c.rendered_field
    next_field = None
    for i in range(len(s.n)):
        if (mouse_x >= s.n[i].x and mouse_x <= s.n[i].x + s.block_size) and (mouse_y >= s.n[i].y and mouse_y <= s.n[i].y + s.block_size):
            next_field = s.n[i]
            break

    #jesli gracz nacisnie na inne pole, pokaza sie informacje na jego temat; jesli kliknal na to
    #samo pole lub nie kliknal na zadne pole w ogole, informacje o dotychczasowym polu znikna
    if next_field is None or previous_field == next_field:
        c.rendered_field = None
    else:
        c.rendered_field = next_field

    #jesli gracz kliknie mysza wewnatrz planszy, to nie chcemy zamykac okna z nieruchomoscia
    #po to, by gracz mogl wykonac ewentualny zakup domkow, zastawienie itp.
    czy_wewnatrz_planszy = button_clicked(mouse_pos, c.central_square)
    if czy_wewnatrz_planszy:
        c.rendered_field = previous_field

    c.czy_domki = sprawdz_domki(c.rendered_field, c)

    if czy_wewnatrz_planszy and previous_field is not None and c.player.interested:
        czy_kup_domek = button_clicked(mouse_pos, c.kup_domek_rect)
        czy_sprzedaj_domek = button_clicked(mouse_pos, c.sprzedaj_domek_rect)
        czy_zastaw = button_clicked(mouse_pos, c.zastaw_rect)

        if czy_kup_domek:
            kup_domek(c)
            #print("manage_draw_window: mickiewicza nr: ", c.n[21].name)
            #print("manage_draw_window: mickiewicza domki: ", c.n[21].domki)
        if czy_sprzedaj_domek:
            sprzedaj_domek(c)
        if czy_zastaw:
            zastaw(c)

        data = {
            "function":"spend_money",
            "game_name":c.game_name,
            "player":c.player.name,
            "money":c.player.money
            }

        c.player.money = c.network.send(data)