From 5b00c48fda26b30f67b862f4b5fca0d49b0fc463 Mon Sep 17 00:00:00 2001 From: "Tirthik Karmakar (karmakart)" Date: Tue, 1 Nov 2022 03:41:29 +0000 Subject: [PATCH] Add files via upload --- app.py | 132 +++++++++++++++++++++------------------------------ choice.html | 30 ++++++++++++ display.html | 28 +++++++++++ last.html | 8 ++++ 4 files changed, 120 insertions(+), 78 deletions(-) create mode 100644 choice.html create mode 100644 display.html create mode 100644 last.html diff --git a/app.py b/app.py index 4503e31..92b96dd 100644 --- a/app.py +++ b/app.py @@ -1,78 +1,54 @@ -from flask import Flask, render_template, url_for, request, redirect -from flask_sqlalchemy import SQLAlchemy - -app = Flask(__name__) -app.app_context().push() -#Configuring the databases and the database binding -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' -app.config['SQLALCHEMY_BINDS'] = { - 'items': 'sqlite:///items.db' #bind key - } - -db = SQLAlchemy(app) - - -class Character(db.Model): - """ - Creating an object of class Character used for the player's stats and actions. - The object attributes are initialised as columns of a database that can be later on used to store information - about the user inside the database. - - """ - id = db.Column(db.Integer, primary_key=True) - username = db.Column(db.String(20), nullable=False) - health = db.Column(db.Integer, default=100) - attack = db.Column(db.Integer, default=15) - defence = db.Column(db.Integer, default=10) - - def __repr__(self): - """ - Method used for visualising - """ - return '' % self.username, self.health, self.attack, self.defence - -class Items(db.Model): - """ - Items class written to product items as objects. - The objects are stored inside a database. - The class is binded to "items.db. - """ - __bind_key__ = 'items' - item_id = db.Column(db.Integer, primary_key=True) - item_name = db.Column(db.String(10), nullable=False) - item_description = db.Column(db.String(20)) - item_health = db.Column(db.Integer) - item_attack = db.Column(db.Integer) - item_defence = db.Column(db.Integer) - - def __repr__(self): - return '' % self.item_description, self.item_description, self.item_attack, self.item_defence - - -@app.route('/', methods = ['POST', 'GET']) -def index(): - if request.method == 'POST': - user_content = request.form['username'] #store the information from the form into a variable user_content - new_player = Character(username=user_content) #creating a new object of the Character class - #setting the username of the object to the given input - - #further implementation: Set the character username to the user's username - - try: - #append the object created to the database and redirect the page - db.session.add(new_player) - db.session.commit() - return redirect('/') - except: - #return an error message - return 'There was an issue creating the new player' - else: - #query to the database - #further implementation to return the stats of the player logged. - stats = Character.query.all() - return render_template('index.html', stats=stats) - - - -if __name__ == "__main__": - app.run(debug=True) +from flask import Flask, render_template, request +import random +import uuid + +app = Flask(__name__) + +game_stage = {} + +@app.route("/") +def level(): + return """ +

+ This is your level where you will have go through a three enemy caves +

+ Find out to select your luck + """ + +@app.route("/display") +def first(): + return render_template('display.html') + def new(): + id_game = str(uuid.uuid4()) + win = random.randint(1, 3) + game_stage[id_game] = win + +@app.route('/choice', methods=['POST']) +def choice(): + selected = int(request.form["cave"]) + + id_game = request.args.get("id_game") + win = game_stage[id_game] + + opened = set([1, 2, 3]) + opened.discard(win) + opened.discard(selected) + opened = random.choice(list(opened)) + + return render_template("choice.html", id_game=id_game, selected=selected, opened=opened) + +@app.route('/last', methods=['POST']) +def last(): + + + selected = int(request.form["cave"]) + + # request.args contains the URL parameters, like the game_id + id_game = request.args.get("id_game") + win = game_stage[id_game] + + won = selected == win + return render_template("last.html", won=won, win=win) + +if __name__ =="__main__": + app.run(debug=True) diff --git a/choice.html b/choice.html new file mode 100644 index 0000000..90a2e1d --- /dev/null +++ b/choice.html @@ -0,0 +1,30 @@ + + + + + + + + + + Do you want try other way? + +
+ +

You have selected Cave {{ selected }}

+ +

You enter the Cave {{ opened }}.

+ Dead-END + +

Well.... Do you want try other way?

+
+ {% for i in [1, 2, 3] %} + + Door {{ i }} {% if opened==i %} (opened) {% endif %} + +
+ {% endfor %} + + \ No newline at end of file diff --git a/display.html b/display.html new file mode 100644 index 0000000..30a41a8 --- /dev/null +++ b/display.html @@ -0,0 +1,28 @@ + + + + + + + The level + + + +
+ +

The choice of your lucky Path

+ Choose one of the 3 Caves: +

+ Cave 1 +

+ Cave 2 +

+ Cave 3 +

+ + +
+ + + + \ No newline at end of file diff --git a/last.html b/last.html new file mode 100644 index 0000000..2c248d9 --- /dev/null +++ b/last.html @@ -0,0 +1,8 @@ +{% if has_won %} +

You woke up!!

+{% else %} +

You have lost!

+The Path would have been {{ win }}. +{% endif %} + +Play again.....