def is_any_animal(self): if not An.is_any_animal(): self.switch_frame(AnimalGuessPage) elif not An.is_any_question(): self.switch_frame(NoQuestionGuessPage) else: self.switch_frame(QuestionPage)
def add_animal(self, name, diet, size, landwater, special, pattern, patterntype): self.can_add = True if not name: messagebox.showwarning("Hata !", "Hayvanın ismini yazın.") if diet not in An.question_answers["diet"]: messagebox.showwarning("Hata !", "Beslenme şeklini menüsünden seçin.") if size not in An.question_answers["size"]: messagebox.showwarning("Hata !", "Büyüklüğünü menüsünden seçin.") if landwater not in An.question_answers["landwater"]: messagebox.showwarning( "Hata !", "Karada mı suda mı yaşadığını menüsünden seçin.") else: if not special: special = "None" if name in An.raw_animal_names: response = messagebox.askyesno( "Dikkat !", "{} hayvanı zaten var. Onun yerine eklemek ister misin?". format(name)) self.can_add = response if self.can_add: An.add_animal(name, diet, size, landwater, special, pattern, patterntype) messagebox.showinfo("", "{} hayvanı eklendi.".format(name)) self.switch_frame(SpecialFuncsPage)
async def animal(ctx, name): await ctx.message.delete() animal = Animals(name) try: await ctx.send(animal.image()) except: await ctx.send("we dont have that animal :(")
def __init__(self, master): tk.LabelFrame.__init__(self, master) self.sorry_frame = tk.Frame(self) self.sorry_frame.pack(fill="both", expand=True) if not An.is_any_question(): self.sorry_lbl = tk.Label( self.sorry_frame, text= "Üzgünüm, bu özellikte bir hayvan bulamadım ve başka sorum kalmadı.\n\nŞimdi napalım ?" ) self.sorry_lbl.pack(pady=100) else: self.sorry_lbl = tk.Label( self.sorry_frame, text= "Üzgünüm, bu özellikte bir hayvan bulamadım.\n\nBaşka soruya geçelim bakalıımm..." ) self.sorry_lbl.pack(pady=100) self.pass_btn_frame = tk.Frame(self) self.pass_btn_frame.pack(fill="y", expand=True) if not An.is_any_question(): self.guess_btn = tk.Button( self.pass_btn_frame, text="Tahmin et", padx=10, pady=10, command=lambda: master.switch_frame(AnimalGuessPage)) self.restart_btn = tk.Button(self.pass_btn_frame, text="Yeniden Oynayalım", padx=10, pady=10, command=lambda: master.restart()) self.exit_btn = tk.Button( self.pass_btn_frame, text="Çık", padx=10, pady=10, command=lambda: master.switch_frame(ExitPage)) self.guess_btn.pack(side=tk.LEFT, padx=10) self.restart_btn.pack(side=tk.LEFT, padx=10) self.exit_btn.pack(side=tk.LEFT, padx=10) self.guess_btn.focus() else: self.pass_btn = tk.Button( self.pass_btn_frame, text="Yeni soruya geç", padx=10, pady=10, command=lambda: master.switch_frame(QuestionPage)) self.pass_btn.pack() self.pass_btn.focus()
def __init__(self, name, age): Animals.__init__(self, name, age, race) self.race = 'Chien' self.name = name self.age = age self.live = True self.weight = 20 self.eat = 50 self.drink = 50 self.sleep = 50
def answer_normal(self, answer, question): # diğer soruların cevabı test ediliyor self.last_question = question self.last_answer = answer if not An.is_any_animal: self.switch_frame(AnimalGuessPage) An.answer_normal(answer, question) if question in An.question_names: An.question_names.remove(question) self.switch_frame(AnimalGuessPage)
def feature_to_animals(self, feature): animal = An.raw_animal_names[self.animal_number] if feature == "": An.raw_animals[animal][self.feature_to_add] = "None" else: An.raw_animals[animal][self.feature_to_add] = feature self.animal_number += 1 if self.animal_number == len(An.raw_animal_names): An.save_animals() messagebox.showinfo("Tamamlandı", "Tüm hayvanlara özellik eklendi.") self.switch_frame(SpecialFuncsPage) else: self.switch_frame(AddFeatureToAnimalsPage)
def __init__(self): tk.Tk.__init__(self) self.title("Hayvan Tahmin Oyunu") # Animal Guess Game self.iconbitmap("pati.ico") # oyunun ikonu pati self.protocol("WM_DELETE_WINDOW", self.exit_or_not) # çarpıya basıldığında çalışır self.geometry("{}x{}+{}+{}".format(self.width, self.height, self.center_width, self.center_height)) An.load_animals() An.load_animal_names() self._frame = None self.switch_frame(StartPage)
def change_or_not(self, animal, feature, new_feature): if animal == "animal": # hayvan seçilmediyse, messagebox.showwarning("Hata !", "Bir Hayvan Seçin.") elif feature == "feature": # özellik seçilmediyse, messagebox.showwarning("Hata !", "Bir Özellik Seçin.") # girilen özellik girilebilicek özelliklerde yoksa hata verir elif (feature not in [ "special", "pattern", "patterntype" ]) and (new_feature not in An.question_answers[feature]): messagebox.showwarning( "Hata !", "Şu özelliklerden birini yazın:{}.".format( An.question_answers[feature])) else: # hayvanın özelliğini değiştir ve kaydet An.change_feature(animal, feature, new_feature) self.switch_frame(SpecialFuncsPage)
def answer_special(self, answer): # bilindik özellik cevabı test ediliyor dont_know = An.answer_special(answer) An.question_names.remove("special") if dont_know: self.switch_frame(NoSpecialPage) else: self.switch_frame(AnimalGuessPage)
async def some_cat(msg: types.Message): what_we_want = msg.text.lower() try: if what_we_want == "котик": await types.ChatActions.upload_photo() cat = Animals.give_me_a_cat() cat_n_caption = types.MediaGroup() cat_n_caption.attach_photo(cat[0], cat[1]) await msg.reply_media_group(media=cat_n_caption) if what_we_want == "собачка": await types.ChatActions.upload_photo() dog = Animals.give_me_a_dog() dog_n_caption = types.MediaGroup() dog_n_caption.attach_photo(dog[0], dog[1]) await msg.reply_media_group(media=dog_n_caption) except Exception as some_error: print(some_error) await msg.reply(text("Что-то пошло не так...\nПопробуйте снова!"))
async def inline_echo(iq_iq: InlineQuery): result_id = random.uniform(0, 2384723684723684) catt = Animals.give_me_a_cat() cat = InlineQueryResultPhoto(id=result_id, photo_url=catt[0], thumb_url=catt[0], title="😺", caption=catt[1]) await BOT.answer_inline_query(iq_iq.id, results=[cat], cache_time=1)
class TestAnimal(unittest.TestCase): def setUp(self): self.panda = Animals("Pandio", 48, "panda", "male", 245) def test_init(self): self.assertEqual(self.panda.name, "Pandio") self.assertEqual(self.panda.age, 48) self.assertEqual(self.panda.species, "panda") self.assertEqual(self.panda.gender, "male") self.assertEqual(self.panda.weight, 245) def test_get_name(self): panda2 = Animals("Diva_Panda", 24, "panda", "female", 190) self.assertEqual(panda2.name, "Diva_Panda") tiger = Animals("Pesho", 26, "tiger", "male", 170) self.assertEqual(tiger.name, "Pesho") def test_grow(self): self.panda.grow() self.assertEqual(self.panda.weight, 260)
def restart(self): # oyunu yeniden başlat An.load_animals() An.load_animal_names() An.reload_questions() self.last_question = "" self.last_answer = "" self.switch_frame(QuestionPage)
def mainmenu(self): # ana menüye dön An.load_animals() An.load_animal_names() An.reload_questions() self.last_question = "" self.last_answer = "" self.switch_frame(StartPage)
def check_to_del(self, animal): if animal == "animal": messagebox.showwarning("Hata !", "Bir Hayvan Seçin.") else: response = messagebox.askyesno( "Dikkat!", "{} hayvanını silmek istediğine emin misin ?".format(animal)) if response: An.del_animal(animal) An.save_animals() An.reload_animals() messagebox.showinfo("", "{} hayvanı silindi.".format(animal)) self.switch_frame(DelAnimalPage)
def __init__(self, name, age): Animals.__init__(self, name, age) self.race = 'Fox' self.rabbit = 0
def main(): crocodile = Animals('крокодил', 'зеленый', '22') crocodile.get_info() num = Numbers() num.info()
async def animal(ctx, name): await ctx.message.delete() animal = Animals(name) await ctx.send(animal.image())
def setUp(self): self.panda = Animals("Pandio", 48, "panda", "male", 245)
def __init__(self, master): tk.LabelFrame.__init__(self, master) self.restart_frame = tk.Frame(self) self.restart_frame.pack(fill="x") self.rstrt_btn = tk.Button(self.restart_frame, text="Baştan Başla", height=3, width=12, command=lambda: master.restart()) self.mainmenu_btn = tk.Button(self.restart_frame, text="Ana Menü", height=3, width=12, command=lambda: master.mainmenu()) self.rstrt_btn.pack(side=tk.LEFT, padx=10, pady=10) self.mainmenu_btn.pack(side=tk.RIGHT, padx=10, pady=10) try: # if there are animals, this will guess an animal self.guess = An.guess() self.guess_frame = tk.Frame(self) self.guess_frame.pack(fill="both", expand=True) self.guess_label = tk.Label( self.guess_frame, text="O zaman bence tuttuğun hayvaaannnn...") self.guess_label3 = tk.Label(self.guess_frame, text="Doğru mu Yanlış mı ?") self.guess_label2 = tk.Label(self.guess_frame, text="Bir {}".format(self.guess)) self.guess_answer_frame = tk.Frame(self) self.guess_answer_frame.pack(fill="y", expand=True) self.guess_yes_btn = tk.Button( self.guess_answer_frame, text="Doğru", padx=10, command=lambda: master.switch_frame(FinishPage)) self.guess_no_btn = tk.Button( self.guess_answer_frame, text="Yanlış", padx=10, command=lambda: master.wrong_guess(self.guess)) self.guess_label.pack(pady=40, side=tk.TOP) self.after(1000, self.guess_is) self.after(1500, self.correct_or_not) except: # to NoAnimalPage self.finish_frame = tk.Frame(self) self.finish_frame.pack(fill="both", expand=True) self.finish_lbl = tk.Label( self.finish_frame, text="Üzgünüm, böyle bir hayvan bulamadım.\n\nŞimdi napalıım ?" ) self.finish_lbl.pack(side=tk.BOTTOM) self.finish_btn_frame = tk.Frame(self) self.finish_btn_frame.pack(fill="y", expand=True) self.restart_btn = tk.Button(self.finish_btn_frame, text="Yeniden Oynayalım", padx=10, pady=10, command=lambda: master.restart()) self.exit_btn = tk.Button( self.finish_btn_frame, text="Çık", padx=10, pady=10, command=lambda: master.switch_frame(ExitPage)) self.restart_btn.pack(side=tk.LEFT, padx=10) self.exit_btn.pack(side=tk.LEFT, padx=10) self.restart_btn.focus()
def __init__(self, master): tk.LabelFrame.__init__(self, master) if (master.last_question in An.linked_questions) and ( master.last_answer == An.question_answers[master.last_question][0]): self.question = An.linked_questions[master.last_question] else: self.question = An.choose_question() self.restart_frame = tk.Frame(self) self.restart_frame.pack(fill="x") self.rstrt_btn = tk.Button(self.restart_frame, text="Baştan Başla", height=3, width=12, command=lambda: master.restart()) self.mainmenu_btn = tk.Button(self.restart_frame, text="Ana Menü", height=3, width=12, command=lambda: master.mainmenu()) self.rstrt_btn.pack(side=tk.LEFT, padx=10, pady=10) self.mainmenu_btn.pack(side=tk.RIGHT, padx=10, pady=10) self.question_frame = tk.Frame(self) self.question_frame.pack(fill="x", expand=True) self.question_lbl = tk.Label(self.question_frame, text=An.questions[self.question], pady=30) self.question_lbl.pack(side=tk.BOTTOM) if self.question == "special": # seçilen soru special sorusuysa self.var = tk.StringVar() self.var.trace_variable( "w", self.validate) # anında düzeltme fonksiyonu çalışır self.answer_special_frame = tk.Frame(self, width=400) self.answer_special_frame.pack(expand=True) self.answer_special_lbl = tk.Label(self.answer_special_frame, text="Cevabınızı girin: ") self.answer_special_lbl.grid(row=0, column=0, padx=10) self.answer_special_entry = tk.Entry(self.answer_special_frame, textvariable=self.var, width=20) self.answer_special_entry.grid(row=0, column=1, padx=10) self.answer_special_entry.focus() # Enter self.answer_special_btn = tk.Button( self.answer_special_frame, text="Gir", padx=15, pady=5, command=lambda: master.answer_special(self.answer_special_entry .get())) self.answer_special_btn.grid(row=0, column=2, padx=10) else: # diğer sorularda self.answers_frame = tk.Frame(self, width=400) self.answers_frame.pack(expand=True) self.answer_no = 0 for answer in An.question_answers[self.question]: tk.Button(self.answers_frame, text=answer.title(), padx=10, pady=10, command=lambda answer=answer: master.answer_normal( answer, self.question)).grid( row=0, padx=10, column=self.answer_no) self.answer_no += 1 self.dont_know_frame = tk.Frame(self) self.dont_know_frame.pack(fill="both", expand=True) self.dont_know_btn = tk.Button( self.dont_know_frame, text="Bilmiyorum", padx=10, pady=10, command=lambda: master.switch_frame(DontKnowPage)) self.dont_know_btn.pack(pady=10)
def img1(): an = Animals('dog') return (an.image())
def discard_features(self): An.reload_animals() self.switch_frame(SpecialFuncsPage)