Exemple #1
0
 def guess_lower(self):
     """User has guessed the next card is higher."""
     last_card = self.last_card
     next_card = self.get_next_card()
     if next_card.to_int() < last_card.to_int():
         output_string = (
             "Your {} card is {}, which is lower! Congrats! Do you think the next card will "
             "be higher or lower?".format(Commons.ordinal(self.turns),
                                          next_card.to_string()))
         return output_string
     if next_card.to_int() == last_card.to_int():
         output_string = (
             "Your {} card is {}, which is the same (that's fine.) Do you think the next card will "
             "be higher or lower?".format(Commons.ordinal(self.turns),
                                          next_card.to_string()))
         return output_string
     if next_card.to_int() > last_card.to_int():
         self.lost = True
         # high scores
         is_high_score = self.check_high_score()
         previous_score_text = ""
         if is_high_score:
             previous_score = self.high_scores_obj.get_high_score(
                 self.HIGH_SCORE_NAME)
             previous_score_text = "(previous highscore was: {}, set by {} {}.)".format(
                 previous_score["score"],
                 previous_score["player"],
                 Commons.format_unix_time(previous_score["date"]),
             )
             self.update_high_score()
         # Output message
         output_string = "Your {} card is {}. Sorry, that's higher, you lose.".format(
             Commons.ordinal(self.turns), next_card.to_string())
         if is_high_score:
             output_string += " You managed {} cards though, that's a new highscore!{}".format(
                 self.turns - 1, previous_score_text)
         else:
             output_string += " You managed {} cards though.".format(
                 str(self.turns - 1))
         return output_string
Exemple #2
0
 def passive_trigger(self, evt):
     if not isinstance(evt, EventMessage):
         return
     if not evt.text.lower().startswith("dream"):
         return
     data_date = evt.get_send_time().date()
     dream_text = evt.text
     new_dream = {"text": dream_text}
     dream_data = self.load_data(data_date)
     if dream_data is None:
         dream_data = {"dreams": []}
     dream_data["dreams"].append(new_dream)
     dream_count = len(dream_data["dreams"])
     self.save_data(dream_data, data_date)
     # Send date to destination
     dream_ordinal = Commons.ordinal(dream_count)
     self.message_channel(
         "Logged dream. {} of the day.".format(dream_ordinal))
Exemple #3
0
def test_ordinal(number, ordinal):
    assert Commons.ordinal(number) == ordinal