Beispiel #1
0
 def display(self, gamer, data, dice_result):
     """
     Display description
     :type data: dict
     :return:
     """
     import operation
     player_dict = data['player_dict']
     bank = data['epic_bank']
     if self._status == 1:
         # Some body own it
         owner_id = self.owner
         owner = player_dict[owner_id]
         if owner_id == gamer.id:
             # Owner pass this station
             operation.push2all("%s own %s" % (gamer.name, self.name))
         else:
             # Other pass this station
             operation.push2all("%s own %s" % (owner.name, self.name))
             fee = self.payment(gamer.station_num)
             operation.pay(gamer, owner, fee, data)
     elif self._status == -1:
         # Nobody own
         while True:
             operation.push2all(
                 "Nobody own %s do you want to buy it?" % self.name)
             operation.push2all("1: Buy it")
             operation.push2all("2: Do not buy it")
             while True:
                 input_str = operation.wait_choice(
                     "Please enter the number of your decision:")
                 if(True):
                     input_data = data["msg"].get_json_data("input")
                     input_str = input_data[0]["request"]
                 try:
                     choice = int(input_str)
                     break
                 except ValueError:
                     operation.push2all("Please enter a number.")
             operation.push2all()
             if choice == 1:
                 price = self.value
                 if price > gamer.cash:
                     operation.push2all("You do not have enough money")
                     break
                 else:
                     operation.pay(gamer, bank, price, data)
                     operation.trade_asset(self, bank, gamer)
                     operation.push2all("%s buy %s for %d" %
                                        (gamer.name, self.name, price))
                     break
             elif choice == 2:
                 break
             else:
                 operation.push2all("Invalid operation")
     elif self._status == 0:
         # In mortgage
         operation.push2all("%s is in mortgaged" % self.name)
     else:
         raise ValueError("Invalid estate status")
 def display(self, gamer, data, dice_result):
     """
     Display description
     :param dice_result:
     :return:
     """
     player_dict = data['player_dict']
     epic_bank = data['epic_bank']
     if self._status == 1:
         # Some body own it
         owner_id = self.owner
         owner = player_dict[owner_id]
         if owner_id == gamer.id:
             # Owner pass this estate
             operation.push2all("%s own %s" % (gamer.name, self.name))
         else:
             # Other pass this estate
             operation.push2all("%s own %s" % (owner.name, self.name))
             payment = self.payment
             operation.pay(gamer, owner, payment, data)
     elif self._status == -1:
         # Nobody own
         while True:
             operation.push2all("Nobody own %s do you want to buy it?" %
                                self.name)
             operation.push2all("Price: %d" % self.value)
             operation.push2all("1: Buy it")
             operation.push2all("2: Do not buy it")
             while True:
                 operation.push2all(
                     "Please enter the number of your decision:")
                 input_str = operation.wait_choice()
                 try:
                     choice = int(input_str)
                     break
                 except ValueError:
                     operation.push2all("Please enter a number.")
             operation.push2all(" ")
             if choice == 1:
                 price = self.value
                 cur_cash = gamer.cash
                 if price > cur_cash:
                     operation.push2all("You do not have enough money")
                     break
                 else:
                     operation.pay(gamer, epic_bank, price, data)
                     operation.trade_asset(self, epic_bank, gamer)
                     operation.push2all("%s buy %s for %d" %
                                        (gamer.name, self.name, price))
                     break
             elif choice == 2:
                 break
             else:
                 operation.push2all("Invalid operation")
     elif self._status == 0:
         # In mortgage
         operation.push2all("%s is in mortgaged" % self.name)
     else:
         raise ValueError("Invalid estate status")
