This commit is contained in:
Adrian Gunnar Lauterer 2024-02-24 22:55:26 +01:00
parent ccbdd92300
commit b407bee0c9
Signed by: adriangl
GPG Key ID: D33368A59745C2F0
2 changed files with 37 additions and 16 deletions

26
main.py
View File

@ -36,7 +36,7 @@ def create():
#replace spaces with underscores #replace spaces with underscores
player_name = player_name.replace(' ', '_') player_name = player_name.replace(' ', '_')
# replace illegal characters with nothing # replace illegal characters with nothing
illegal_chars = ['<', '>', '(', ')', '[', ']', ',', '.', ':', ';', '-', '/', '|', '\\', 'exec', 'spectator'] illegal_chars = ['<', '>', '(', ')', '[', ']', ',', '.', ':', ';', '-', '/', '|', '\\','=', 'exec', 'spectator']
for char in illegal_chars: for char in illegal_chars:
player_name = player_name.replace(char, '') player_name = player_name.replace(char, '')
if player_name: if player_name:
@ -90,6 +90,7 @@ def game(game_id, player_name):
gamestate = requests.get(ozai_url + 'game/' + game_id).json() gamestate = requests.get(ozai_url + 'game/' + game_id).json()
move_status = False move_status = False
#if a move was made.
if request.method == 'POST': if request.method == 'POST':
source = request.form['source'] source = request.form['source']
@ -116,16 +117,17 @@ def game(game_id, player_name):
else: else:
move_status = response.text move_status = response.text
#dont send player parameter if the player is a spectator
if player_name == 'spectator': while True:
gamestate = requests.get(ozai_url + 'game/' + game_id).json() if player_name == 'spectator':
return render_template('game.html', game_id=game_id, gamestate=gamestate) gamestate = requests.get(ozai_url + 'game/' + game_id).json()
elif player_name in gamestate['players']: return render_template('game.html', game_id=game_id, gamestate=gamestate)
gamestate = requests.get(ozai_url + 'game/' + game_id + '?player=' + player_name).json() elif player_name in gamestate['players']:
return render_template('game.html', game_id=game_id, gamestate=gamestate, player_name=player_name, move_status=move_status) gamestate = requests.get(ozai_url + 'game/' + game_id + '?player=' + player_name).json()
else: return render_template('game.html', game_id=game_id, gamestate=gamestate, player_name=player_name, move_status=move_status)
return 'Player not found', 404 else:
return 'Player not found', 404
return 'Player not found', 404
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True, host='0.0.0.0', port=5000)

View File

@ -133,6 +133,22 @@
height: 1.5em; height: 1.5em;
} }
.blue_bg {
background-color: rgb(49, 157, 245, 0.5);
}
.yellow_bg {
background-color: rgb(245, 245, 10, 0.5);
}
.red_bg {
background-color: rgb(255, 0, 0, 0.5);
}
.black_bg {
background-color: rgb(93, 93, 93, 0.5);
}
.white_bg {
background-color:rgb(208, 202, 195, 0.5);
}
.blue { .blue {
background-color: rgb(49, 157, 245); background-color: rgb(49, 157, 245);
} }
@ -231,11 +247,14 @@
</div> </div>
<div class="flex-col"> <div class="flex-col">
<!-- <h3>Wall</h3> --> <!-- <h3>Wall</h3> -->
<div class="wall"> <div class="wall">
{% set colors_base = ['blue', 'yellow', 'red', 'black', 'white'] %}
{% for row in player_data.wall %} {% for row in player_data.wall %}
{% for cell in row %} {% set colors = colors_base[-loop.index0:] + colors_base[:-loop.index0] %}
<div class="{{ cell }}">{% if cell %}{{ cell[:1] }}{% else %}{{ '_' }}{% endif %}</div> {% for cell in row %}
{% endfor %} {% set color = colors[loop.index0] + "_bg" %}
<div class="{{ color }}">{% if cell %}{{ color[:1] }}{% else %}{{ '_' }}{% endif %}</div>
{% endfor %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>