-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
107 lines (91 loc) · 3.79 KB
/
Copy pathapp.py
File metadata and controls
107 lines (91 loc) · 3.79 KB
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
103
104
105
106
107
"""
==========================================================================
HEXAJUMP - ENTERPRISE BACKEND ENGINE & STATE LAYER
==========================================================================
"""
import os
from flask import Flask, send_from_directory, jsonify, request, session, render_template
app = Flask(__name__, static_folder='static', template_folder='templates')
app.secret_key = 'hexajump_crypto_high_performance_system_secure_key_2026'
def initialize_player_session():
"""Initializes player save state structure into the server memory securely."""
if 'coins' not in session:
session['coins'] = 1000
if 'selected_avatar' not in session:
session['selected_avatar'] = 'm1'
if 'unlocked_avatars' not in session:
session['unlocked_avatars'] = ['m1', 'f1']
if 'high_scores' not in session:
session['high_scores'] = {
'm1': 0, 'm2': 0, 'm3': 0,
'f1': 0, 'f2': 0, 'f3': 0
}
@app.route('/')
def serve_launcher():
"""Serves the primary UI canvas layer out of the templates environment."""
initialize_player_session()
return render_template('index.html')
@app.route('/<path:path>')
def serve_static_assets(path):
"""Fallback directory route map for serving static media assets cleanly."""
return send_from_directory(app.static_folder, path)
# --------------------------------------------------------------------------
# RESTful API Interface Layer
# --------------------------------------------------------------------------
@app.route('/api/player/data', methods=['GET'])
def get_player_data():
initialize_player_session()
return jsonify({
"coins": session['coins'],
"selected_avatar": session['selected_avatar'],
"unlocked_avatars": session['unlocked_avatars'],
"high_scores": session['high_scores']
}), 200
@app.route('/api/store/buy', methods=['POST'])
def buy_avatar():
initialize_player_session()
data = request.get_json() or {}
avatar_id = data.get('avatar_id')
price = data.get('price', 999999)
if not avatar_id or avatar_id in session['unlocked_avatars']:
return jsonify({"status": "error", "message": "Avatar already unlocked or invalid ID"}), 400
if session['coins'] >= price:
session['coins'] -= price
session['unlocked_avatars'].append(avatar_id)
session.modified = True
return jsonify({
"status": "success",
"coins": session['coins'],
"unlocked_avatars": session['unlocked_avatars']
}), 200
return jsonify({"status": "error", "message": "Insufficient balance"}), 400
@app.route('/api/game/over', methods=['POST'])
def handle_game_over():
initialize_player_session()
data = request.get_json() or {}
score = data.get('score', 0)
avatar_id = data.get('avatar_id')
coins_earned = data.get('coins_earned', 0)
session['coins'] += coins_earned
new_high_score = False
if avatar_id in session['high_scores'] and score > session['high_scores'][avatar_id]:
session['high_scores'][avatar_id] = score
new_high_score = True
session.modified = True
return jsonify({
"status": "success",
"high_score": session['high_scores'].get(avatar_id, 0),
"is_new_high": new_high_score
}), 200
@app.route('/api/state/select', methods=['POST'])
def select_avatar():
initialize_player_session()
data = request.get_json() or {}
avatar_id = data.get('avatar_id')
if avatar_id in session['unlocked_avatars']:
session['selected_avatar'] = avatar_id
session.modified = True
return jsonify({"status": "success"}), 200
return jsonify({"status": "error", "message": "Avatar template locked"}), 400
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)