repository to manage all files for 1_2_oder_3 interaction game for Inf2/2 Interaktionen SoSe23 from Engert, Caliskan and Bachiri
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

router.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from flask import Flask, jsonify, Response, request
  2. from game import Game
  3. app = Flask(__name__)
  4. my_game = Game()
  5. @app.route('/question', methods=['GET'])
  6. def get_question():
  7. my_game.get_question()
  8. print(my_game.question)
  9. return jsonify(my_game.question)
  10. @app.route('/teamsize', methods=['POST'])
  11. def teamsize():
  12. team_size = request.json
  13. my_game.set_teamsize(team_size.get('teamsize'))
  14. print(f'Teamsize: {my_game.teamsize}\n')
  15. return Response(status=200)
  16. @app.route('/scoreboard', methods=['GET'])
  17. def scoreboard():
  18. my_game.set_scoreboard()
  19. print(my_game.scoreboard)
  20. return jsonify(my_game.scoreboard)
  21. @app.route('/check', methods=['GET'])
  22. def check():
  23. return my_game.scoreboard
  24. @app.route('/reset', methods=['GET'])
  25. def reset():
  26. my_game.reset_game()
  27. return Response(status=200)
  28. @app.route('/scores', methods=['POST'])
  29. def get_scores():
  30. scores = request.json
  31. my_game.add_score(scores)
  32. return Response(status=200)
  33. @app.route('/winner', methods=['GET'])
  34. def set_winner():
  35. my_game.final_result()
  36. return jsonify(my_game.final_score)
  37. def main():
  38. ## Router
  39. # app.run(host='192.168.50.79', port=5555, debug=True)
  40. ## Postman
  41. app.run(host='127.0.0.1', port=5555, debug=True)
  42. if __name__ == '__main__':
  43. main()