change scoreboard and question
This commit is contained in:
parent
60b02019e2
commit
beab4b0111
@ -4,7 +4,7 @@ import random
|
|||||||
|
|
||||||
|
|
||||||
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,
|
||||||
@ -12,6 +12,8 @@ class Game:
|
|||||||
|
|
||||||
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
|
||||||
@ -38,22 +40,20 @@ class Game:
|
|||||||
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))
|
self.question = dict(zip(field_names, question))
|
||||||
add_data = my_game.correct_field(data)
|
self.add_correct_field()
|
||||||
return add_data
|
return self.question
|
||||||
|
|
||||||
def correct_field(self, data_dict: dict) -> dict:
|
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)])
|
self.question.update([('Correct_field', index)])
|
||||||
return data_dict
|
|
||||||
|
def set_correct_field(self, correct_field: int):
|
||||||
|
self.field = correct_field
|
||||||
|
|
||||||
my_game = Game()
|
|
||||||
test = my_game.get_question()
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,15 +5,10 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
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()
|
my_game.get_question()
|
||||||
return jsonify(question)
|
return jsonify(my_game.question)
|
||||||
|
|
||||||
## USEFUL ?
|
|
||||||
# @app.route('/connection', methods=['GET'])
|
|
||||||
# def connection():
|
|
||||||
# return Response(status=200)
|
|
||||||
|
|
||||||
@app.route('/teamsize', methods=['POST'])
|
@app.route('/teamsize', methods=['POST'])
|
||||||
def teamsize():
|
def teamsize():
|
||||||
@ -23,23 +18,22 @@ def teamsize():
|
|||||||
|
|
||||||
@app.route('/scoreboard', methods=['GET'])
|
@app.route('/scoreboard', methods=['GET'])
|
||||||
def scoreboard():
|
def scoreboard():
|
||||||
new_score = my_game.scoreboard
|
return my_game.scoreboard, Response(status=200)
|
||||||
return new_score
|
|
||||||
|
|
||||||
@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('/scores', methods=['POST'])
|
||||||
@app.route('/GETSCORES', 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
|
||||||
@ -53,4 +47,3 @@ def main():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user