Example #1
0
 def __init__(self, name, description, basePrice, pricePerPound):
     self.__name = str(name).strip()
     self.__description = str(description).strip()
     if is_number(basePrice):
         self.__basePrice = float(basePrice)
     else:
         raise TypeError('ShippingMethod basePrice must be a numerical type.')
     if is_number(pricePerPound):
         self.__pricePerPound = float(pricePerPound)
     else:
         raise TypeError('ShippingMethod pricePerPound must be a numerical type.')
Example #2
0
 def change_delay(self, parameter):
     """Change the delay betwen generations of the simulation."""
     if toolbox.is_number(parameter):
         delay = float(parameter)
     else:
         prompt = 'Seconds of delay between generations?'
         delay = toolbox.get_number(prompt)
     self.__delay = delay
Example #3
0
 def change_speed(self, speed):
     """Change the delay betwen generations of the simulation."""
     if toolbox.is_number(speed):
         speed = int(speed)
     else:
         prompt = 'How fast should the generations update?'
         speed = toolbox.get_integer_between(0, 11, prompt)
     self.__delay = Life.speeds[speed]
Example #4
0
 def change_fillrate(self, parameter):
     """Change the fillrate for the simulation."""
     if toolbox.is_number(parameter) and 0 <= float(parameter) <= 100:
         fillrate = float(parameter)
     else:
         prompt = 'What percent of cells should be alive?'
         fillrate = toolbox.get_integer_between(0, 100, prompt)
     self.__fillrate = fillrate
     self.random()
Example #5
0
 def set_speed(self, parameter):
     """Changes the speed of simulation"""
     if parameter != None:
         self.speed = int(parameter)
     else:
         number = False
         while not number:
             speed = input('How fast do you want to simulate? (lower is faster. Default is 0.25) ')
             number = is_number(speed)
         self.speed = float(speed)
Example #6
0
 def player_double_down(self, player, hand, additionalBet):
     if hand.can_double() and is_number(additionalBet) and player.money >= additionalBet:
         card = self._shoe.draw().flip()
         self.show_card_to_players(card)
         hand.double_down(card, additionalBet)
         self.rake_in(player.rake_out(additionalBet))
         if self.isVerbose: print(f"{player.name} doubled down and received a {card} {hand}.")
         player.timesDoubled += 1
         player.totalWagers += additionalBet
     else:
         if self.isVerbose: print("Sorry, you can't double this hand (pick again).")
Example #7
0
 def __init__(self, name, type, price):
     self.__name = str(name).strip()
     if is_number(price):
         self.__price = float(price)
     else:
         raise TypeError('Product price must be a numerical type.')
     type = str(type).strip()
     if type in Product.types:
         self.__type = type
     else:
         raise TypeError('Product type must be a member of Product.type.')
Example #8
0
 def change_fillrate(self, fillrate):
     """
     Change the fillrate for the simulation.
     :param fillrate:
     :return: fillrate
     """
     if toolbox.is_number(fillrate) and 0 <= float(fillrate) <= 100:
         fillrate = float(fillrate)
     else:
         prompt = 'What percent of cells do you want to be alive?'
         fillrate = toolbox.get_integer_between(0, 100, prompt)
     self.__fillrate = fillrate
     self.random()
Example #9
0
 def change_delay(self, parameter):
     """
     Change the delay betwen generations of the simulation.
     :param parameter:
     :return: None
     """
     if toolbox.is_number(parameter):
         delay = float(parameter)
     else:
         prompt = 'Seconds of delay between generations?'
         delay = toolbox.get_number(prompt)
     self.__delay = delay
     print(f'Your speed of running the simulation is now 1 gen every {delay} seconds.')
Example #10
0
 def change_fillrate(self, parameter):
     """
     Change the fillrate for the simulation.
     :param parameter:
     :return: None
     """
     if toolbox.is_number(parameter) and 0 <= float(parameter) <= 100:
         fillrate = float(parameter)
     else:
         prompt = 'What percent of cells should be alive?'
         fillrate = toolbox.get_integer_between(0, 100, prompt)
     self.__fillrate = fillrate
     self.random()
     print(f'The percent of alive cells is now {fillrate} percent.')
