Exemple #1
0
 def __init__(self, name, initial_cash, initial_chips):
     self.__name = name #initialize the name
     self.__wallet = Wallet(initial_cash) #initialize the Wallet
     self.__chips = ChipBag(initial_chips) #initialize the ChipBag
     self.__saturation = 10 #just ate
     self.__hunger = 0 #not hungry
     self.__fatigue = 0 #not tired
     self.__rep = 0 #no reputation
Exemple #2
0
class Player(object):

    #constructor
    def __init__(self, name, initial_cash, initial_chips):
        self.__name = name #initialize the name
        self.__wallet = Wallet(initial_cash) #initialize the Wallet
        self.__chips = ChipBag(initial_chips) #initialize the ChipBag
        self.__saturation = 10 #just ate
        self.__hunger = 0 #not hungry
        self.__fatigue = 0 #not tired
        self.__rep = 0 #no reputation

    #representation and string methods
    def __repr__(self):
        return self.__name #use the name field

    def __str__(self):
        return self.__repr__() #use the __repr__ method

    #getters
    def get_wallet(self):
        return self.__wallet #return the wallet field

    def get_chips(self):
        return self.__chips #return the chips field

    def get_rep(self):
        return self.__rep #return the rep field

    def get_name(self):
        return self.__name #return the name


    #properties
    wallet = property(get_wallet) #create a getter property for the wallet
    chips = property(get_chips) #create a getter property for chips
    rep = property(get_rep) #create a getter property for rep
    name = property(get_name) #create a getter property for name

    #methods

    #print_stats method - prints the stats of the player
    def print_stats(self):
        print(self.__name + '\'s current stats:')
        print('Hunger: ' + str(self.__hunger))
        print('Fatigue: ' + str(self.__fatigue))
        print('Reputation: ' + str(self.__rep))
        balance = self.__wallet.value + self.__chips.value + DepositBox().balance
        print('Wallet balance: ' + str(self.__wallet.value))
        print('Chip balance: ' + str(self.__chips.value))
        print('Deposit box balance: ' + str(DepositBox().balance))
        print('Total balance: ' + str(balance))
        percent_wallet = float(self.__wallet.value / balance)
        percent_chips = float(self.__chips.value / balance)
        percent_box = float(DepositBox().balance / balance)
        print('Percent in wallet: ' + str(percent_wallet))
        print('Percent in chips: ' + str(percent_chips))
        print('Percent in deposit box: ' + str(percent_box))


    #feed method - decreases the hunger of the player (cannot go past 0)
    def feed(self, food):
        self.__hunger -= food.nutrition #use the nutrition field to determine how much to feed
        if self.__hunger < 0: #check for invalid values
            self.__hunger = 0 #fix them
        self.__saturation += food.saturation #use the saturation field to determine the new saturation
        food.eat(self) #call food.eat to handle the food code


    #remove_fatigue method - removes a set number of fatigue points from the player
    def remove_fatigue(self, points):
        self.__fatigue -= points #remove the points

    #sleep method - completely removes fatigue from the player
    def sleep(self):
        self.__fatigue = 0 #refresh the player

    #gain_rep method - increases reputation
    def gain_rep(self, amt):
        self.__rep += amt #increase reputation
        if self.__rep > 100: #this if statement checks for invalid values
            self.__rep = 100
        elif self.__rep < -100:
            self.rep = -100


    #lose_rep method - decreases reputation
    def lose_rep(self, amt):
        self.gain__rep(-amt) #use the gain__rep method negatively


    #pass_time method - run by the game to pass the time
    def pass_time(self):
        if randint(0,1) == 1 and self.__saturation > 0:
            self.__saturation -= 1 #make the player hungry 50% of the time
        if randint(0,1) == 1 and self.__saturation == 0:
            self.__hunger += 1 #add hunger 50% of the time if saturation is 0
        if self.__hunger >= 100: #if the player is too hungry to continue
            print('You have fainted of hunger.') #print the 'death message'
            print('While asleep, you have been robbed of all your money.')
            current__bal = self.__wallet.value #get the value of the wallet
            self.__wallet.pay(current__bal) #wipe the wallet
        if self.__wallet.value <= 0:
            if DepositBox().balance <= 0 and self.__chips.value <= 0: #if the player has no more money
                print('You have no more money.')
                print('GAME OVER')
                sys.exit(0) #quit the script
        if self.__hunger >= 50: #if a warning should be shown
            print('You are very hungry.') #print the warning
        if randint(0,1) == 0:
            self.__fatigue +=  1 #add fatigue 50% of the time
        if self.__fatigue >= 100: #if tthe player is too tired to continue
            print('You have fainted from fatigue.') #print the 'death message'
            print('While asleep, all your chips were stolen.')
            current__bal = self.__chips.value #get the value of the chips
            self.__chips.pay(current__bal) #wipe the chip bag
        if self.__chips.value <= 0:
            if DepositBox().balance <= 0 and self.__wallet.value <= 0: #if the player has no more money
                print('You have no more money.')
                print('GAME OVER')
                sys.exit(0) #quit the script
        if self.__fatigue >= 50: #if a warning should be shown
            print('You are very tired.') #print the warning