-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
102 lines (81 loc) · 2.43 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from flask import Flask, jsonify, request, render_template
import flask
import requests
import store
import os
import random
from flask_cors import CORS
import game1 as g1
import game2 as g2
#dddd
app = Flask(__name__)
#, static_url_path='', static_folder='static', template_folder='templates')
CORS(app)
@app.route("/")
def index():
return app.send_static_file('index.html')
@app.route("/login", methods=["POST", "GET"])
def Userlogin():
if flask.request.method == 'POST':
userName = request.args.get("username")
#else:
#userName = request.form["username"]
#print('2. username: ', userName)
return app.send_static_file('index.html')
@app.route("/intro")
def UserIntro():
return app.send_static_file('index.html')
options1 = {}
correct_answer1 = ''
idx1 = 0
options2 = {}
correct_answer2 = ''
idx2 = 0
@app.route('/game1')
def game1():
global options1
global correct_answer1
global idx1
gm1 = g1.Game1()
options1, correct_answer1, idx1 = gm1.game1_backend()
return render_template('index2.html', options=options1)
@app.route('/game2')
def game2():
global options2
global correct_answer2
global idx2
gm2 = g2.Game2()
options2, correct_answer2, idx2 = gm2.game2_backend()
return render_template('index3.html', options=options2)
@app.route('/game3')
def game3():
return app.send_static_file('index.html')
@app.route('/game4')
def game4():
return render_template('index.html')
@app.route('/submit1', methods=['POST', 'GET'])
def submit1():
global options1
global correct_answer1
global idx1
if flask.request.method == 'POST':
user_answer = request.form['answer']
result = "Correct!" if user_answer == correct_answer1 else "Wrong!"
idx_dict = {1: 'A', 2: 'B', 3: 'C', 4: 'D'}
return jsonify({'result': result, 'answer': idx_dict[idx1+1]})
else:
return correct_answer1
@app.route('/submit2', methods=['POST', 'GET'])
def submit2():
global options2
global correct_answer2
global idx2
if flask.request.method == 'POST':
user_answer = request.form['answer']
result = "Correct!" if user_answer == correct_answer2 else "Wrong!"
idx_dict = {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'F'}
return jsonify({'result': result, 'answer': idx_dict[idx2+1]})
else:
return options2[correct_answer2][0]
if __name__ == "__main__":
app.run(debug=True)