### Merge branch 'master' of https://git.hacksaar.de/hacksaar/haxotel

parents 725ef739 ac59ffd9
 from npc import Npc from questionman import Questionman import random class Euclid(Questionman): def testQuestion(qpair): q,ac = qpair print(q) a = input("> ") print("Is correct: ",ac(a)) class Euclid (Npc): questions = [ questions = [ ("Imagine there is a circle. The origin and the point (4,0) are on the circle. The circle is symmetric with respect to the line x=y. Where is its center? ", lambda x: "2,2" in ("".join(x.split())).strip("()[]{}")), ("Imagine there is a circle. The origin and the point (4,0) are on the circle. The circle is symmetric with respect to the line x=y. Where is its center? ", lambda x: "2,2" in ("".join(x.split())).strip("()[]{}")), ("In a rectangular triangle, if the two shortest sides have lengths 3 meters and 4 meters, how long is the longest side?", lambda x: "5m" in ("".join(x.split())).replace("meters","m").replace("meter","m")), ("In a rectangular triangle, if the two shortest sides have lengths 3 meters and 4 meters, how long is the longest side?", lambda x: "5m" in ("".join(x.split())).replace("meters","m").replace("meter","m")), ... @@ -18,42 +10,11 @@ class Euclid (Npc): ... @@ -18,42 +10,11 @@ class Euclid (Npc): ("What does a mine turtle have on its back?",lambda x: "button" in x.lower() or "trigger" in x.lower()), ("What does a mine turtle have on its back?",lambda x: "button" in x.lower() or "trigger" in x.lower()), ] ] class DLevel(Npc.DialogLevel): def __init__ (self,euclid): super().__init__(euclid) self.question, self.answerChecker = random.choice(Euclid.questions) self.questionAsked = False def checkStandardRequests(self, teller, verb, message): resp = super().checkStandardRequests(teller, verb, message) if resp is not None: assert len(resp) == 3 return resp if not self.questionAsked: self.questionAsked = True return ("ask", self.question, None) else: if self.answerChecker(message): # correct answer self.npc.correctAnswerGiven = True newq, newac = random.choice(Euclid.questions) return ("say", "That answer is correct. I will go annoy people somewhere else. Good Bye.", Euclid.DLevel(self.npc)) else: # wrong answer return ("shout", "WRONG! "+self.question, None) def __init__(self,game): def __init__(self,game): super().__init__(game, Euclid.DLevel(self)) super().__init__(game) self.correctAnswerGiven = False def __str__ (self): def __str__ (self): return "Euclid" return "Euclid" def __repr__ (self): def __repr__ (self): return "E" return "E" \ No newline at end of file def blocksMove(self): return True def afterAnswering(self): if self.correctAnswerGiven: self.correctAnswerGiven = False self.relocate() \ No newline at end of file
questionman.py 0 → 100644
 from npc import Npc import random def testQuestion(qpair): q,ac = qpair print(q) a = input("> ") print("Is correct: ",ac(a)) class Questionman (Npc): class DLevel(Npc.DialogLevel): def __init__ (self,npc): super().__init__(npc) self.question, self.answerChecker = random.choice(self.npc.questions) self.questionAsked = False def checkStandardRequests(self, teller, verb, message): resp = super().checkStandardRequests(teller, verb, message) if resp is not None: assert len(resp) == 3 return resp if not self.questionAsked: self.questionAsked = True return ("ask", self.question, None) else: if self.answerChecker(message): # correct answer self.npc.correctAnswerGiven = True newq, newac = random.choice(self.npc.questions) return ("say", "That answer is correct. I will go annoy people somewhere else. Good Bye.", Questionman.DLevel(self.npc)) else: # wrong answer return ("shout", "WRONG! "+self.question, None) def __init__(self,game): super().__init__(game, Questionman.DLevel(self)) self.correctAnswerGiven = False def __str__ (self): return "QuestionMan" def __repr__ (self): return "Q" def blocksMove(self): return True def afterAnswering(self): if self.correctAnswerGiven: self.correctAnswerGiven = False self.relocate() \ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment