Browse Source

change scoreboard and question

master
David Engert 1 year ago
parent
commit
beab4b0111
2 changed files with 23 additions and 30 deletions
  1. 13
    13
      src_folder/BackEnd/game.py
  2. 10
    17
      src_folder/BackEnd/router.py

+ 13
- 13
src_folder/BackEnd/game.py View File





class Game: class Game:
def __init__(self, teamsize=0):
def __init__(self, teamsize=0, correct_field=0):
self.teamsize = teamsize self.teamsize = teamsize
self.scoreboard = {'score_red': 0, self.scoreboard = {'score_red': 0,
'score_blue': 0, 'score_blue': 0,


self.questions = QuestionDataBase('src_folder/BackEnd/Database/EinsZweiOderDrei.db') self.questions = QuestionDataBase('src_folder/BackEnd/Database/EinsZweiOderDrei.db')
self.available_questions = list(range(1, self.questions.num_rows())) self.available_questions = list(range(1, self.questions.num_rows()))
self.field = correct_field
self.question = {}


def set_teamsize(self, teamsize: int): def set_teamsize(self, teamsize: int):
self.teamsize = teamsize self.teamsize = teamsize
self.available_questions.remove(random_question_number) self.available_questions.remove(random_question_number)


question= list(questions_data[random_question_number]) question= list(questions_data[random_question_number])
data = dict(zip(field_names, question))
add_data = my_game.correct_field(data)
return add_data
def correct_field(self, data_dict: dict) -> dict:
self.question = dict(zip(field_names, question))
self.add_correct_field()
return self.question
def add_correct_field(self):
answeroption = ['Answeroption_1', 'Answeroption_2', 'Answeroption_3', 'Correct_answeroption'] answeroption = ['Answeroption_1', 'Answeroption_2', 'Answeroption_3', 'Correct_answeroption']
for i in range(0, len(answeroption) -1): for i in range(0, len(answeroption) -1):
if data_dict[answeroption[-1]] == data_dict[answeroption[i]]:
if self.question[answeroption[-1]] == self.question[answeroption[i]]:
index = answeroption.index(answeroption[i]) + 1 index = answeroption.index(answeroption[i]) + 1
self.set_correct_field(index)
break break
data_dict.update([('Correct_field', index)])
return data_dict
self.question.update([('Correct_field', index)])


my_game = Game()
test = my_game.get_question()
def set_correct_field(self, correct_field: int):
self.field = correct_field





+ 10
- 17
src_folder/BackEnd/router.py View File



my_game = Game() my_game = Game()


@app.route('/GETQUESTION', methods=['GET'])
@app.route('/question', methods=['GET'])
def get_question(): def get_question():
question = my_game.get_question()
return jsonify(question)

## USEFUL ?
# @app.route('/connection', methods=['GET'])
# def connection():
# return Response(status=200)
my_game.get_question()
return jsonify(my_game.question)


@app.route('/teamsize', methods=['POST']) @app.route('/teamsize', methods=['POST'])
def teamsize(): def teamsize():


@app.route('/scoreboard', methods=['GET']) @app.route('/scoreboard', methods=['GET'])
def scoreboard(): def scoreboard():
new_score = my_game.scoreboard
return new_score
return my_game.scoreboard, Response(status=200)


@app.route('/check', methods=['GET']) @app.route('/check', methods=['GET'])
def check(): def check():
pass
return my_game.scoreboard


@app.route('/reset', methods=['GET']) @app.route('/reset', methods=['GET'])
def reset(): def reset():
my_game.reset_game() my_game.reset_game()
return Response(status=200) return Response(status=200)


## IDEA
@app.route('/GETSCORES', methods=['POST'])
@app.route('/scores', methods=['POST'])
def get_scores(): def get_scores():
pass

scores = request.json
my_game.add_score(scores)
return Response(status=200)


def main(): def main():
## ASUS Router ## ASUS Router


if __name__ == '__main__': if __name__ == '__main__':
main() main()


Loading…
Cancel
Save