some things
This commit is contained in:
@ -6,7 +6,7 @@ Arial
|
|||||||
#Cambria
|
#Cambria
|
||||||
Calibri
|
Calibri
|
||||||
#Clarendon
|
#Clarendon
|
||||||
#DaxPro
|
#Dax Pro
|
||||||
#Didot
|
#Didot
|
||||||
#Franklin Gothic
|
#Franklin Gothic
|
||||||
#Frutiger
|
#Frutiger
|
||||||
@ -24,6 +24,6 @@ Roboto
|
|||||||
#Roboto Slab
|
#Roboto Slab
|
||||||
#Rockwell
|
#Rockwell
|
||||||
#Sabon
|
#Sabon
|
||||||
#Segoe UI
|
Segoe UI
|
||||||
#Times New Roman
|
#Times New Roman
|
||||||
#Verdana
|
#Verdana
|
@ -1,5 +1,5 @@
|
|||||||
from .util import (base64, FONT_SIZE, FONT_COLOR, IMAGE_BACKGROUND, IMAGE_SIZE,
|
from .util import (base64, FONT_SIZE, FONT_COLOR, IMAGE_BACKGROUND, IMAGE_SIZE,
|
||||||
MARGINS, FONTS)
|
MARGINS, FONTS, read_file, write_file)
|
||||||
from . import images
|
from . import images
|
||||||
from . import web
|
from . import web
|
||||||
from . import game
|
from . import game
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +1,10 @@
|
|||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
|
|
||||||
from font_game.images import gen_image
|
from font_game.images import gen_image
|
||||||
from font_game import base64, FONTS
|
from font_game import base64, FONTS, read_file, write_file
|
||||||
|
|
||||||
def purge_games():
|
def purge_games():
|
||||||
for root, _, files in os.walk("current_games"):
|
for root, _, files in os.walk("current_games"):
|
||||||
@ -45,3 +46,16 @@ def start_game(game_length: int = 10) -> str:
|
|||||||
file.write(game)
|
file.write(game)
|
||||||
|
|
||||||
return game_id
|
return game_id
|
||||||
|
|
||||||
|
def test_game(game_id: str):
|
||||||
|
return pathlib.Path(f"current_games/{game_id}").is_file()
|
||||||
|
|
||||||
|
def guess_font(game_id: str, font_guess: str):
|
||||||
|
game_dict = read_file(f"current_games/{game_id}")
|
||||||
|
i = int(game_dict['i'])
|
||||||
|
font = game_dict['fonts'].split(',')[i]
|
||||||
|
if font_guess == font:
|
||||||
|
game_dict['points'] = str(int(game_dict['points']) + 1)
|
||||||
|
|
||||||
|
game_dict['i'] = str(i+1)
|
||||||
|
write_file(f"current_games/{game_id}", game_dict)
|
||||||
|
@ -11,6 +11,21 @@ IMAGE_SIZE = (1800, 1200)
|
|||||||
|
|
||||||
MARGINS = 60
|
MARGINS = 60
|
||||||
|
|
||||||
|
def read_file(path: str) -> dict:
|
||||||
|
with open(path, "r", encoding="utf-8") as file:
|
||||||
|
game_dict = dict(
|
||||||
|
[tuple(line.split(":")) for line in file.read().split('\n')]
|
||||||
|
)
|
||||||
|
|
||||||
|
return game_dict
|
||||||
|
|
||||||
|
def write_file(path: str, game: dict):
|
||||||
|
game_string = "\n".join(
|
||||||
|
[f"{key}:{value}" for key, value in game.items()]
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(path, "w", encoding="utf-8") as file:
|
||||||
|
file.write(game_string)
|
||||||
|
|
||||||
def base64(num: int) -> str:
|
def base64(num: int) -> str:
|
||||||
temp = ""
|
temp = ""
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import pathlib
|
import os
|
||||||
import flask
|
import flask
|
||||||
from font_game.images import purge_images
|
from font_game.images import purge_images
|
||||||
from font_game.game import start_game, purge_games
|
from font_game.game import start_game, purge_games, guess_font, test_game
|
||||||
from font_game import FONTS
|
from font_game import FONTS, read_file
|
||||||
|
|
||||||
app = flask.Flask(
|
app = flask.Flask(
|
||||||
__name__,
|
__name__,
|
||||||
@ -20,36 +20,21 @@ def font_game():
|
|||||||
if flask.request.method == "POST":
|
if flask.request.method == "POST":
|
||||||
game_id = flask.request.form['id']
|
game_id = flask.request.form['id']
|
||||||
font_guess = flask.request.form['font']
|
font_guess = flask.request.form['font']
|
||||||
|
if not test_game(game_id):
|
||||||
if not pathlib.Path(f"current_games/{game_id}").is_file():
|
|
||||||
return flask.redirect("/")
|
return flask.redirect("/")
|
||||||
|
|
||||||
with open(f"current_games/{game_id}", "r+", encoding="utf-8") as file:
|
guess_font(game_id, font_guess)
|
||||||
game_dict = dict(
|
|
||||||
[tuple(line.split(":")) for line in file.read().split('\n')]
|
|
||||||
)
|
|
||||||
i = int(game_dict['i'])
|
|
||||||
font = game_dict['fonts'].split(',')[i]
|
|
||||||
if font_guess == font:
|
|
||||||
game_dict['points'] = str(int(game_dict['points']) + 1)
|
|
||||||
game_dict['i'] = str(i+1)
|
|
||||||
game = "\n".join(
|
|
||||||
[f"{key}:{value}" for key, value in game_dict.items()]
|
|
||||||
)
|
|
||||||
file.seek(0)
|
|
||||||
file.write(game)
|
|
||||||
|
|
||||||
args = flask.request.args
|
args = flask.request.args
|
||||||
if 'id' in args:
|
if 'id' in args:
|
||||||
if not pathlib.Path(f"current_games/{args['id']}").is_file():
|
game_id = args['id']
|
||||||
|
if not test_game(game_id):
|
||||||
return flask.redirect("/")
|
return flask.redirect("/")
|
||||||
|
|
||||||
with open(f"current_games/{args['id']}", "r", encoding="utf-8") as file:
|
game = read_file(f"current_games/{game_id}")
|
||||||
game = dict(
|
|
||||||
[tuple(line.split(":")) for line in file.read().split('\n')]
|
|
||||||
)
|
|
||||||
|
|
||||||
if int(game['i']) == int(game['game_length']):
|
if int(game['i']) == int(game['game_length']):
|
||||||
|
os.remove(f"current_games/{game_id}")
|
||||||
return flask.render_template("final.html", points=game['points'],
|
return flask.render_template("final.html", points=game['points'],
|
||||||
game_length=game['game_length'])
|
game_length=game['game_length'])
|
||||||
|
|
||||||
@ -68,14 +53,6 @@ def font_game():
|
|||||||
}
|
}
|
||||||
return flask.render_template("fontgame.html", **parameters)
|
return flask.render_template("fontgame.html", **parameters)
|
||||||
|
|
||||||
if 'n' in flask.request.args:
|
|
||||||
game_length = int(flask.request.args['n'])
|
|
||||||
else:
|
|
||||||
game_length = 10
|
|
||||||
|
|
||||||
game_id = start_game(game_length)
|
|
||||||
return flask.redirect(f"/fontgame?id={game_id}")
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
return flask.render_template("menu.html")
|
return flask.render_template("menu.html")
|
||||||
@ -83,7 +60,9 @@ def root():
|
|||||||
@app.route("/startgame", methods=["POST"])
|
@app.route("/startgame", methods=["POST"])
|
||||||
def start():
|
def start():
|
||||||
if 'game_length' in flask.request.form:
|
if 'game_length' in flask.request.form:
|
||||||
game_length = flask.request.form['game_length']
|
game_length = int(flask.request.form['game_length'])
|
||||||
else:
|
else:
|
||||||
game_length = 10
|
game_length = 10
|
||||||
return flask.redirect(f"/fontgame?n={game_length}")
|
|
||||||
|
game_id = start_game(game_length)
|
||||||
|
return flask.redirect(f"/fontgame?id={game_id}")
|
||||||
|
Reference in New Issue
Block a user