working demo
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import json
|
||||
from flask import Flask, request, render_template
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def game():
|
||||
gamecode = request.args.get('code')[:-1]
|
||||
|
||||
#return open("page copy.html", "r").read()
|
||||
#print(buildHTML(gamecode))
|
||||
|
||||
return buildHTML(gamecode)
|
||||
|
||||
|
||||
def buildHTML(gamecode):
|
||||
with open("story.json", "r") as f:
|
||||
print("\n\n")
|
||||
story = json.loads(f.read())
|
||||
nodeName = "start"
|
||||
for action in gamecode:
|
||||
nodeName = story[nodeName]["choices"][int(action) - 1]["next"]
|
||||
print(action, nodeName)
|
||||
info = story[nodeName]
|
||||
currText = info["text"]
|
||||
choices = ""
|
||||
for i in range(len(info["choices"])):
|
||||
choice = info["choices"][i]
|
||||
choices += f"{(i + 1) * 10}: " + choice["text"] + "\\n"
|
||||
print(str(request.user_agent) + "\n",currText,choices)
|
||||
|
||||
with open('page.html', "r") as page:
|
||||
return page.read().replace("{{CurrText}}", currText.replace('"', '\\"')).replace("{{Choices}}", choices.replace('"', '\\"'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, port=1387)
|
||||
Reference in New Issue
Block a user