Skip to content

Commit

Permalink
Corrected several bugs, especially with the timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
QaisAlrefai committed Dec 21, 2022
1 parent 27192fd commit 6dd9337
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions GuessTheNumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def __init__(self, parent):
self.Bind(wx.EVT_MENU, lambda ev: self.o.speak(self.ConvertSeconds(self.time), interrupt=True), self.IDRemainingTime)
self.Bind(wx.EVT_MENU, lambda ev: self.o.speak(self.ConvertSeconds(int(GameSettings["TryTime"])*60 - self.time), interrupt=True), self.IDElapsedTime)
self.Bind(wx.EVT_MENU, lambda ev: self.o.speak(F"{self.Instructions}.", interrupt=True), self.IDInstructions)
self.Bind(wx.EVT_MENU, lambda ev: self.o.speak(F"{self.Result}.", interrupt=True), self.IDResult)
self.Bind(wx.EVT_MENU, lambda ev: self.o.speak(F"{self.Result}", interrupt=True), self.IDResult)
self.Bind(wx.EVT_MENU, lambda ev: self.o.speak(F"You tryed {self.Tries} times.", interrupt=True), self.IDTries)
self.Bind(wx.EVT_MENU, lambda ev: self.o.speak(F"Remaining Trise: {self.RemainingTrise}.", interrupt=True), self.IDRemainingTrise)
self.Bind(wx.EVT_CLOSE, self.OnClose)
Expand Down Expand Up @@ -324,11 +324,14 @@ def OnPlay(self, ev):
self.Result = self.Failed
if GameSettings["Sounds"] == "True":
pywinmm.load("sounds/fail.wav").play()
self.o.speak(F"{self.CantTrye}! {self.Result}.", interrupt=True)
self.o.speak(F"{self.CantTrye}, {self.Result}", interrupt=True)
self.CurrentNumber.Value = ""
self.RandomNumber = self.RandomNumbers()
self.RemainingTrise = int(GameSettings["NumberTries"])
self.Tries = 0
self.time = int(GameSettings["TryTime"])*60
self.Instructions = F"In {self.ConvertSeconds(self.time)} and {self.RemainingTrise} Tries, try to find the correct number between {self.Min} and {self.Max}."
self.o.speak(F"{self.Instructions}", interrupt=False)
elif self.CurrentNumber.Value == self.RandomNumber:
self.Success =F"Well done, the correct number is {self.RandomNumber}, you found it in {Elapsed} and {self.Tries} tries."
self.Result = self.Success
Expand All @@ -340,20 +343,22 @@ def OnPlay(self, ev):
self.RandomNumber = self.RandomNumbers()
self.RemainingTrise = int(GameSettings["NumberTries"])
self.Tries = 0
self.Instructions = F"In {self.ConvertSeconds(self.time)} and {self.RemainingTrise} Tries, try to find the correct number between {self.Min} and {self.Max}."
self.o.speak(F"{self.Instructions}", interrupt=False)
elif self.CurrentNumber.Value < self.RandomNumber:
self.Greater = F"The correct number is greater than {self.CurrentNumber.Value}."
self.Result = self.Greater
if GameSettings["Sounds"] == "True":
pywinmm.load("sounds/error.wav").play()
self.o.speak(F"{self.Result}.", interrupt=True)
self.o.speak(F"{self.Result}", interrupt=True)
self.RemainingTrise -= 1
self.CurrentNumber.Value = ""
elif self.CurrentNumber.Value > self.RandomNumber:
self.Less = F"The correct number is less than {self.CurrentNumber.Value}."
self.Result = self.Less
if GameSettings["Sounds"] == "True":
pywinmm.load("sounds/error.wav").play()
self.o.speak(F"{self.Result}.", interrupt=True)
self.o.speak(F"{self.Result}", interrupt=True)
self.RemainingTrise -= 1
self.CurrentNumber.Value = ""

Expand All @@ -362,12 +367,19 @@ def OnPlay(self, ev):

def OnTimer(self, event):
if not self.time:
self.Result = self.Failed
self.Failed = F"Unfortunately, you failed to find the correct number, the correct number is {self.RandomNumber}."
self.Result = F"{self.TimeEnd}, {self.Failed}"
self.o.speak(F"{self.Result}", interrupt=False)
self.RandomNumber = self.RandomNumbers()
self.RemainingTrise = int(GameSettings["NumberTries"])
self.Tries = 0
self.time = int(GameSettings["TryTime"])*60
self.Instructions = F"In {self.ConvertSeconds(self.time)} and {self.RemainingTrise} Tries, try to find the correct number between {self.Min} and {self.Max}."
self.Info.SetLabel(self.Instructions)
self.o.speak(F"{self.Instructions}", interrupt=False)
if GameSettings["Sounds"] == "True":
pywinmm.load("sounds/fail.wav").play()
self.o.speak(F"{self.TimeEnd}, {self.Result}", interrupt=True)
self.CurrentNumber.Value = ""
self.time = int(GameSettings["TryTime"])*60
else:
self.time -= 1
self.Instructions = F"In {self.ConvertSeconds(self.time)} and {self.RemainingTrise} Tries, try to find the correct number between {self.Min} and {self.Max}."
Expand Down

0 comments on commit 6dd9337

Please sign in to comment.