Пример #1
0
 def get_filename_for_saving(self, filename, myPath='./'):
     """Make sure that the filename exists, that it has the right extension and that it goes into the correct directory."""
     if filename == '':
         filename = get_string('What do you want to call the file? ')
     #
     # Make sure the file has the correct file extension.
     #
     if filename[-5:] != '.life':
         filename = filename + '.life'
     #
     # Check if the file already exists.
     #
     if not os.path.isdir(myPath):
         mkdir(myPath)
     if filename in os.listdir(myPath):
         prompt = f"A file named '{filename}' already exists! Do you want to replace it?"
         replaceFile = get_boolean(prompt)
         if replaceFile == False:
             filename = self.get_filename_for_saving('')
     #
     # Add on the correct path for saving files.
     #
     if filename[0:len(myPath)] != myPath:
         filename = os.path.join(myPath, filename)
     return filename
Пример #2
0
 def advance(self):
     """
     This will advance the simulation forward one year.
     :return: None
     """
     self.__economy.run()
     answer = input("<Press RETURN to continue>")
     self.__economy.determine_success(self.__farmer.totalPlots)
     balance = self.__economy.print_results(self.__farmer.totalPlots, self.__farmer.get_farmHands(), self.__farmer.get_family(), self.__farmer.get_money())
     self.__farmer.set_money(balance)
     answer = input("<Press RETURN to continue>")
     self.__economy.reset_plots(self.__farmer.totalPlots)
     if self.__farmer.get_money() < 0:
         print("You have lost all your money and are now in debt. You are forced to sell your children and farm,")
         print("and you are now on the run from the government, with a warrant for your arrest due to tax")
         print("evasion. Better luck next time.")
         answer = toolbox.get_boolean("Would you like to reset the game?")
         if answer:
             self.reset()
         else:
             command = 'quit'
     else:
         command = ''
         self.show_plots()
         self.status_bar()
     return command
 def buy_plot(self):
     """
     Purchases another plot of land for the farmer to use.
     Makes a new plot True.
     Subtracts the price from self.__money.
     :return: None
     """
     plotPrice = 50
     confirm = toolbox.get_boolean(f'Are you sure you want to purchase another plot for ${plotPrice}? : ')
     if confirm:
         self.__money = self.__money - plotPrice
         if self.__money < plotPrice:
             self.__money = self.__money + plotPrice
             print("You don't have enough money to make this purchase.")
         else:
             counter = 0
             #
             # Loop through the list of plots and count the number of plots owned
             #
             for plots in self.totalPlots:
                 if plots.get_owned():
                     counter += 1
             self.totalPlots[counter].set_owned(True)
             self.totalPlots[counter].set_contents("EMPTY")
             self.hire_farmHands()
             print('\nYou also hired a farmhand to work on the new land.\n')
Пример #4
0
 def get_filename_for_saving(self, filename, myPath='./'):
     """
     Make sure that the filename exists, that it has the right extension and that it goes into the
     correct directory.
     :param filename: name of the file, may be None at this point.
     :param myPath: Where the file should be saved.
     :return: The corrected filename with the path prepended.
     """
     if filename == '':
         filename = get_string('What do you want to call the file? ')
     #
     # Make sure the file has the correct file extension.
     #
     if filename[-5:] != '.life':
         filename = filename + '.life'
     #
     # Check if the file already exists.
     #
     if not path.isdir(myPath):
         mkdir(myPath)
     if filename in listdir(myPath):
         prompt = f"A file named '{filename}' already exists! Do you want to replace it?"
         replaceFile = get_boolean(prompt)
         if not replaceFile:
             filename = self.get_filename_for_saving('')
     #
     # Add on the correct path for saving files.
     #
     if filename[0:len(myPath)] != myPath:
         filename = path.join(myPath, filename)
     return filename
Пример #5
0
 def reset(self):
     """
     resets the game entirely
     :return: None
     """
     confirm = toolbox.get_boolean("Are you sure you want to reset? All progress will be lost. ")
     if confirm:
         self.__init__()
         self.main()
Пример #6
0
    def wants_insurance(self):
        """
        Returns True if the player should buy insurance else return False.

        This procedure is called by the dealer after all players have bet and
        receives their cards and after the dealer has received his cards. It is
        only called if the dealer is showing an ace (the dealer might have blackjack).
        """
        return get_boolean(
            f'{self.name}, do you want insurance? (The dealer has an ace showing)'
        )
