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.5KB

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