def loadPet(petName): petInfo = open(petName.replace(' ', '_') + ".pet", 'r') petList = petInfo.read() petList = petList.split(' ') newPet = Pet(petList[0], int(petList[1]), int(petList[2]), int(petList[3]), int(petList[4]), int(petList[5]), int(petList[6]), int(petList[7])) newPet.whenYouWereGone(int(time.time())) playGame(newPet)
def setUp(self): print("set-up") self.vet = Vet() self.lisa = Owner("Lisa", "1 Street St, Burlington VT", 8021234567) self.sherlock = Owner("Sherlock", "Baker street", 2342342334) self.knox = Pet("Knox", "Feline", "Domestic short hair", 2) self.fluffy = Pet("Fluffy", "Canine", "Pug", 2) self.dracula = Pet("Dracula", "Feline", "Domestic Shorthair", 4) self.record1 = VetRecord("4th April 2020", "In one month", "Dr.DoLittle", "check-up") self.record2 = VetRecord("2nd January 2020", "In one week", "Dr.Nancy", "Ate trash")
class Test(unittest.TestCase): def setUp(self): self.pet = Pet('kitten', Character('owner', 30, 'w', House())) def test_hunger_down(self): self.pet.hunger_down() self.assertEqual(self.pet.hunger, 9) def test_act(self): self.pet.owner.needs['fun'] = 7 self.pet.owner.needs['comfort'] = 7 self.pet.act() self.assertIn(self.pet.owner.needs['fun'], (6, 10)) self.assertIn(self.pet.owner.needs['fun'], (5, 10))
def get_pet(self, name): if self.pet is None: pet = Pet(name, self) self.house.pets[name] = pet self.pet = pet else: print('You already have a pet')
def add_pet(self, id_pet, type_pet, nickname, color, birthday, owner, phone): if self.get_pet(id_pet) is not None: return False if not re.fullmatch("[A-ZА-Я][a-zа-я]*", type_pet): raise ValueError if not re.fullmatch("[A-ZА-Я][a-zа-я]*", nickname): raise ValueError if not re.fullmatch("[A-ZА-Я][a-zа-я-]*", color): raise ValueError if not re.fullmatch(r"\d{2}-\d{2}-\d{4}", birthday): raise ValueError if not re.fullmatch("([A-ZА-Я][a-zа-я]* ){2}[A-ZА-Я][a-zа-я]*", owner): raise ValueError if not re.fullmatch(r"\+?\d{11}", phone): raise ValueError new_pet = Pet(id_pet, type_pet, nickname, color, birthday, owner, phone) self.pets.append(new_pet) return True
def __init__(self): #Initialize Window, without putting a value in it yet self.window = None self.view = PetView(self.window) self.model = Pet("Honey Badger") # This queue's actions so that two threads don't try to access something at the same time self.request_queue = queue.Queue() self.result_queue = queue.Queue() # Adding buttons/Controls to the View window # TODO: Use Lambdas instead of wrapper functions ttk.Button(self.view.mainframe, text="Feed", name="feed", command= lambda: self.submitAction(self.feed)).grid(column=2, row=4) ttk.Button(self.view.mainframe, text="Play", name="play", command= lambda: self.submitAction(self.play)).grid(column=2, row=5) ttk.Button(self.view.mainframe, text="Clean", name="clean", command= lambda: self.submitAction(self.clean)).grid(column=2, row=6)
def main(): count = int(input("Enter the count of data desires: ")) # How to delete file content f = open("petdb.txt", "a+") f.seek(0) f.truncate() for n in range(0, count, 1): name = name_generator("pet") owner = name_generator("owner") age = date_generator(0) image = download_image() breed = image.split(".")[0] new_pet = Pet(n, image, name, breed, age, owner) f.write(str(new_pet) + "\n")
def __init__(self): #make this a widget QtGui.QWidget.__init__(self) #main layout will be a Horizontal Box layout self.mainLayout = QtGui.QHBoxLayout(self) #logowidget layout will be left-most layout within main layout self.LogoWidget = LogoWidget() self.LogoWidget.setStyleSheet("background-color:white;") self.mainLayout.addWidget(self.LogoWidget) #Display layout will be right-most layout self.DisplayWidget = DisplayWidget() self.mainLayout.addWidget(self.DisplayWidget) #connect Feed button to action self.DisplayWidget.feedButton.clicked.connect(self.feed) #connect info "?" button to action self.DisplayWidget.infoButton.clicked.connect(self.openInfoDialog) #instantiate the pet self.Pet = Pet() #get pet hunger value and set progress bar to display it self.hunger = self.Pet.hunger self.DisplayWidget.hungerProgressBar.setValue(self.hunger) #get pet health value and set progress bar to display it self.health = self.Pet.health self.DisplayWidget.healthProgressBar.setValue(self.health) #start hunger timer self.hungerTimer() #update hunger to see how hunger Marie got from last save self.updateHungerFromPreviousSave() #create an update timer to update application self.updateTimer = QtCore.QTimer() #update application every second self.updateTimer.start(1000) self.updateTimer.timeout.connect(self.update)
def create_pet(self): print('welcome to the pet shop!') self.display_kinds() kind = self.get_user_input('which one would you like?') while kind not in self.kinds: print('we don\'t have that...') self.display_kinds() kind = self.get_user_input('please select one on the list.') name = self.get_user_input( 'what would you like your new buddy to be named?') player_pet = Pet(name, kind, self) print(f'this is {player_pet.name}, a {player_pet.kind}.') print('<( o o )>') print('you need to take care of it.') print('type actions to see all the actions!') return player_pet
def initListPet(self): with open('pets.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for col in csv_reader: tempPet = Pet(col[0], col[1], col[2], col[3], col[4], col[5], col[6], col[7], col[8], col[9], col[10]) pets.insert(tempPet)
def drawScreen(root): ''' Draw all objects on screen ''' root.petFrame = Pet(root)
def main(): new_pet = Pet() new_toy = Toy() let_pet_play(new_pet) new_pet.idle() while new_pet.alive: if new_pet.energy == 0: # Checks to make sure the pet has the energy to play with the toy print("Your pet is too tired and needs to sleep for 60 seconds.") new_pet.sleep() let_pet_play(new_pet) new_pet.idle() elif new_toy.battery_power == 0: # Checks to make sure the toy has the battery level to play print( "It looks like the toy's battery is dead. You will have to wait 35 seconds for the battery to " "recharge.") new_toy.charge_battery() let_pet_play(new_pet) new_pet.idle() elif new_pet.energy > 0: if new_pet.energy <= new_toy.battery_power: # If the toy has more battery power than the pet has energy, time.sleep( new_pet.energy ) # the pet energy and toy battery life are decreased by the new_toy.drain_battery(new_pet.energy) # pet energy level new_pet.play_with_toy(new_pet.energy) let_pet_play(new_pet) new_pet.idle() else: time.sleep( new_toy.battery_power ) # If the pet has more energy than the toy has battery, new_pet.play_with_toy( new_toy.battery_power ) # the pet energy and toy battery life are decreased by new_toy.drain_battery( new_toy.battery_power) # the battery power let_pet_play(new_pet) new_pet.idle() print( "Oh no! It seems your pet got too unhappy and died. Try not to wait too long to let it play next time." )
# cat class from inheritance example from Pet import Pet # subclasses show the differences from superclass and other subclasses # they require that the superclass is passed through them class Cat(Pet): # if you want to add an attribute, you must slightly redefine __init__ def __init__(self, name, age, color): self.color = color # super is in reference to the superclass Pet # this is intended to call the __init__ method of the superclass # then pass its variables super().__init__(name, age) # if the methods in the subclass carry the same name as the superclass' # the subclass method overrides that of the superclass def speak(self): print('Meow') def show(self): print(f'My name is {self.name}, I am {self.age} years old, and I am {self.color}') p = Pet('April', 4) p.speak() p.show() c = Cat('Mishi', 3, 'Black') c.speak() c.show()
def show(self): Pet.show(self) print("weight=%f" % self.weight)
from sqlalchemy.orm import sessionmaker from Pet import Pet from ReplyInfo import ReplyInfo connect_str = "mysql+mysqlconnector://root:[email protected]/test?charset=utf8mb4" engine = create_engine(connect_str, echo=True) connection = engine.connect() Session = sessionmaker(bind=engine) session = Session() # result = session.query(ReplyInfo).all() # for row in result: # print(row) p1 = Pet() p1.name = 'honoy' p1.owner = 'Buffy' p1.species = 'dog' p1.sex = 'f' p1.birth = '1998-09-08' p1.death = None pets = [] for x in range(10): pets.append(p1) # add a list (add_all只能add一个,不清楚为啥) # session.add_all(p1) # session.bulk_save_objects(pets)
def main(): d1 = Dog("Money", "black") p1 = Pet("Candy", "Fish") animal_speak(d1) animal_speak(p1)
def __init__(self, name, hates_dogs): Pet.__init__(self, name, "Cat") self.hates_dogs = hates_dogs
def __init__(self, name, chases_cats): Pet.__init__(self, name, "Dog") self.chases_cats = chases_cats
def main(): global currPet global currGameState is_draggable = False on_pizza = False on_edamame = False on_fruitTart = False on_rice = False offset_x = 0 offset_y = 0 m_x = 0 m_y = 0 pizza_x = 100 pizza_y = 350 edamame_x = 280 edamame_y = 350 fruitTart_x = 530 fruitTart_y = 350 rice_x = 650 rice_y = 350 savefile = open(os.getcwd() + "/save/saveFile.txt", "a+") FRAMERATE = 12 titleBG = GIFImage(os.getcwd() + "/graphicAssets/BgTitle3") homeBG = GIFImage(os.getcwd() + "/graphicAssets/BgTitle5") homeBG.resize(800, 480) qaBG = GIFImage(os.getcwd() + "/graphicAssets/BgTitle4") qaBG.resize(800, 480) sleepBG = GIFImage(os.getcwd() + "/graphicAssets/SleepBG") sleepBG.resize(800, 480) waterBG = GIFImage(os.getcwd() + "/graphicAssets/BgWater") waterBG.resize(800, 480) foodBG = GIFImage(os.getcwd() + "/graphicAssets/BgFood") foodBG.resize(800, 480) playBG = GIFImage(os.getcwd() + "/graphicAssets/BgPlay") playBG.resize(800, 480) #loading food images pizza = pg.image.load(os.getcwd() + "/graphicAssets/pizza.png") fruitTart = pg.image.load(os.getcwd() + "/graphicAssets/fruitTart.png") rice = pg.image.load(os.getcwd() + "/graphicAssets/rice.png") edamame = pg.image.load(os.getcwd() + "/graphicAssets/edamame.png") eggUnhatched = GIFImage(os.getcwd() + "/graphicAssets/EggUnhatched", WIDTH / 4 + 80, HEIGHT / 2 - 170, 15) eggUnhatched.resize(250, 250) eggHatchedBala = GIFImage(os.getcwd() + "/graphicAssets/EggHatchedBala2") eggHatchedBala.resize(200, 200) eggHatchedBala.setCoords(300, 130) eggHatchedMamau = GIFImage(os.getcwd() + "/graphicAssets/EggHatchedMamau2") eggHatchedMamau.resize(200, 200) eggHatchedMamau.setCoords(300, 130) eggHatchedTora = GIFImage(os.getcwd() + "/graphicAssets/EggHatchedTora2") eggHatchedTora.resize(200, 200) eggHatchedTora.setCoords(300, 130) showerBG = GIFImage(os.getcwd() + "/graphicAssets/ShowerBG") showerBG.resize(800, 480) showerBala = GIFImage(os.getcwd() + "/graphicAssets/ShowerBala", WIDTH / 4 + 80, HEIGHT / 2 + 40, 15) showerBala.resize(150, 200) showerDoneBala = GIFImage(os.getcwd() + "/graphicAssets/ShowerDoneBala", WIDTH / 4 + 80, HEIGHT / 2 + 40, 15) showerDoneBala.resize(150, 200) showerMamau = GIFImage(os.getcwd() + "/graphicAssets/ShowerMamau", WIDTH / 4 + 80, HEIGHT / 2 + 40, 15) showerMamau.resize(150, 200) showerDoneMamau = GIFImage(os.getcwd() + "/graphicAssets/ShowerDoneMamau", WIDTH / 4 + 80, HEIGHT / 2 + 40, 15) showerDoneMamau.resize(150, 200) showerTora = GIFImage(os.getcwd() + "/graphicAssets/ShowerTora", WIDTH / 4 + 80, HEIGHT / 2 + 40, 15) showerTora.resize(150, 200) showerDoneTora = GIFImage(os.getcwd() + "/graphicAssets/ShowerDoneTora", WIDTH / 4 + 80, HEIGHT / 2 + 40, 15) showerDoneTora.resize(150, 200) eggUnhatched = GIFImage(os.getcwd() + "/graphicAssets/EggUnhatched", WIDTH / 4 + 80, HEIGHT / 2 - 170, 15) eggUnhatched.resize(250, 250) startButton = Buttonify(os.getcwd() + "/graphicAssets/startButton.png", screen) startButton.resize(300, 100) startButton.setCoords(100, 300) newGameButton = Buttonify(os.getcwd() + "/graphicAssets/NewGame.png", screen) newGameButton.resize(320, 110) newGameButton.setCoords(75, 180) continueGameButton = Buttonify(os.getcwd() + "/graphicAssets/LoadGame.png", screen) continueGameButton.resize(300, 100) continueGameButton.setCoords(425, 175) qa1LeftButton = RectButton(WIDTH / 4 - 145, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa1MiddleButton = RectButton(WIDTH / 4 + 98, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa1RightButton = RectButton(WIDTH / 4 + 340, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa2LeftButton = RectButton(WIDTH / 4 - 145, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa2MiddleButton = RectButton(WIDTH / 4 + 98, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa2RightButton = RectButton(WIDTH / 4 + 340, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa3LeftButton = RectButton(WIDTH / 4 - 145, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa3MiddleButton = RectButton(WIDTH / 4 + 98, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa3RightButton = RectButton(WIDTH / 4 + 340, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa4LeftButton = RectButton(WIDTH / 4 - 145, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa4MiddleButton = RectButton(WIDTH / 4 + 98, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) qa4RightButton = RectButton(WIDTH / 4 + 340, HEIGHT / 2 + 55, 215, 50, screen, BLACK, 100) HomeFoodButton = RectButton(7 * WIDTH / 8, HEIGHT / 16 + 10, 90, 90, screen, BLACK, 180) HomeWaterButton = RectButton(7 * WIDTH / 8, HEIGHT / 16 + 110, 90, 90, screen, BLACK, 180) HomeSleepButton = RectButton(7 * WIDTH / 8, HEIGHT / 16 + 210, 90, 90, screen, BLACK, 180) HomeStressButton = RectButton(7 * WIDTH / 8, HEIGHT / 16 + 310, 90, 90, screen, BLACK, 180) sleepAffirmationsButton = RectButton(300, 210, 215, 50, screen, BLACK, 100) sleepLogButton = RectButton(300, 140, 215, 50, screen, BLACK, 100) sleepMeditateButton = RectButton(300, 280, 215, 50, screen, BLACK, 100) sleep_checkin_button = RectButton(20, 20, 215, 50, screen, BLACK, 100) sleep_checkin_button.getImageRect().center = (WIDTH / 2, HEIGHT / 2) sleep_question_button = RectButton(20, 20, 550, 50, screen, BLACK) sleep_question_button.getImageRect().center = (WIDTH / 2, HEIGHT / 4) sleep_response_button = RectButton(20, 20, 650, 50, screen, BLACK) sleep_response_button.getImageRect().center = (WIDTH / 2, HEIGHT / 4) backButton = RectButton(10, 10, 215, 50, screen, BLACK, 100) sleepBreatheButton = RectButton(200, 200, 215, 50, screen, BLACK, 100) exitButton = RectButton(20, HEIGHT - 70, 215, 50, screen, BLACK, 100) currPet.setCoords(WIDTH / 2, 3 * HEIGHT / 4) currPet.setMoveCycleCount(45) meditate = Meditate(screen) checkin_button = RectButton(20, 20, 215, 50, screen, BLACK, 100) checkin_button.getImageRect().center = (WIDTH / 2, HEIGHT / 2) water_question_button = RectButton(20, 20, 550, 50, screen, BLACK) water_question_button.getImageRect().center = (WIDTH / 2, HEIGHT / 4) water_response_button = RectButton(20, 20, 650, 50, screen, BLACK) water_response_button.getImageRect().center = (WIDTH / 2, HEIGHT / 4) shower_response_button = RectButton(20, 350, 100, 50, screen, BLACK) shower_response_button.getImageRect().center = (WIDTH / 2, HEIGHT / 4) shower_text_button = RectButton(20, 350, 650, 50, screen, BLACK) shower_text_button.getImageRect().center = (WIDTH / 2, HEIGHT / 4) water_drop1 = Buttonify(os.getcwd() + "/graphicAssets/WaterDrop.png", screen) water_drop2 = Buttonify(os.getcwd() + "/graphicAssets/WaterDrop.png", screen) water_exists1 = True water_exists2 = True water_drop1.resize(100, 100) water_drop2.resize(100, 100) petSum = 0 showerCount = 0 while True: clock = pg.time.Clock() ev = pg.event.get() screen.fill(WHITE) if currGameState.value > Screen.HATCH.value: currPet.food += FOOD_CHANGE_RATE currPet.water += WATER_CHANGE_RATE currPet.sleep += SLEEP_CHANGE_RATE currPet.stress += STRESS_CHANGE_RATE currPet.food = 0 if currPet.food < 0 else 100 if currPet.food > 100 else currPet.food currPet.water = 0 if currPet.water < 0 else 100 if currPet.water > 100 else currPet.water currPet.sleep = 0 if currPet.sleep < 0 else 100 if currPet.sleep > 100 else currPet.sleep currPet.stress = 0 if currPet.stress < 0 else 100 if currPet.stress > 100 else currPet.stress if currGameState == Screen.STARTING: titleBG.animate(screen) title = titleFont.render('JikoAi', True, WHITE) screen.blit(title, (WIDTH / 4 - 15, HEIGHT / 2 - 125)) subtitle = textFont.render('Click to begin!', True, WHITE) screen.blit(subtitle, (WIDTH / 4 + 25, HEIGHT / 2 + 32)) elif currGameState == Screen.SELECTION: titleBG.animate(screen) newGameButton.draw() continueGameButton.draw() elif currGameState == Screen.HOME: homeBG.animate(screen) innerFoodBar = pg.Rect(40, 40, 200, 25) innerWaterBar = pg.Rect(40, 80, 200, 25) innerSleepBar = pg.Rect(40, 120, 200, 25) innerStressBar = pg.Rect(40, 160, 200, 25) currPet.drawStatBar(screen, innerFoodBar, ORANGE, currPet.food) currPet.drawStatBar(screen, innerWaterBar, BLUE, currPet.water) currPet.drawStatBar(screen, innerSleepBar, PURPLE, currPet.sleep) currPet.drawStatBar(screen, innerStressBar, RED, currPet.stress) currPet.draw(screen) HomeFoodButton.draw() HomeFoodButton.draw_text("food") HomeWaterButton.draw() HomeWaterButton.draw_text("water") HomeSleepButton.draw() HomeSleepButton.draw_text("sleep") HomeStressButton.draw() HomeStressButton.draw_text("play") exitButton.draw() exitButton.draw_text("EXIT") elif currGameState == Screen.EGG: print("FILLER") elif currGameState == Screen.HATCH: homeBG.animate(screen) hatchedSubtitle = RectButton(150, 50, 500, 50, screen, BLACK, 128) hatchedSubtitle.draw() hatchedSubtitle.draw_text("Here's your new pet!") underSubtitle = RectButton(150, 350, 500, 50, screen, BLACK, 128) underSubtitle.draw() underSubtitle.draw_text("Click anywhere to continue.") if petSum <= 6: eggHatchedBala.animate(screen) currPet = Pet.init_gifImage(PetType.BALAGIF, "bala") elif petSum <= 9: eggHatchedMamau.animate(screen) currPet = Pet.init_gifImage(PetType.MAMAUGIF, "mamau") else: eggHatchedTora.animate(screen) currPet = Pet.init_gifImage(PetType.TORAGIF, "tora") savefile.write(str(currPet.petType.value) + "\n") currGameState = Screen.HOME currPet.setCoords(WIDTH / 2, HEIGHT / 2) elif currGameState == Screen.Q_A: homeBG.animate(screen) eggUnhatched.animate(screen) bgRect = pg.Surface((600, 75)) bgRect.set_alpha(100) bgRect.fill(BLACK) screen.blit(bgRect, (WIDTH / 4 - 80, HEIGHT / 2 + 70)) eggSubtitle = textFont.render('Who will your pet be?', True, WHITE) screen.blit(eggSubtitle, (WIDTH / 4 - 30, HEIGHT / 2 + 77)) elif currGameState == Screen.Q_A1: qaBG.animate(screen) bgRect = pg.Surface((600, 75)) bgRect.set_alpha(100) bgRect.fill(BLACK) screen.blit(bgRect, (WIDTH / 4 - 90, HEIGHT / 2 - 160)) qTitle = textFont.render('Some questions first!', True, WHITE) screen.blit(qTitle, (WIDTH / 4 - 30, HEIGHT / 2 - 157)) q1Text = textFont.render('Do you often feel stressed?', True, WHITE) bgRect1 = pg.Surface((700, 75)) bgRect1.set_alpha(100) bgRect1.fill(BLACK) screen.blit(bgRect1, (WIDTH / 4 - 145, HEIGHT / 2 - 35)) screen.blit(q1Text, (WIDTH / 4 - 110, HEIGHT / 2 - 30)) bgRect2 = pg.Surface((215, 50)) bgRect2.set_alpha(100) bgRect2.fill(BLACK) qa1LeftButton.draw() qa1LeftButton.draw_text("Not often") qa1MiddleButton.draw() qa1MiddleButton.draw_text("Sometimes") qa1RightButton.draw() qa1RightButton.draw_text("Often") elif currGameState == Screen.Q_A2: qaBG.animate(screen) bgRect = pg.Surface((600, 75)) bgRect.set_alpha(100) bgRect.fill(BLACK) screen.blit(bgRect, (WIDTH / 4 - 90, HEIGHT / 2 - 160)) qTitle = textFont.render('Some questions first!', True, WHITE) screen.blit(qTitle, (WIDTH / 4 - 30, HEIGHT / 2 - 157)) q1Text = textFont.render('I feel good about myself.', True, WHITE) bgRect1 = pg.Surface((700, 75)) bgRect1.set_alpha(100) bgRect1.fill(BLACK) screen.blit(bgRect1, (WIDTH / 4 - 145, HEIGHT / 2 - 35)) screen.blit(q1Text, (WIDTH / 4 - 110, HEIGHT / 2 - 30)) bgRect2 = pg.Surface((215, 50)) bgRect2.set_alpha(100) bgRect2.fill(BLACK) qa2LeftButton.draw() qa2LeftButton.draw_text("Disagree") qa2MiddleButton.draw() qa2MiddleButton.draw_text("Not sure") qa2RightButton.draw() qa2RightButton.draw_text("Agree") elif currGameState == Screen.Q_A3: qaBG.animate(screen) bgRect = pg.Surface((600, 75)) bgRect.set_alpha(100) bgRect.fill(BLACK) screen.blit(bgRect, (WIDTH / 4 - 90, HEIGHT / 2 - 160)) qTitle = textFont.render('Some questions first!', True, WHITE) screen.blit(qTitle, (WIDTH / 4 - 30, HEIGHT / 2 - 157)) q1Text = textFont.render('I have things under control.', True, WHITE) bgRect1 = pg.Surface((700, 75)) bgRect1.set_alpha(100) bgRect1.fill(BLACK) screen.blit(bgRect1, (WIDTH / 4 - 145, HEIGHT / 2 - 35)) screen.blit(q1Text, (WIDTH / 4 - 110, HEIGHT / 2 - 30)) bgRect2 = pg.Surface((215, 50)) bgRect2.set_alpha(100) bgRect2.fill(BLACK) qa3LeftButton.draw() qa3LeftButton.draw_text("Disagree") qa3MiddleButton.draw() qa3MiddleButton.draw_text("Not sure") qa3RightButton.draw() qa3RightButton.draw_text("Agree") elif currGameState == Screen.Q_A4: qaBG.animate(screen) bgRect = pg.Surface((600, 75)) bgRect.set_alpha(100) bgRect.fill(BLACK) screen.blit(bgRect, (WIDTH / 4 - 90, HEIGHT / 2 - 160)) qTitle = textFont.render('Some questions first!', True, WHITE) screen.blit(qTitle, (WIDTH / 4 - 30, HEIGHT / 2 - 157)) q1Text = textFont.render('I take good care of myself.', True, WHITE) bgRect1 = pg.Surface((700, 75)) bgRect1.set_alpha(100) bgRect1.fill(BLACK) screen.blit(bgRect1, (WIDTH / 4 - 145, HEIGHT / 2 - 35)) screen.blit(q1Text, (WIDTH / 4 - 110, HEIGHT / 2 - 30)) bgRect2 = pg.Surface((215, 50)) bgRect2.set_alpha(100) bgRect2.fill(BLACK) qa4LeftButton.draw() qa4LeftButton.draw_text("Disagree") qa4MiddleButton.draw() qa4MiddleButton.draw_text("Not sure") qa4RightButton.draw() qa4RightButton.draw_text("Agree") elif currGameState == Screen.WATER: waterBG.animate(screen) backButton.draw() backButton.draw_text("Back") checkin_button.draw() checkin_button.draw_text("CHECK IN") water_question_button.draw() water_question_button.draw_text( "Have you drank anything recently?") elif currGameState == Screen.WATER_ACTIVE: waterBG.animate(screen) backButton.draw() backButton.draw_text("Back") water_response_button.draw() water_response_button.draw_text( "Thank you for keeping us both healthy!") if water_exists1: water_drop1.draw() if water_exists2: water_drop2.draw() currPet.draw(screen) elif currGameState == Screen.FUN: playBG.animate(screen) backButton.draw() backButton.draw_text("Back") elif currGameState == Screen.SLEEP: sleepBG.animate(screen) # affirmations sleepAffirmationsButton.draw() sleepAffirmationsButton.draw_text("Affirmations") # meditate sleepMeditateButton.draw() sleepMeditateButton.draw_text("Meditation") # sleep sleepLogButton.draw() sleepLogButton.draw_text("Log Sleep") # back backButton.draw() backButton.draw_text("Back") # currPet.draw(screen) elif currGameState == Screen.SHOWER: showerBG.animate(screen) shower_response_button.draw() shower_response_button.draw_text("SHOWER") if currPet.petType == "PetType.BALA" or currPet.petType == "PetType.BALAGIF": showerBala.animate(screen) elif currPet.petType == "PetType.MAMAU" or currPet.petType == "PetType.MAMAUGIF": showerMamau.animate(screen) elif currPet.petType == "PetType.TORA" or currPet.petType == "PetType.TORAGIF": showerTora.animate(screen) backButton.draw() backButton.draw_text("Back") elif currGameState == Screen.SHOWER_TWO: showerBG.animate(screen) if currPet.petType == "PetType.BALA" or currPet.petType == "PetType.BALAGIF": showerBala.animate(screen) elif currPet.petType == "PetType.MAMAU" or currPet.petType == "PetType.MAMAUGIF": showerMamau.animate(screen) elif currPet.petType == "PetType.TORA" or currPet.petType == "PetType.TORAGIF": showerTora.animate(screen) backButton.draw() backButton.draw_text("Back") elif currGameState == Screen.SHOWER_DONE: showerBG.animate(screen) shower_text_button.draw() shower_text_button.draw_text("Thank you for taking care of me!") if currPet.petType == "PetType.BALA" or currPet.petType == "PetType.BALAGIF": showerDoneBala.animate(screen) elif currPet.petType == "PetType.MAMAU" or currPet.petType == "PetType.MAMAUGIF": showerDoneMamau.animate(screen) elif currPet.petType == "PetType.TORA" or currPet.petType == "PetType.TORAGIF": showerDoneTora.animate(screen) backButton.draw() backButton.draw_text("Back") elif currGameState == Screen.FOOD: foodBG.animate(screen) #drawing food images screen.blit(pg.transform.scale(pizza, (100, 100)), (pizza_x, pizza_y)) screen.blit(pg.transform.scale(fruitTart, (100, 100)), (fruitTart_x, fruitTart_y)) screen.blit(pg.transform.scale(rice, (100, 100)), (rice_x, rice_y)) screen.blit(pg.transform.scale(edamame, (100, 100)), (edamame_x, edamame_y)) #drawing the text foodText = textFont.render('Did you eat well today?', True, WHITE) foodRect = pg.Surface((550, 75)) foodRect.set_alpha(100) foodRect.fill(BLACK) screen.blit(foodRect, (150, HEIGHT - 400)) screen.blit(foodText, (150, HEIGHT - 400)) #drawing the character currPet.draw(screen) #other buttons and stuff backButton.draw() backButton.draw_text("Back") elif currGameState == Screen.MEDITATION: sleepBG.animate(screen) backButton.draw() backButton.draw_text("Back") meditate.setOn() elif currGameState == Screen.AFFIRMATIONS: sleepBG.animate(screen) backButton.draw() backButton.draw_text("Back") affirmations.run() elif currGameState == Screen.LOGSLEEP: sleepBG.animate(screen) backButton.draw() backButton.draw_text("Back") sleep_checkin_button.draw() sleep_checkin_button.draw_text("CHECK IN") sleep_question_button.draw() sleep_question_button.draw_text("Have you slept recently?") elif currGameState == Screen.LOGSLEEP_ACTIVE: sleepBG.animate(screen) backButton.draw() backButton.draw_text("Back") sleep_response_button.draw() sleep_response_button.draw_text( "Thank you for keeping us both healthy!") currPet.draw(screen) # meditate.setOn() pg.display.update() clock.tick(FRAMERATE) for event in ev: if event.type == pg.QUIT: pg.quit() sys.exit() if event.type == pg.MOUSEBUTTONUP and event.button == 1: is_draggable = False on_pizza = False on_edamame = False on_fruitTart = False on_rice = False if event.type == pg.MOUSEMOTION: if is_draggable: m_x, m_y = event.pos #test for each image: if on_pizza: pizza_x = m_x + offset_x pizza_y = m_y + offset_y elif on_edamame: edamame_x = m_x + offset_x edamame_y = m_y + offset_y elif on_fruitTart: fruitTart_x = m_x + offset_x fruitTart_y = m_y + offset_y elif on_rice: rice_x = m_x + offset_x rice_y = m_y + offset_y if event.type == pg.MOUSEBUTTONDOWN and event.button == 1: if currGameState == Screen.Q_A: currGameState = Screen.Q_A1 if currGameState.value > Screen.HATCH.value: savefile.close() update_save() savefile = open(os.getcwd() + "/save/saveFile.txt", 'a+') mouse = pg.mouse.get_pos() if currGameState == Screen.STARTING: currGameState = Screen.SELECTION elif newGameButton.getImageRect().collidepoint( mouse) and currGameState == Screen.SELECTION: open(os.getcwd() + "/save/saveFile.txt", 'w').close() currGameState = Screen.Q_A elif continueGameButton.getImageRect().collidepoint( mouse) and currGameState == Screen.SELECTION: lines = open(os.getcwd() + "/save/saveFile.txt", "r").read().splitlines() if len(lines) > 5: savePetType = lines[0] if savePetType.__contains__("GIF"): currPet = Pet.init_gifImage(lines[0], lines[1]) else: currPet = Pet(lines[0], lines[1]) currPet.food = float(lines[2]) currPet.water = float(lines[3]) currPet.sleep = float(lines[4]) currPet.stress = float(lines[5]) dtimeT = (init_time - datetime.datetime.strptime( lines[6], "%Y-%B-%d %I:%M:%S.%f")) dtime = dtimeT.seconds currPet.food += FOOD_CHANGE_RATE * dtime * FRAMERATE currPet.water += WATER_CHANGE_RATE * dtime * FRAMERATE currPet.sleep += SLEEP_CHANGE_RATE * dtime * FRAMERATE currPet.stress += STRESS_CHANGE_RATE * dtime * FRAMERATE currGameState = Screen.HOME currPet.setCoords(WIDTH / 2, HEIGHT / 2) else: print("Save game not found") open(os.getcwd() + "/save/saveFile.txt", 'w').close() currGameState = Screen.Q_A elif qa1LeftButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A1: petSum += 1 currGameState = Screen.Q_A2 elif qa1MiddleButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A1: petSum += 2 currGameState = Screen.Q_A2 elif qa1RightButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A1: petSum += 3 currGameState = Screen.Q_A2 elif qa2LeftButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A2: petSum += 1 currGameState = Screen.Q_A3 elif qa2MiddleButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A2: petSum += 2 currGameState = Screen.Q_A3 elif qa2RightButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A2: petSum += 3 currGameState = Screen.Q_A3 elif qa3LeftButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A3: petSum += 1 currGameState = Screen.Q_A4 elif qa3MiddleButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A3: petSum += 2 currGameState = Screen.Q_A4 elif qa3RightButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A3: petSum += 3 currGameState = Screen.Q_A4 elif qa4LeftButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A4: petSum += 1 currGameState = Screen.HATCH elif qa4MiddleButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A4: petSum += 2 currGameState = Screen.HATCH elif qa4RightButton.getImageRect().collidepoint( mouse) and currGameState == Screen.Q_A4: petSum += 3 currGameState = Screen.HATCH elif currGameState == Screen.HATCH: currGameState = Screen.HOME currPet.setCoords(WIDTH / 2, HEIGHT / 2) elif backButton.getImageRect().collidepoint(mouse) and ( currGameState is Screen.FOOD or currGameState is Screen.WATER or currGameState is Screen.WATER_ACTIVE or currGameState is Screen.SLEEP or currGameState is Screen.FUN): currGameState = Screen.HOME currPet.setCoords(WIDTH / 2, HEIGHT / 2) elif sleepMeditateButton.getImageRect().collidepoint( mouse) and currGameState == Screen.SLEEP: currGameState = Screen.MEDITATION elif sleepAffirmationsButton.getImageRect().collidepoint( mouse) and currGameState == Screen.SLEEP: currGameState = Screen.AFFIRMATIONS elif sleepLogButton.getImageRect().collidepoint( mouse) and currGameState == Screen.SLEEP: currGameState = Screen.LOGSLEEP elif backButton.getImageRect().collidepoint(mouse) and ( currGameState is Screen.FOOD or currGameState is Screen.WATER or currGameState is Screen.SLEEP or currGameState is Screen.FUN or currGameState is Screen.SHOWER or currGameState is Screen.SHOWER_TWO or currGameState is Screen.SHOWER_DONE): currGameState = Screen.HOME elif backButton.getImageRect().collidepoint(mouse) and ( currGameState is Screen.MEDITATION or currGameState is Screen.AFFIRMATIONS or currGameState is Screen.LOGSLEEP or currGameState is Screen.LOGSLEEP_ACTIVE): currPet.sleep = currPet.sleep + 20 currGameState = Screen.SLEEP elif sleep_checkin_button.getImageRect().collidepoint( mouse) and currGameState == Screen.LOGSLEEP: currGameState = Screen.LOGSLEEP_ACTIVE elif currGameState == Screen.HOME: if HomeFoodButton.getImageRect().collidepoint(mouse): currGameState = Screen.FOOD elif HomeWaterButton.getImageRect().collidepoint(mouse): currGameState = Screen.WATER elif HomeSleepButton.getImageRect().collidepoint(mouse): currGameState = Screen.SLEEP elif HomeStressButton.getImageRect().collidepoint(mouse): currGameState = Screen.SHOWER elif exitButton.getImageRect().collidepoint(mouse): update_save() pg.quit() if sys.platform.startswith('linux'): os.system("sudo shutdown -h now") sys.exit() elif currGameState == Screen.WATER: if checkin_button.getImageRect().collidepoint(mouse): water_drop1.getImageRect().center = (random.randint( 100, WIDTH - 100), random.randint(100, HEIGHT - 100)) water_drop2.getImageRect().center = (random.randint( 100, WIDTH - 100), random.randint(100, HEIGHT - 100)) currGameState = Screen.WATER_ACTIVE currPet.setCoords(WIDTH / 2, HEIGHT / 2) water_exists1 = True water_exists2 = True elif currGameState is Screen.WATER_ACTIVE: if water_drop1.getImageRect().collidepoint( mouse) and water_exists1: currPet.water += 12 if currPet.water > 100: currPet.water = 100 water_exists1 = False elif water_drop2.getImageRect().collidepoint( mouse) and water_exists2: currPet.water += 12 if currPet.water > 100: currPet.water = 100 water_exists2 = False elif currGameState == Screen.SHOWER: if shower_response_button.getImageRect().collidepoint( mouse): currGameState = Screen.SHOWER_TWO elif currGameState == Screen.SHOWER_TWO: currPet.stress -= 25 if currPet.stress < 0: currPet.stress = 0 currGameState = Screen.SHOWER_DONE elif currGameState == Screen.FOOD: #we have currPet: and pizza, edamame, rice, fruitTart if pizza.get_rect().collidepoint(mouse): is_draggable = True on_edamame = False on_fruitTart = False on_rice = False on_pizza = True m_x, m_y = event.pos offset_x = pizza.get_rect().x - m_x offset_y = pizza.get_rect().y - m_y elif edamame.get_rect().collidepoint(mouse): is_draggable = True on_edamame = True on_fruitTart = False on_rice = False on_pizza = False m_x, m_y = event.pos offset_x = edamame.get_rect().x - m_x offset_y = edamame.get_rect().y - m_y elif rice.get_rect().collidepoint(mouse): is_draggable = True on_edamame = False on_fruitTart = False on_rice = True on_pizza = False m_x, m_y = event.pos offset_x = rice.get_rect().x - m_x offset_y = rice.get_rect().y - m_y elif fruitTart.get_rect().collidepoint(mouse): is_draggable = True on_edamame = False on_fruitTart = True on_rice = False on_pizza = False m_x, m_y = event.pos offset_x = fruitTart.get_rect().x - m_x offset_y = fruitTart.get_rect().y - m_y
init_time = datetime.datetime.strptime( datetime.datetime.now().strftime("%Y-%B-%d %I:%M:%S.%f"), "%Y-%B-%d %I:%M:%S.%f") titleFont = pg.font.Font(os.getcwd() + "/VT323-Regular.ttf", 180) textFont = pg.font.Font(os.getcwd() + "/VT323-Regular.ttf", 60) smallFont = pg.font.Font(os.getcwd() + "/VT323-Regular.ttf", 40) # pg.mixer.init() pg.mixer.music.load('Bitbasic_-_01_-_An_opener.ogg') pg.mixer.music.play(-1) screen = pg.display.set_mode((WIDTH, HEIGHT), 0, 32) affirmations = Affirmations(screen) currGameState = Screen.STARTING currPet = Pet.init_gifImage(PetType.BALAGIF, "bala") words = "" def update_save(): global currPet global currGameState savefile = open(os.getcwd() + "/save/saveFile.txt", "w+") savefile.write(str((currPet.petType)) + "\n") savefile.write(currPet.name + "\n") savefile.write(str(currPet.food) + "\n") savefile.write(str(currPet.water) + "\n") savefile.write(str(currPet.sleep) + "\n") savefile.write(str(currPet.stress) + "\n") savefile.write( str(datetime.datetime.now().strftime("%Y-%B-%d %I:%M:%S.%f")) + "\n")
def run(self): # display vet record! print("Displaying current Pet record \n_________________________________________________") lisa = Owner("Lisa", "1 Street St, Burlington VT", 8021234567) fifi = Pet("Fifi", "Feline", "Persian", 2, lisa) fifi.addVetRecord(VetRecord("1st January 2020", " In 6 months", "Dr.DoLittle", "Threw up food")) fifi.addVetRecord(VetRecord("2nd March 2020", " In 1 month", "Dr.DoLittle", "Ate trash")) self.vet.addPetRecord(fifi) if (len(self.vet.petRecords)) == 0: print("There is no pet record to show") else: self.vet.displayPetRecords() print("Took in a kitten up for adoption") dracula = Pet("Dracula", "Feline", "Domestic Shorthair", 4) self.vet.addPetRecord(dracula) dracula.addVetRecord(VetRecord("4th April 2020", "In one month", "Dr.DoLittle", "check-up")) print("Found a stray pug \n \nDisplaying pet records now") fluffy = Pet("Fluffy", "Canine", "Pug", 2) self.vet.addPetRecord(fluffy) fluffy.addVetRecord(VetRecord("4th April 2020", "In one month", "Dr.Nancy", "General check-up")) # display vet record! if (len(self.vet.petRecords)) == 0: print("There is no pet record to show") else: self.vet.displayPetRecords() print("Lisa comes in with her cat Fifi for a visit ") if self.vet.findPet("Fifi") == None: print("Cannot find pet record. Does not exist in database") else: self.vet.findPet("Fifi").getVetRecord() #setting pet record for today's visit fifi.addVetRecord(VetRecord("04th April 2020", " In 6 months", "Dr.DoLittle", "Check-Up")) print("\nLisa adopts dracula") lisa.adoptPet(dracula, lisa) print("Lisa adopts fluffy\n") lisa.adoptPet(fluffy, lisa) print("Displaying Lisa's pets") if len(lisa.pets) == 0: print("Lisa has no pets to show") else: lisa.getPets()
def main(): pygame.init() screen = Display() tamagotchi = Pet(screen.display) menu = Menu(tamagotchi, screen.display) frameCount = 0 screen.display.fill((255, 255, 255)) screen.update() menu.displayButtons() running = True # GAME LOOP while running: # EVENTS HANDLING for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: x, y = event.pos # reset if ((500 <= x <= 600) and (600 <= y <= 700)): pygame.draw.rect(screen.display, (255, 255, 255), (0, 100, 700, 500)) tamagotchi = Pet(screen.display) menu.tamagotchi = tamagotchi print("RESET") menu.handleMouse(x,y) # POOPING if frameCount % 1000 == 999: rand = random.randint(0, 2) if rand == 1: tamagotchi.poop() # LOWERING HYGIENE if tamagotchi.pooCounter > 0: if frameCount % 50 == 0: if tamagotchi.hygiene < 30: tamagotchi.ill = 1 if tamagotchi.hygiene <= 0: tamagotchi.hygiene = 0 else: tamagotchi.hygiene -= 1 * tamagotchi.pooCounter # HUNGER (LOWERING FOOD) if frameCount % 70 == 0: if(tamagotchi.food > 0): tamagotchi.food -= 1 else: tamagotchi.food = 0 if(tamagotchi.food < 20): tamagotchi.health -= 1 # BOREDOM (LOWERING HAPPINESS) if frameCount % 80 == 0: if tamagotchi.happiness > 0: tamagotchi.happiness -= 1 else: tamagotchi.happiness = 0 # ILLNESS if tamagotchi.ill == 1: screen.blit(tamagotchi.illness, (80, 200)) pygame.display.update((80, 200), (120, 120)) if frameCount % 100 == 0: tamagotchi.health -= 1 # HEALTH if tamagotchi.health < 0: tamagotchi.health = 0 # DEATH if tamagotchi.health <= 0: if tamagotchi.death == 0: tamagotchi.animationFrame = 0 tamagotchi.currentAnimation = "death" tamagotchi.death = 1 # PRINT TAMAGOTCHI VARIABLES if frameCount % 20 == 0: print("energy:"+str(tamagotchi.energy)) print("food:"+str(tamagotchi.food)) print("happiness:"+str(tamagotchi.happiness)) print("hygiene:"+str(tamagotchi.hygiene)) print("health:"+str(tamagotchi.health)) print("sad:"+str(tamagotchi.sad)) print("ill:"+str(tamagotchi.ill)) print("death:"+str(tamagotchi.death)) # DISPLAYING TAMAGOTCHI ANIMATIONS tamagotchi.animate() frameCount += 1 screen.fpsClock.tick(screen.FPS)
def addPet(self,name,species='snail'): self._pets.append(Pet(name,species))
def __init__(self, name, age, breed): self._breed = breed Pet.__init__(self, name, age)
def show(self): Pet.show(self) print("color=%s" % self.color)
def __init__(self, name, age): Pet.__init__(self, name, age)
def __init__(self, name, color): Pet.__init__(self, name, 'Dog') #super(Dog, self).__init__(name,'Dog') #super().__init__(name,'Dog') self.color = color
def newPet(petName): newPet = Pet(petName.replace(' ', '_'), 0, 50, 20, 20, 0, int(time.time()), int(time.time())) return newPet
class PetController(): def __init__(self): #Initialize Window, without putting a value in it yet self.window = None self.view = PetView(self.window) self.model = Pet("Honey Badger") # This queue's actions so that two threads don't try to access something at the same time self.request_queue = queue.Queue() self.result_queue = queue.Queue() # Adding buttons/Controls to the View window # TODO: Use Lambdas instead of wrapper functions ttk.Button(self.view.mainframe, text="Feed", name="feed", command= lambda: self.submitAction(self.feed)).grid(column=2, row=4) ttk.Button(self.view.mainframe, text="Play", name="play", command= lambda: self.submitAction(self.play)).grid(column=2, row=5) ttk.Button(self.view.mainframe, text="Clean", name="clean", command= lambda: self.submitAction(self.clean)).grid(column=2, row=6) # --------------------------THREADING CODE ------------------------------------------ # # Remember this? - Copied and Pasted # Thread main is where all the work will get done. def submitAction(self, action, *arguments, **keyWordArguments): self.request_queue.put((action, arguments, keyWordArguments)) print(action) print("submitted successfully") return self.result_queue.get() def threadmain(self): def timertick(): try: action, arguments, keyWordArguments = self.request_queue.get_nowait() except queue.Empty: pass else: print("something in queue") print("Hunger: "+str(self.model.hunger)) print("Happiness: "+str(self.model.happiness)) print("Cleanliness: "+str(self.model.cleanliness)) retval = action(*arguments, **keyWordArguments) self.result_queue.put(retval) self.window.after(500, timertick) self.window = tk.Tk() timertick() self.window.mainloop() # -------------------------/THREADING CODE ------------------------------------------ # # Actions to be performed by the controller def feed(self): if self.model.hunger > 10: self.model.hunger += self.model.hungerRate def play(self): if self.model.hunger > 0: if self.model.happiness < 10: self.model.hunger -= 1 self.model.happiness += 1 def clean(self): if self.model.cleanliness > 0: self.model.cleanliness -= 1 # Actions on timer def feedDecay(self): if self.model.hunger > 0: self.model.hunger -= 1 def happinessDecay(self): if self.model.happiness > 0: self.model.happiness -= 1 def cleanDecay(self): if self.model.cleanliness > 0: self.model.cleanliness -= 1 def update(self): self.feedDecay() self.happinessDecay() self.cleanDecay() def updateValues(self): # Set variables for the UI self.view.petHunger.set(self.model.getHunger()) self.view.petHappiness.set(self.model.getHappiness()) self.view.petCleanliness.set(self.model.getCleanliness()) # END OF SETTING IT UP def run(self): thread.start_new_thread(self.threadmain, ()) secondsPassed = 0 while True: secondsPassed += 1 self.submitAction(self.update) self.submitAction(self.updateValues) sleep(1)
def setUp(self): self.pet = Pet('kitten', Character('owner', 30, 'w', House()))
class MyGlobals(object): # -------------Дисплей и основное---------- display_width = 950 display_height = 586 display = pygame.display.set_mode((display_width, display_height)) display_fps = 60 font_type_text = "images/pixelsh.ttf" default_pos_pic = (0, 0) fps = pygame.time.Clock() # ------------Иконка игры------------------ icon = pygame.image.load("images/icon.png") # --------------Питомец------------------- cat_width = 230 cat_height = 192 cat = Pet(100, 100, 100, 100, 106, 5) cat_x = display_width // 8 cat_y = display_height - cat_height title = "Mew Game" cat_hunger_loss = 0.001 cat_sleep_loss = 0.01 cat_health_loss = 0.003 cat_max_stats = "100" default_cat_name = "Mew" min_stats = 6 stats_loss_divider = 10 # -----------Флаг isempty------------------ isempty = False # ----------Загрузка спрайтов кнопок------- but_ac = pygame.image.load("images/button/but_inact.png") but_in = pygame.image.load("images/button/but_in.png") but_cl = pygame.image.load("images/button/but_act.png") gameover = pygame.image.load("images/button/button_start.png") menu = pygame.image.load("images/button/but_menu.png") menu_button = pygame.image.load("images/button/button_menu_lofi.png") # ---------Константы для кнопок------------- text_indent_btn_x = 20 text_indent_btn_y = -5 btn_width = 100 btn_height = 38 btn_x_in_game = 10 btn_y_in_game = 40 btn_y_indent = 50 button_start_x = 20 button_start_y = 80 button_replenishment = 5 btn_mult_y_in_game = 12.5 btn_mult_x_in_game = 27 btn_healt_mult_y = 2 button_click_left = 1 btn_health_inscription = "Heal" btn_sleep_inscription = "Sleep" btn_food_inscription = "Food" btn_next_inscription = "Next" btn_prev_inscription = "Prev" btn_start_inscription = "Start" mouse_get_pressed_state = 3 # ----Загрузка спрайтов для анимации кота--- cat_sit = [ pygame.image.load("images/cat_sprites/sit_col/" + "sit_" + str(i) + ".png") for i in range(1, 9) ] death = [ pygame.image.load("images/cat_sprites/dead/dead_" + str(i) + ".png") for i in range(1, 9) ] # -----Загрузка спрайтов для анимации фона--- bg_lofi = [ pygame.image.load("images/bg/lofi_bg/" + str(i) + ".png") for i in range(1, 61) ] bg_menu = [ pygame.image.load("images/bg/menu_bg/" + str(i) + ".png") for i in range(1, 89) ] # ----------Загрузка музыки и звуков---------- bg_music = [ os.path.join(d, f) for d, dirs, m_files in os.walk("sounds/music") for f in m_files ] mew_1 = "sounds/cat/mew_1.wav" mew_2 = "sounds/cat/mew_2.wav" mrr = "sounds/cat/mrr.wav" eat = "sounds/cat/eat.mp3" menu_track = "sounds/Nuver Its getting late.mp3" # -----------Количество треков----------------- tracks_number = len(bg_music) current_track = 0 # --------Пользовательские события------------- NEXT = pygame.USEREVENT + 1 PREV = pygame.USEREVENT - 1 # ----------Звуковые каналы-------------------- channel1 = 0 channel2 = 1 sounds_volume = 0.2 music_volume = 0.5 # -----------------Цвета----------------------- BlACK = (0, 0, 0) EGGPLANT = (43, 0, 92) PERIWINKLE = (158, 91, 172) DARK_PURPLE = (135, 0, 148) DOVE = (52, 14, 18) SYRUP = (108, 90, 106) # ----------------Конфигурация текста---------- font_size_in_menu = 15 text_x_in_menu = 377 text_y_in_menu = 50 text_x_indent_in_menu = 3 text_y_indent_in_menu = 30 text_x_stats = 587 text_y_stats = 50 text_x_indent = 5 text_y_indent = 40 font_size_gameover = 30 cat_name_x_gameover = 470 cat_name_y_gameover = 150 cat_name_y_indent_gameover = 40 text_x_gameover_dead = 217 text_x_gameover_death_reason = 417 text_x_gameover_close = 260 main_font_size = 25 input_text_x = 382 input_text_indent_x = 3 input_text_y = 110 input_text_bg = (52, 14, 18) input_text_fd = (117, 65, 71) input_text_size = 20 music_font_size = 10 music_font_pos = 545 music_text_crop_l = 1 music_text_crop_r = -4 input_text_crop = -1 text_mult_y_died = 10 text_mult_y_died_stats = 2 text_mult_y_died_stats_3 = 3 sleep_loss_mult = 2 health_loss_mult = 1.8 # -----------Конфигурация анимации-------------- bg_lofi_deceleration = 4 bg_menu_deceleration = 49 cat_deceleration = 11 cat_dead_indent_x = -5 cat_dead_indent_y = 40 gameover_pos = (80, 80) # -----------Файл со статами--------------------- stats_file_name = "stats.txt" stat_time = "time" stat_food = "food" stat_sleep = "sleep" stat_health = "health" stat_happy = "happy" stat_name = "name" need_input = False input_text = "" stats = { stat_time: "", stat_food: "", stat_sleep: "", stat_happy: "", stat_health: "", stat_name: "" } temp_stats_keys_list = list(stats.keys())
def main(): energy = 58 energyPerGame = 10 pet = Pet(energy, energyPerGame) pet.train()