Beispiel #3
0
    def display(self, gamer, data, dice_result):
        """display message when entering the utility

        Parameters
        ----------
        self: class itself
        gamer: gamer object
        data: data dict
        dice_result: result of dice

        """
        # import operation
        player_dict = data['player_dict']
        bank = data['epic_bank']
        if self._status == 1:
            # Some body own it
            owner_id = self.owner
            owner = player_dict[owner_id]
            if owner_id == gamer.id:
                # Owner pass this station
                data["msg"].push2all(
                    operation.gen_record_json("%s own %s" %
                                              (gamer.name, self.name)))
            else:
                # Other pass this station
                passing_time = 0
                if gamer.id in self.enter_log:
                    passing_time = self.enter_log[gamer.id]
                    self.enter_log[gamer.id] += 1
                else:
                    self.enter_log[gamer.id] = 1
                data["msg"].push2all(
                    operation.gen_record_json("%s own %s" %
                                              (gamer.name, self.name)))
                payment = self.payment(gamer.utility_num,
                                       dice_result) * (0.9**passing_time)
                if gamer.alliance == owner.alliance:
                    # Make discount to alliance
                    payment = payment * 0.9
                    data['msg'].push2single(
                        gamer.id,
                        operation.gen_hint_json(
                            "%s and %s are alliances, make discount" %
                            (owner.name, gamer.name)))
                operation.pay(gamer, owner, payment, data)
        elif self._status == -1:
            # Nobody own
            while True:
                data["msg"].push2single(
                    gamer.id,
                    operation.gen_choice_json(
                        "Nobody own %s do you want to buy it?" % self.name))
                input_data = data["msg"].get_json_data("input")
                while input_data is False:
                    input_data = data["msg"].get_json_data("input")
                input_str = input_data[0]["request"]
                choice = int(input_str)
                if choice == 1:
                    price = self.value
                    if price > gamer.cash:
                        data["msg"].push2single(
                            gamer.id,
                            operation.gen_hint_json(
                                "You do not have enough money"))
                        break
                    else:
                        operation.pay(gamer, bank, price, data)
                        operation.trade_asset(self, bank, gamer)
                        data["msg"].push2all(
                            operation.gen_record_json(
                                "%s buy %s for %d" %
                                (gamer.name, self.name, price)))
                        break
                elif choice == 2:
                    break
                else:
                    data["msg"].push2single(
                        gamer.id, operation.gen_hint_json("Invalid operation"))
        elif self._status == 0:
            # In mortgage
            data["msg"].push2single(
                gamer.id,
                operation.gen_hint_json("%s is in mortgaged" % self.name))
        else:
            raise ValueError("Invalid estate status")
Beispiel #4
0
 def display(self, gamer, data, dice_result):
     """
     Display description
     """
     player_dict = data['player_dict']
     epic_bank = data['epic_bank']
     if self._status == 1:
         # Some body own it
         owner_id = self.owner
         owner = player_dict[owner_id]
         print(owner_id)
         print(player_dict)
         if owner_id == gamer.id:
             # Owner pass this estate
             data['msg'].push2single(gamer.id, operation.gen_hint_json(
                 "%s own %s" % (gamer.name, self.name)))
         else:
             # Other pass this estate
             passing_time = 0
             if gamer.id in self.enter_log:
                 passing_time = self.enter_log[gamer.id]
                 self.enter_log[gamer.id] += 1
             else:
                 self.enter_log[gamer.id] = 1
             payment = self.payment * (0.9 ** passing_time)
             data['msg'].push2single(gamer.id, operation.gen_hint_json(
                 "%s own %s" % (owner.name, self.name)))
             if gamer.alliance == owner.alliance:
                 # Make discount to alliance
                 payment = payment * 0.9
                 data['msg'].push2single(gamer.id, operation.gen_hint_json(
                     "%s and %s are alliances, make discount" % (owner.name, gamer.name)))
             operation.pay(gamer, owner, payment, data)
     elif self._status == -1:
         # Nobody own
         while True:
             # data['msg'].push2singe(gamer.id, operation.gen_hint_json("Nobody own %s do you want to buy it?" % self.name))
             data["msg"].push2single(gamer.id, operation.gen_choice_json(
                 "Nobody own %s do you want to buy it?" % self.name))
             # data['msg'].push2single(gamer.id, operation.gen_hint_json("Price: %d" % self.value))
             # data['msg'].push2single(gamer.id, operation.gen_hint_json("1: Buy it"))
             # data['msg'].push2single(gamer.id, operation.gen_hint_json("2: Do not buy it"))
             input_str = data['msg'].get_json_data("input")
             while not input_str:
                 input_str = data['msg'].get_json_data("input")
             input_str = input_str[0]["request"]
             choice = int(input_str)
             if choice == 1:
                 price = self.value
                 cur_cash = gamer.cash
                 if price > cur_cash:
                     data['msg'].push2single(gamer.id, operation.gen_hint_json(
                         "You do not have enough money"))
                     break
                 else:
                     operation.pay(gamer, epic_bank, price, data)
                     operation.trade_asset(self, epic_bank, gamer)
                     data['msg'].push2all(operation.gen_hint_json(
                         "%s buy %s for %d" % (gamer.name, self.name, price)))
                     break
             elif choice == 2:
                 break
             else:
                 data['msg'].push2single(
                     gamer.id, operation.gen_hint_json("Invalid operation"))
     elif self._status == 0:
         # In mortgage
         data['msg'].push2single(gamer.id, operation.gen_hint_json(
             "%s is in mortgaged" % self.name))
     else:
         raise ValueError("Invalid estate status")