Пример #7
0
    def insurance(self, hand, dealerShowing):
        """
        Returns True if the player should buy insurance else return False.

        This procedure is called by the dealer after all players have bet and
        receives their cards and after the dealer has received his cards. It is
        only called if the dealer is showing an ace, ten or a face card. i.e.
        when the dealer might have blackjack.
        """
        return get_boolean(
            f'Do you want insurance? (The dealer has a {dealerShowing})')
Пример #8
0
    def save(self, filename, myPath='./'):
        """
        Save the current generation of the current world as a text file.
        :param filename: name of the file, may be None at this point.
        :param myPath: Where the file should be saved.
        :return: None
        """
        replace = False
        Cell.set_display('basic')
        if filename == None:
            filename = toolbox.get_string(
                'What do you want to call the file? ')

        #
        # Make sure the file has the correct file extension.
        #
        if filename[-5:] != '.life':
            filename = filename + '.life'
        allFiles = os.listdir(myPath)

        if filename in allFiles:
            replace = toolbox.get_boolean(
                'There is already a file with this name. Would like to replace it?'
            )

        if replace == True:

            #
            # if the path doesn't already exist, create it.
            #
            if not os.path.isdir(myPath):
                os.mkdir(myPath)

            #
            # Add on the correct path for saving files if the user didn't
            # include it in the filename.
            #
            if filename[0:len(myPath)] != myPath:
                filename = myPath + filename
            self.__world.save(filename)
            print()
            print('You now saved this world.')
            print()
        else:
            print("Okay I won't save it.")
            print(self.__world, end='')
        print()
        print(self.status() + '\n' + self.menu(), end=' ')
 def sell_plot(self):
     """
     Sells a plot of land chosen by the user.
     Change that plot to be False.
     Gives money depending on the value of the land.
     :return: None
     """
     plotPrice = 25
     confirm = toolbox.get_boolean("Are you sure you want to sell a plot?")
     if confirm:
         counter = 0
         for plots in self.totalPlots:
             if plots.get_owned():
                 counter += 1
         self.totalPlots[counter-1].set_owned(False)
         self.__money = self.__money + plotPrice
         print('You also fired a farmhand as they had no job.')
         self.fire_farmHands()
Пример #10
0
 def name_file(self, filename):
     """
     Name file based on user input
     :param filename: what the user would like as filename
     :return: filename
     """
     if filename == None:
         filename = toolbox.get_string(
             'What do you want to call the file? ')
         if filename[-5:] != '.life':
             filename = filename + '.life'
         if filename in self.__worldFiles:
             replace = toolbox.get_boolean(
                 'There is already with this file. Would you like to replace it with current world? '
             )
             if replace == False:
                 self.name_file(filename)
     return filename
Пример #11
0
 def show_pole(self):
     if self.__wrongGuesses == 0:
         string = self.__pole.get_manPrint()
     elif self.__wrongGuesses == 1:
         string = self.__pole.onlyHead()
     elif self.__wrongGuesses == 2:
         string = self.__pole.headBody()
     elif self.__wrongGuesses == 3:
         string = self.__pole.rightArm()
     elif self.__wrongGuesses == 4:
         string = self.__pole.leftArm()
     elif self.__wrongGuesses == 5:
         string = self.__pole.rightLeg()
     else:
         string = self.__pole.fullBody()
         string += '\n\n****** You got hanged!!! ******'
         self.__gameOver = True
         again = toolbox.get_boolean('Would you like to play a new game?')
         if again == True:
             self.start_game()
     return string
Пример #12
0
    def main(self):
        """
        Main event loop for store.
        :return: None
        """
        command = 'help'
        parameter = None
        while command != 'quit':
            if command == 'help':
                self.help('help.txt')
                self.start_game()
            elif command == 'newGame':
                self.start_game()
            elif command == 'guess':
                self.take_guess()
            elif self.__gameOver == True:
                again = toolbox.get_boolean(
                    'Would you like to play a new game?')
                if again == True:
                    self.start_game()

            command, parameter = self.get_command()
        print('goodbye')
Пример #13
0
 def show_word(self):
     string = ''
     regString = ''
     currentLetter = ''
     for letter in self.__word:
         if letter in self.__lettersGuessed:
             currentLetter = f'  {letter}  '
             regString += letter
         else:
             currentLetter = '     '
         string += currentLetter
     string += '\n'
     for character in self.__word:
         string += ' ___ '
     if regString == self.__word:
         print(string)
         print()
         string += f'\n\n******* You Guesses It!!! *******'
         self.__gameOver = True
         again = toolbox.get_boolean('Would you like to play a new game?')
         if again == True:
             self.start_game()
     return string