From ba585a16ad25d0e7241d6160721c71101c47bc65 Mon Sep 17 00:00:00 2001 From: Rogier Neeleman Date: Sun, 2 Jul 2017 22:32:23 +0200 Subject: [PATCH] If you found a tag, it now shows you your time remaining to play. --- nfgame.py | 38 ++++++++++++++++++++++------------ templates/tagalreadyfound.html | 3 ++- templates/tagfound.html | 3 ++- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/nfgame.py b/nfgame.py index 92ce43a..1144545 100644 --- a/nfgame.py +++ b/nfgame.py @@ -186,18 +186,6 @@ def tag_found(taghash): session['tag'] = taghash return redirect(url_for('new_user')) - cur_score = entries[0]['tags'] - if cur_score == None: - cur_score = taghash - else: - found_tags = cur_score.split(',') - for found_tag in found_tags: - if taghash == found_tag: - return render_template('tagalreadyfound.html', tagname=tags.get(taghash), color='#FFFF80') - break - - cur_score = cur_score + "," + taghash - '''Calculate duration''' starttime = datetime.strptime(entries[0]['starttime'], "%Y-%m-%d %H:%M:%S") now = datetime.now() @@ -212,11 +200,35 @@ def tag_found(taghash): if int(timediff.seconds) > int(app.config['MAX_TIME']): return render_template('timeout.html', color='#FF9999') + '''Calculate time remaining''' + endtime = starttime + timedelta(seconds=int(app.config['MAX_TIME'])) + playtime = endtime - now + hours = playtime.seconds / 3600 + minutes = (playtime.seconds - (hours * 3600)) / 60 + seconds = playtime.seconds - (minutes * 60) + if len(str(minutes)) == 1: + minutes = '0' + str(minutes) + if len(str(seconds)) == 1: + seconds = '0' + str(seconds) + timeremaining = str(hours) + ":" + str(minutes) + ":" + str(seconds) + + cur_score = entries[0]['tags'] + if cur_score == None: + cur_score = taghash + else: + found_tags = cur_score.split(',') + for found_tag in found_tags: + if taghash == found_tag: + return render_template('tagalreadyfound.html', tagname=tags.get(taghash), color='#FFFF80', time=timeremaining) + break + + cur_score = cur_score + "," + taghash + db = get_db() cur = db.execute('update score set tags = ?, lasttime = datetime(), duration = ? where id = ?', [cur_score, time, session['id']]) db.commit() - return render_template('tagfound.html', tagname=tags.get(taghash), color='#00FF00') + return render_template('tagfound.html', tagname=tags.get(taghash), color='#00FF00', time=timeremaining) @app.route('/admin/') def admin_page(password): diff --git a/templates/tagalreadyfound.html b/templates/tagalreadyfound.html index 245c702..26c3b23 100644 --- a/templates/tagalreadyfound.html +++ b/templates/tagalreadyfound.html @@ -2,7 +2,8 @@ {% block body %}

Hmmm!

- It seems you already found the tag: {{ tagname }}! + It seems you already found the tag: {{ tagname }}!
+ Time left to play: {{ time }}
{% endblock %} diff --git a/templates/tagfound.html b/templates/tagfound.html index 2d770e6..ec3add0 100644 --- a/templates/tagfound.html +++ b/templates/tagfound.html @@ -3,7 +3,8 @@

Found tag!

You found tag: {{ tagname }}!
- +
+ Time left to play: {{ time }}
{% endblock %}