Exemple #1
0
 def parse(self, game):
     type = game.attrib["type"]
     score = int(game.attrib["score"])
     if type == "SingleImage":
         img = game.find("./img")
         image = img.attrib["src"]
         image = os.path.join(self.dataPath, "img", image)
         return GameData.SingleImageGameData(image, score)
     elif type == "ImageReveal":
         img = game.find("./img")
         image = img.attrib["src"]
         image = os.path.join(self.dataPath, "img", image)
         return GameData.ImageRevealGameData(image, score)
     elif type == "WhoIsLying":
         quote = game.find("./quote").text
         answerlistTag = game.find("./answerList")
         answerList = []
         answerKey = []
         for answerTag in answerlistTag:
             key = True if answerTag.attrib["isLying"] == "True" else False
             answer = answerTag.text
             answerKey.append(key)
             answerList.append(answer)
         #TODO
         return GameData.WhoIsLyingGameData(quote, answerList, answerKey,
                                            None, score)
     elif type == "Sound":
         soundfile = game.find("./sound").attrib["src"]
         soundfile = os.path.join(self.dataPath, "snd", soundfile)
         image = os.path.join("data", "res", "music.png")
         return GameData.SoundGameData(soundfile, image, score)