Exemple #1
0
 def player_move(self, _player: player.Player):
     dice1, dice2 = self.roll_dice()  # roll the dice
     print(dice1, dice2)
     current_region = self.__region_list[_player.move(dice1, dice2)]  # player current region
     assert isinstance(current_region, region.Region)  # check if current_region is Region class
     _type = current_region.get_buy_type(_player.get_id())  # with vaues in constant.py, set purchase type
     # checking desert.
     if current_region.is_desert() and not _player.check_desert():
         _player.set_stop()
         messagebox.showerror("Desert", "You are in desert!")
     # pay toll when region is owned by other player.
     if _player.get_id() != current_region.get_owner_id() and current_region.get_owner_id() is not None:
         _toll = current_region.get_toll()
         _player.pay_money(_toll, current_region.get_owner())
         print("%s gave $%d money to %s"
               % (_player.get_player_name(), _toll, current_region.get_owner().get_player_name()))
     # get the price of region.
     current_region_price = current_region.get_sales_price(_player.get_id())
     # when player has enough money, then ask whether buy the region or not
     if _player.get_current_money() >= current_region_price and current_region.can_buy():
         want_to_buy = messagebox.askyesno("Buy", constant.ASK_BUY_MESSAGE[_type] % current_region_price)
         if want_to_buy:
                 current_region.buy(_player)
     # checking dice is double or not.
     if dice1 != dice2:
         self.__current_player_no = (self.__current_player_no + 1) % constant.PLAYER_NO
     else:
         messagebox.showinfo("Double", "Your dices ar Double!")
     return dice1, dice2
Exemple #2
0
    def buy(self, _player: player.Player):
        # 사막 여부 판단
        if self.is_desert():
            return False
        sales_price = self.get_sales_price(_player.get_id())  # 판매 금액 얻기.
        if self.__owner is None: # 밑에 owner.get id != player.get id에서 owner가 None인 경우 애러가 나서 수정했습니다.
            is_success = _player.pay_money(sales_price)
        elif self.__owner.get_id() != _player.get_id():  # 소유자가 다른 경우에는 지역을 구매하는데 든 돈을 이전 소유자에게 지불.
            is_success = _player.pay_money(sales_price, self.__owner)
        else:  # 소유자가 없거나 혹은 소유자가 같은 경우에는 단순히 돈만 감소시킨다.
            is_success = _player.pay_money(sales_price)

        if is_success:  # 구매가 성공한 경우
            self.__change_owner(_player)  # 소유자 변경
            self.__current_price = sales_price  # 현재 금액 업데이트
        return is_success
Exemple #3
0
    def test_player_move(self, _player: player.Player, dice1: int, dice2: int):
        current_region = self.__region_list[_player.move(dice1, dice2)]  # 현재 _player 가 있는 지역
        assert isinstance(current_region, region.Region)  # 적절한 값인지 체크
        _type = current_region.get_buy_type(_player.get_id())  # 구매 타입을 정한다. constant.py 에 있는 내용 참조.
        if current_region.is_desert() and not _player.check_desert():
            _player.set_stop()
        # 통행료 지급하는 부분
        if _player.get_id() != current_region.get_owner_id() and current_region.get_owner_id() is not None:
            _toll = current_region.get_toll()
            _player.pay_money(_toll, current_region.get_owner())
            print("%s gave $%d money to %s" % (_player.get_player_name(), _toll, current_region.get_owner().get_player_name()))

        # 지역 구매 여부 묻기
        current_region_price = current_region.get_sales_price(_player.get_id())
        if _player.get_current_money() >= current_region_price:
            ask = input(constant.ASK_BUY_MESSAGE[_type] % current_region_price)
            if ask is 'Y':
                    current_region.buy(_player)
            elif ask is 'N':
                pass
Exemple #4
0
 def player_move(self, _player: player.Player):
     dice1, dice2 = self.roll_dice()  # 주사위를 던진다.
     print(dice1, dice2)
     current_region = self.__region_list[_player.move(dice1, dice2)]  # 현재 _player 가 있는 지역
     assert isinstance(current_region, region.Region)  # 적절한 값인지 체크
     _type = current_region.get_buy_type(_player.get_id())  # 구매 타입을 정한다. constant.py 에 있는 내용 참조.
     if current_region.is_desert() and not _player.check_desert():
         _player.set_stop()
     # 통행료 지급하는 부분
     if _player.get_id() != current_region.get_owner_id() and current_region.get_owner_id() is not None:
         _toll = current_region.get_toll()
         _player.pay_money(_toll, current_region.get_owner())
         print("%s gave $%d money to %s"
               % (_player.get_player_name(), _toll, current_region.get_owner().get_player_name()))
     # 지역 구매 여부 묻기
     current_region_price = current_region.get_sales_price(_player.get_id())
     if _player.get_current_money() >= current_region_price:
         want_to_buy = messagebox.askyesno("Buy", constant.ASK_BUY_MESSAGE[_type] % current_region_price)
         if want_to_buy:
                 current_region.buy(_player)
     return dice1, dice2