Skip to content

Commit

Permalink
Show the timer in binary if user succeeds 5 times
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-borges committed Jan 28, 2024
1 parent c7a8394 commit 0132f55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion level.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, question: str, difficulty: int):
self.difficulty = difficulty
self._amountOfObjects = random.randint(difficulty * 10 + 5, difficulty * 20 + 10)
self._initialTimer = 10
self.number_correct = 0

def start(self):
self._startLevelTime = int(time.time())
Expand Down Expand Up @@ -93,6 +94,7 @@ def __on_timeout(self):
return

def __on_correct_answer(self, all_objects: pg.sprite.Group) -> pg.sprite.Group:
self.number_correct += 1
return random.choice([Correct(all_objects),CorrectPicture(all_objects), DeadSheep(all_objects)]).execute()

def get_amount_of_objects(self) -> int:
Expand All @@ -103,10 +105,13 @@ def is_stopped(self) -> bool:

def get_question(self) -> str:
return self.question

def get_number_correct(self) -> int:
return self.number_correct

def reset(self):
self._startLevelTime: int = -1
self._stopLevelTime: int = -1
self.answer: str = ""
self._amountOfObjects = random.randint(self.difficulty * 10 + 5, self.difficulty * 20 + 10)
self.start()
self.start()
5 changes: 4 additions & 1 deletion main-window.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ def main():
timerColor=(0,0,0)
if timer <= 5:
timerColor=(255,0,0)
text = font.render(str(timer), True, timerColor)
timer_str = str(timer)
if currentLevel.number_correct > 4:
timer_str = str(bin(timer)[2:])
text = font.render(timer_str, True, timerColor)
textpos = text.get_rect(centerx=co.rb_topright[0], y=co.rb_topright[1] - 50)
screen.blit(text, textpos)

Expand Down

0 comments on commit 0132f55

Please sign in to comment.