Exemplo n.º 1
0
 def destroy(self, clear_all_traces=False):
     if clear_all_traces:
         DBGame.destroy(self.id)
     else:
         #self._store_to_db()
         pass
     self.engine.stop()
     Game.remove(self)
Exemplo n.º 2
0
 def _create(self, game_config, done_callback):
     """success: deferred returns id
     error: deferred returns None"""
     self._config = game_config
     
     def _create_callback(game_id):
         self.id = game_id
         
         self.engine = EngineProcessProtocol(self)
         
         params = [engine_config['executable']]
         params.extend(engine_config['params'])
         
         reactor.spawnProcess(self.engine, engine_config['full-path'], params)
         Game.add(self)
         
         done_callback()
     
     DBGame.create(game_config, _create_callback) 
Exemplo n.º 3
0
def create_game_from_json(game_json: Json) -> str:

    # Create game and questions
    game: Game = Game(status='Created',
                      operations=','.join(game_json["operations"]),
                      mode=game_json["mode"],
                      question_type=game_json["questionType"],
                      num_questions=game_json["numberOfQuestions"],
                      duration=game_json["duration"])
    db.session.add(game)
    db.session.commit()

    questions: List[Tuple[str, str]] = create_questions(game_json)

    # Add questions to database
    for quest_num in range(game_json["numberOfQuestions"]):
        question, answer = questions[quest_num]
        game_question: GameQuestion = GameQuestion(game_id=game.id,
                                                   question=question,
                                                   answer=answer,
                                                   quest_num=1 + quest_num)
        db.session.add(game_question)
    db.session.commit()
    return str(game.id)