Example #11
0
 def generation_delay(self, parameter):
     """
     Set the amount of "delay" between each  shown generation
     :param parameter:
     :return: none
     """
     print("Changing simulation speed...")
     if toolbox.is_number(parameter):
         delay = float(parameter)
     else:
         prompt = 'Seconds of delay between generations?'
         delay = toolbox.get_number(prompt)
     self.__delay = delay
     self.set_delay(delay)
Example #12
0
 def read_animals(self, filename):
     """Read in all animals from the file and add them to
        the list of animals."""
     with open(filename, 'r') as animalsFile:
         for line in animalsFile:
             type, price, product, productValue, sellValue = line.split(',')
             type = type.strip()
             price = price.strip()
             product = product.strip()
             productValue = productValue.strip()
             sellValue = sellValue.strip()
             """if type not in Product.productTypes:
                 raise ValueError(f'{name}: product type cannot be "{type}". Check {filename}.')"""
             if not toolbox.is_number(price):
                 raise ValueError(f'{type}: animal price must be a number. Check {filename}.')
             animal = Animals(type, float(price), product, float(productValue), float(sellValue))
             self.__animals.append(animal)
Example #13
0
 def read_plants(self, filename):
     """Read in all plants from the file and add them to
        the list of plants."""
     with open(filename, 'r') as plantsFile:
         for line in plantsFile:
             type, price, risk, sellValue, lowerLimit, upperLimit = line.split(',')
             type = type.strip()
             price = price.strip()
             risk = risk.strip()
             sellValue = sellValue.strip()
             lowerLimit = lowerLimit.strip()
             upperLimit = upperLimit.strip()
             """if type not in Product.productTypes:
                 raise ValueError(f'{name}: product type cannot be "{type}". Check {filename}.')"""
             if not toolbox.is_number(price):
                 raise ValueError(f'{type}: plant price must be a number. Check {filename}.')
             plant = Plants(type, price, int(risk), sellValue, lowerLimit, upperLimit)
             self.__plants.append(plant)
Example #14
0
    def read_frames(self, filename):
        """
        Reads in the frames from a file
        :param filename: the name of the file holding the frame information
        :return: None
        """
        #
        # todo! Check to see that the files actually exist in graphics
        #
        with open(filename, 'r') as framesFile:
            for line in framesFile:
                #
                # This is so that the program ignores the comments in the file
                #
                if line[0] != '#':
                    name, button1, button1x, button1y, button2, button2x, button2y, button1Next, button2Next = line.split(
                        ',')
                    name = name.strip()

                    button1 = button1.strip()
                    button1x = button1x.strip()
                    button1y = button1y.strip()
                    if not toolbox.is_number(button1x):
                        raise ValueError(
                            f'{name}: button 1 x coordinate must be a number. Check {filename}.'
                        )
                    if not toolbox.is_number(button1y):
                        raise ValueError(
                            f'{name}: button 1 y coordinate must be a number. Check {filename}.'
                        )

                    button2 = button2.strip()
                    button2x = button2x.strip()
                    button2y = button2y.strip()
                    if not toolbox.is_number(button2x) and button2x != 'None':
                        raise ValueError(
                            f'{name}: button 2 x coordinate must be a number. Check {filename}.'
                        )
                    if not toolbox.is_number(button2y) and button2y != 'None':
                        raise ValueError(
                            f'{name}: button 2 y coordinate must be a number. Check {filename}.'
                        )

                    if button2x == 'None':
                        button2x = None
                    if button2y == 'None':
                        button2y = None

                    button1Next = button1Next.strip()
                    button2Next = button2Next.strip()

                    if button2x == None:
                        frame = Frame(name, button1, float(button1x),
                                      float(button1y), button2, button2x,
                                      button2y, button1Next, button2Next)
                    else:
                        frame = Frame(name, button1, float(button1x),
                                      float(button1y), button2,
                                      float(button2x), float(button2y),
                                      button1Next, button2Next)
                    self.__frames.append(frame)
        print(self.__frames)