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

@@ -4,7 +4,7 @@ import random


class Game:
def __init__(self, teamsize=0):
def __init__(self, teamsize=0, correct_field=0):
self.teamsize = teamsize
self.scoreboard = {'score_red': 0,
'score_blue': 0,
@@ -12,6 +12,8 @@ class Game:

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

def set_teamsize(self, teamsize: int):
self.teamsize = teamsize
@@ -38,22 +40,20 @@ class Game:
self.available_questions.remove(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']
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
self.set_correct_field(index)
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

@@ -5,15 +5,10 @@ app = Flask(__name__)

my_game = Game()

@app.route('/GETQUESTION', methods=['GET'])
@app.route('/question', methods=['GET'])
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'])
def teamsize():
@@ -23,23 +18,22 @@ def teamsize():

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

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

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

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

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

def main():
## ASUS Router
@@ -52,5 +46,4 @@ def main():

if __name__ == '__main__':
main()


Loading…
Cancel
Save