Advertisement
gruntfutuk

flatmates

Mar 9th, 2023
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.84 KB | None | 0 0
  1. import random
  2. import time
  3. from dataclasses import dataclass, field
  4. import logging  # for debugging
  5. from typing import ClassVar
  6.  
  7. logging.basicConfig(level=logging.INFO, format='** DEBUGGING ** %(message)s')
  8.  
  9. DURATION = 1  # so you can set delay at top of code, don't want to wait when testing
  10.  
  11.  
  12. def sleep():
  13.     time.sleep(DURATION)
  14.  
  15.  
  16. @dataclass
  17. class Flatmate:
  18.     name: str
  19.     door: str
  20.     questions: tuple = field(default_factory=tuple)
  21.     intro: tuple = field(default_factory=tuple)
  22.     lives: ClassVar[int] = 3
  23.  
  24.     @classmethod
  25.     @property
  26.     def lives_left(cls):
  27.         return cls.lives > 0
  28.  
  29.     @classmethod
  30.     def change_lives(cls, change: int = -1):
  31.         cls.lives += change
  32.  
  33.     def ask_questions(self):
  34.         """ asks all questions and removes a life for each wrong anwswer """
  35.         if self.lives_left:
  36.             for question, answer in self.questions:
  37.                 logging.info(f"\nAnswer: {answer}\n")
  38.                 response = input(question + ": ").strip().casefold()
  39.                 if response != answer:
  40.                     self.change_lives(-1)
  41.                     print(f"Oops. Wrong answer. Lives left: {self.lives}.")
  42.                 if not self.lives_left:
  43.                     break  # no more questions!
  44.  
  45.     def greeting(self):
  46.         print("\n")
  47.         for line in self.intro:
  48.             print(line)
  49.             sleep()
  50.         print("\n")
  51.  
  52.  
  53. flatmates = (
  54.     Flatmate("Eline", "E",
  55.              (("birthday", "05/10/1997"),
  56.               ("colour", "green"),
  57.               ("meal", "pâtes champignons"),
  58.               ("film", "oss 117"),),
  59.              ("You knock on Eline's door.",
  60.               "*Elle fait pause a Koh-Lanta*",
  61.               "Qu'est-ce qu'il y a ? Ah, tu veux mon cadeau ? Eh bien, réponds à ces questions sur moi : ",)
  62.              ),
  63.     Flatmate("Louise", "L",
  64.              (("birthday", "08/10/1998"),
  65.               ("colour", "jaune"),
  66.               ("meal", "les pâtes grillées de mamie Pou"),
  67.               ("film", "30 ans sinon rien"),),
  68.              ("You knock on Louise's door.",
  69.               "*Elle apparaît, tenant un vaporisateur pour ses plantes.*",
  70.               "Je faisais de l'improvisation avec mes plantes ! Maintenant, tu dois improviser des réponses !",)
  71.              ),
  72.     Flatmate("Amir", "A",
  73.              (("birthday", "15/01/1994"),
  74.               ("colour", "vert"),
  75.               ("meal", "couscous"),
  76.               ("film", "les affranchis"),),
  77.              ("You knock on Amir's door.",
  78.               "*Les sons de la guitare s'arrêtent*",
  79.               "*Amir apparaît, couvert d'œufs*",
  80.               "Je m'amusais à mettre des œufs dans ma guitare, que veux-tu ? ",)
  81.              ),
  82.     Flatmate("Jonny", "J",
  83.              (("birthday", "27/08/1999"),
  84.               ("colour", "blue"),
  85.               ("meal", "sticky chicken"),
  86.               ("film", "her"),),
  87.              ("You knock on Jonny's door.",
  88.               "*The strange singing sounds stop*",
  89.               "Why hello there! I was singing some Louis Armstrong - did you hear? Come on then, answer my questions bruv.",)
  90.              )
  91. )
  92.  
  93. print('''
  94.                                  _H_              _H_               _H_                  o88o.
  95.          .=|_|===========v==|_|============v==|_|===========.    (8%8898),
  96.         /                |                 |                 \ ,(8888%8688)
  97.        /_________________|_________________|__________________(898%88688HJW)
  98.        |=|_|_|_|  =|_|_|=|X|)^^^(|X|=|/ \|=||_|_|_|=| ||_|_|=|`(86888%8%9b)
  99.        |=|_|_|_|== |_|_|=|X|\___/|X|=||_||=||_____|=|_||_|_|=|___(88%%8888)
  100.        |=_________= ,-. =|""""""""""="""""=|=_________== == =|_______\//`'
  101.        |=|__|__|_| //O\=|X|"""""|X|=//"\=|=|_|_|_|_| .---.=|.=====.||
  102.        |=|__|__|_|=|| ||=|X|_____|X|=|| ||=|=|_______|=||"||=||=====|||
  103.        |___d%8b____||_||_|=_________=||_||_|__d8%o%8b_=|j_j|=|j==o==j|\---
  104. ''')
  105.  
  106. sleep()
  107.  
  108. print("""Bienvenue. Each of your flatmates has a gift for you
  109. but you'll need to answer some questions first...""")
  110.  
  111. flatmates_to_visit = {flatmate.door: flatmate for flatmate in flatmates}
  112.  
  113. while Flatmate.lives_left and flatmates_to_visit:
  114.     print('\nFlatmates:\n\n  Door  Name')
  115.     print("  --------------------")
  116.     for door, flatmate in flatmates_to_visit.items():
  117.         print(f"  {door:^4}  {flatmate.name}")
  118.     print("  --------------------\n")
  119.     door = input("\nWhich door do you want to knock on? ").upper()
  120.     print()
  121.     if door in flatmates_to_visit:
  122.         flatmate = flatmates_to_visit[door]
  123.         flatmate.greeting()
  124.         flatmate.ask_questions()
  125.         del flatmates_to_visit[door]
  126.     else:
  127.         print("That's not even a door for one of your flatmates, dummy")
  128.  
  129. if Flatmate.lives_left:
  130.     print('Well done')
  131. else:
  132.     print('You do not know your friends well enough')
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement