コード例 #1
0
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            # why is there here? do you need it?' - in case no session
            # if they somehow went straight to the game without starting at start
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room: 
                session['room_name'] = planisphere.name_room(room)
                # if action isn't valid path, nothing given to next_room
                # so just stay in current room
                
                return render_template("repeat_room.html", room=room)
                
            else:
                session['room_name'] = planisphere.name_room(next_room)

        return redirect(url_for("game"))
コード例 #2
0
ファイル: app.py プロジェクト: TianYuWang1996/mystuff
def game():
    room_name = session.get("room_name")

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            # why is there here? do you need it?
            return render_template("you_died.html")
    else:
        action = request.form.get("action")

        if room_name and action:
            if room_name == "Laser Weapon Armory":
                room = planisphere.load_room(room_name)
                next_room = room.go(action)

            if not next_room:
                session["room_name"] = planisphere.name_room(room)
            else:
                session["room_name"] = planisphere.name_room(next_room)
                return render_template("feedback_room.html",
                                       room=room,
                                       action=action)

        return redirect(url_for("game"))
コード例 #3
0
def game():

    room_name = session.get('room_name')

    if request.method == 'GET':
        if room_name and room_name != 'generic_death':
            room = planisphere.load_room(room_name)
            if room.name == "Laser Weapon Armory" and room.timer < 10:
                room.timer = room.timer + 1
            elif room.name == 'Laser Weapon Armory' and room.timer >= 10:
                return render_template("you_died.html")
            return render_template("show_room.html", room=room)

        else:
            # why is there here? do you need it?
            return render_template("you_died.html")

    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)
            if not next_room and room.name == 'Escape Pod':
                room = planisphere.load_room('the_end_loser')
                return render_template("show_room.html", room=room)
            if not next_room:
                session['room_name'] = planisphere.name_room(room)
            else:
                session['room_name'] = planisphere.name_room(next_room)
        return redirect(url_for("game"))
コード例 #4
0
def game():
    room_name = session.get('room_name') # sets the room name to the first room and then to the room_name passed to the session by the last room.

    if request.method == 'GET':
        if room_name:
            # what does this do?
            print(">>> room_name =", room_name, "whose type is ", type(room_name))
            room = planisphere.load_room(room_name)
            print(">>> room =", room, " and its name is: ", str(room))
            return render_template("show_room.html", room=room)
        else:
            # why is there here? do you need it?
            print(">> When does this logic happen?", room, " type", type(room))
            return render_template("show_room.html", room=room)
    else:
        print("***Starting a POST request.***")
        print(">>>> Current room name is: ", room_name)
        action = request.form.get('action')
        print(">>>> The form action is =", action)
        if room_name and action:
            room = planisphere.load_room(room_name)
            print(">> room =", str(room), " which is the current room.")
            print(">> The path is ", repr(room.paths))
            next_room = room.go(action)
            print(">> next_room =", str(next_room))

            if not next_room: # if next_room returns None, then reload the current room.
                session['room_name'] = planisphere.name_room(room)
            else: # otherwise update the session with the next_room
                session['room_name'] = planisphere.name_room(next_room)

        return redirect(url_for("game")) # I think this acts as the game loop
コード例 #5
0
def game():
    room_name = session.get('room_name')
    terminate = False
    if room_name in terminating_rooms:
        terminate = True

    if request.method == "GET":
        if room_name != "Death":
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room, done=terminate)
        else:
            # why is there here? do you need it?
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                # If the input is not valid, repeat currenrt room.
                session['room_name'] = planisphere.name_room(room)
            else:
                # If the input is valid, go on to next room.
                session['room_name'] = planisphere.name_room(next_room)

        return redirect(url_for("game"))
コード例 #6
0
ファイル: app.py プロジェクト: kugys86/gothonweb-from-lpthw
def game():
    if not session.get('logged_in'):
        return render_template('login.html')
    else:
        room_name = session.get('room_name') 
        current_user = session.get('current_user')
        if request.method == "GET":
            if room_name:
                room = planisphere.load_room(room_name)
                lvl = room.lvl
                
                if lvl > session['current_user_highscore']:
                    session['current_user_highscore'] = increase_highscore(current_user)                    
                
                return render_template("show_room.html", room=room, session=session)
        else:
            action = request.form.get('action')
            if room_name and action:
                room = planisphere.load_room(room_name)

                next_room = room.go(action)
                if not next_room:
                    session['room_name'] = planisphere.name_room(room)
                else:
                    session['room_name'] = planisphere.name_room(next_room)

            return redirect(url_for("game"))
コード例 #7
0
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            # why is there here? do you need it?'
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

        if not next_room:
            session['room_name'] = planisphere.name_room(room)
        else:
            session['room_name'] = planisphere.name_room(next_room)
    return redirect(url_for("game"))

    # YOU SHOULD CHANGE THIS IF YOU PUT ON THE INTERNET
    app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
コード例 #8
0
ファイル: app.py プロジェクト: JoseMorales7/LearnPython
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)

        else:
            #why is there here? do you need it?
            return render_template("you_died.html")

    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                session['room_name'] = planisphere.name_room(room)

            else:
                session['room_name'] = planisphere.name_room(next_room)

        return redirect(url_for("game"))
コード例 #9
0
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            # in case the user access /game directly
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                # repeat same room
                session['room_name'] = planisphere.name_room(room)
            else:
                # move to next room
                session['room_name'] = planisphere.name_room(next_room)

        return redirect(url_for("game"))
コード例 #10
0
ファイル: plainisohere_test.py プロジェクト: HMBaytam/python
def test_gothon_game_map():
    start_room = game.load_room(game.START)
    nt.assert_equal(start_room.go('shoot!'), game.generic_death)
    nt.assert_equal(start_room.go('dodge!'), game.generic_death)

    room = start_room.go('tell a joke')
    nt.assert_equal(room, game.laser_weapon_armory)
コード例 #11
0
ファイル: web_engine.py プロジェクト: RinwaOwuogba/gothon-web
def game():
	room_name = session.get('room_name')
	if request.method == "GET":

		# check if user was redirected from "play" option in profile
		if room_name:
			room = planisphere.load_room(room_name)

			if room.name in ["Death", "The End"] and (session['game']['highscore'] < session['score']):
				user = User.query.get(int(session["user_id"]))
				user.highscore = session['score']
				db.session.commit()

			if not session['old']:
				session['score'] += 1000
				session['old'] = True

			user_id = session["user_id"]
			user = User.query.get(int(user_id))

			return render_template("show_room.html", room=room, options=session['game']['options'])
		else:
			return redirect(url_for("play"))
	else:
		action = request.form.get('action')
		options = []

		if room_name and action:
			room = planisphere.load_room(room_name)
			next_room = scan(action, room)

			# show available options at current room to user
			if "help" in action.lower():
				for i in room.paths:
					options.append(i)
				session['game']['options'] = options

			if not next_room:
				session['room_name'] = planisphere.name_room(room)
				session['old'] = True
			else:
				session['room_name'] = planisphere.name_room(next_room)
				session['old'] = False
				session['game']['options'] = []
		return redirect(url_for("game"))
コード例 #12
0
def game():  # Scene 2. When Player is redirectd to the game page:
    room_name = session.get(
        'room_name'
    )  # Get the value of room_name(str type) from the session. Default value is central_corridor
    ##print("$$$ room_name is:", room_name)

    if request.method == "GET":  # Scene 3. When Player enter the game but has not submitted (GET request to the server):
        if room_name:
            room_object = planisphere.load_room(
                room_name
            )  # Get room_object value from the globals directary {room_name:room_object} in load_name() function
            ##print("$$$ room_object 1 is:", room_object)
            return render_template(
                "show_room.html", room=room_object
            )  # Send room_object to html for loading the properties (name、description, etc.) of the objecct,to show in the html page
        else:
            # why is else here? do you need it? No,but keep if-else is a good habit
            return render_template("you_died.html")

    else:  # Scene 4. When Player click the submit on the game page(POST request to the server):
        action = request.form.get(
            'action'
        )  # Server load the value of the 'action' from the form table
        ##print("$$$ action is:", action)
        if room_name and action:  # Scene 5. If the form has been filled when Player click the submit:
            room_object = planisphere.load_room(
                room_name
            )  # Get room_object value from the globals directary {room_name:room_object} in load_name() function
            ##print("$$$ room_object 2 is:", room_object)
            next_room_object = room_object.go(
                action
            )  # Get room_object.next_paths directory {action:next_room_object} from go() function,to get the value of next_room_object
            ##print("$$$ next_room_object is:", room_object)
            if not next_room_object:  # Scene 5-1. If Player filled in an invalid action in the form(next_room_object == None,which means room_object.go(action) doesn't return valid value):
                ##print("next_room_object 1:", next_room_object)
                session['room_name'] = planisphere.name_room(room_object)
                ##print("$$$ session['room_name'] 2 is:", session['room_name'])
            else:
                ##print("next_room_object 2:", next_room_object)      # Scene 5-2. If Player filled in valid actionin the form(next_room_object != None,which menas the action is valid):
                session['room_name'] = planisphere.name_room(next_room_object)
                ##print("$$$ session['room_name'] 3 is:", session['room_name'])
        return redirect(
            url_for("game")
        )  # Scene 6. After Player click the submit,it will be redirected to game page(no matter the form is filled or not)
コード例 #13
0
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
           room = planisphere.load_room(room_name)
           return render_template("show_room.html", room=room)
       else: 
           # why is there here? do you need it?'
           return render_template("you_died.html")
    else:
コード例 #14
0
ファイル: app.py プロジェクト: thedoubl3j/python_playground
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)

        else:
            #why is this here? do you need it? yes, one so you can exit the inner loop? but also in case the logic in the game isn't met and you "die" this handles it.
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                session['room_name'] = planisphere.name_room(next_room)
コード例 #15
0
def game():
    #str1 = " Hello, World123"
    #return render_template("index.html",greeting=str1)
    ##greet = "Hello"
    ##hello = "ZhiTao."
    ##name = request.args.get('greet','hello')
    ##if name:
    ##    greeting = f'{greet}, {hello}'
    ##else:
    ##    greeting = "Hello world!"
    ##return render_template("index.html",greeting = greeting)

    #greeting = "Hello World!"
    #if request.method == "POST":
    #    name = request.form['name']
    #    greet = request.form['greet']
    #    greeting = f'{greet},{name}'
    #    return render_template("index.html",greeting = greeting)
    #else:
    #return render_template("hello_form.html")
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            #why is there here?do you need it?
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                session['room_name'] = planisphere.name_room
            else:
                session['room_name'] = planisphere.name_room
        return redirect(url_for("game"))
コード例 #16
0
def game():
    room_name = session.get("room_name")
    if request.method == 'GET':
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template('show_rooms.html', room=room)
        else:
            # Is this really neccessary?
            render_template('you_are_dead.html')
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                session['room_name'] = planisphere.name_room(room)
            else:
                session['room_name'] = planisphere.name_room(next_room)

        return redirect(url_for("game"))
コード例 #17
0
ファイル: app.py プロジェクト: keqiliu/LearnPython
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name and room_name != 'generic_death':
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                session['room_name'] = planisphere.name_room(room)
            else:
                session['room_name'] = planisphere.name_room(next_room)

        return redirect(url_for("game"))
コード例 #18
0
def game():
    #room name is taken from session name
    #breakpoint()
    room_name = session.get('room_name')
    if request.method == 'GET':
        if room_name:
            # if room name exist create a variable room with values from load room.
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            return render_template("you_died.html")
    else:
        # getting the 'action' value from show room html
        action = request.form.get('action')
        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)
            if not next_room:
                session['room_name'] = planisphere.name_room(room)
            else:
                session['room_name'] = planisphere.name_room(next_room)
        return redirect(url_for("game"))
コード例 #19
0
ファイル: app.py プロジェクト: jpch89/lpthw
def game():
    room_name = session.get('room_name')

    if request.method == 'GET':
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template('show_room.html', room=room)
        else:
            # why is there here? do you need it?
            # 在这里是为了防止用户不经过 /hello 直接进入 /game
            return render_template('you_died.html')
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)

            if not next_room:
                session['room_name'] = planisphere.name_room(room)
            else:
                session['room_name'] = planisphere.name_room(next_room)
        return redirect(url_for('game'))
コード例 #20
0
ファイル: app.py プロジェクト: socofels/mini-project
def game():
    # room_name是字符串 room 是变量
    room_name = session.get('room_name')
    if request.method == "GET":
        room = planisphere.load_room(room_name)
        return render_template("show_room.html", room=room)

    # 当输入提交的时候,任务转跳到这里
    else:
        action = request.form.get('action')

        if room_name and action:
            # room 就是 room_name 的变量
            room = planisphere.load_room(room_name)
            # 下一个房间就是room.go(对应的操作)
            next_room = room.go(action)
            if not next_room:
                # 如果你的动作没有下个房间,那么就保持原地不动
                #session['room_name']是字符串
                pass
            else:
                session['room_name'] = next_room

        return redirect(url_for("game"))
コード例 #21
0
def test_gothon_game_map():
    start_room = planisphere.load_room(START)
    assert start_room.go('dodge') == generic_death

    room = start_room.go('tell a joke')
    assert room == laser_weapon_armory
コード例 #22
0
ファイル: app.py プロジェクト: claws85/Gothons-game
def help():
    room_name = session.get('room_name')
    room = planisphere.load_room(room_name)
    return render_template("help.html", room=room)
コード例 #23
0
ファイル: app.py プロジェクト: claws85/Gothons-game
def game():
    user = User()
    form = RegisterForm()
    room_name = session.get('room_name') # returns name of room object from the session list
# if room_name = you_win then add 'winner' to user's place in database and the count. On dashboard, the only usernames that appear
# should be those with winner

    if request.method == "GET":
        if room_name:
            room = planisphere.load_room(room_name) # returns actual Room object
            return render_template("show_room.html", room=room, turns=turns) # renders show_room.html and sets room param for the template
        else:
            return render_template("you_died.html")
    else: # if POST
        action = request.form.get('action') # takes user input from form here as string
#       print(action)
#       print(type(action))

        if room_name and action: 
            room = planisphere.load_room(room_name)
            print(room) # this is the actual name of the room - "Central Corridor"
#            print(type(room))
            next_room = room.go(action)
            print(room_name) # room name is central_corridor and a string
            print(next_room)
#            print(type(room_name))

            if not next_room:
                session['room_name'] = planisphere.name_room(room)
                flash("Your last attempt was incorrect.")
                turns.count += 1
                print(turns.count)
                return redirect(url_for("game"))
 
            else:
                if action not in ["tell a joke", planisphere.code, "slowly place the bomb"]:
                    session['room_name'] = planisphere.name_room(next_room)
                    turns.count += 1
#                    print(turns.count)
                    print('potato')
#                    print(type(action))
                    if (action == '2') and current_user.data == 100000:
                        current_user.data = turns.count
                        db.session.commit()
                        print('new score added to user')
                    else:
                        if (action == '2') and current_user.data > turns.count:
                            current_user.data = turns.count
                            db.session.commit()
                            print('score updated')
                        else:
                            pass
#                    print('data updated')
#                    print(current_user.data)
                    return redirect(url_for("game"))
                else:
                    session['room_name'] = planisphere.name_room(next_room)
                    turns.count += 1
#                    print(turns.count)
#                    print(current_user.data)
                    return render_template("room_complete.html", room=room)
        
        else:
            flash("Your last attempt was incorrect.")
            turns.count += 1
#            print(turns.count)
            return redirect(url_for("game"))
コード例 #24
0
@app.route("/game", methods=['GET', 'POST'])
def game():
    room_name = session.get('room_name')

    if request.method == "GET":
        if room_name:
           room = planisphere.load_room(room_name)
           return render_template("show_room.html", room=room)
       else: 
           # why is there here? do you need it?'
           return render_template("you_died.html")
    else:
           action = request.form.get('action')

       if room_name and action:
           room = planisphere.load_room(room_name)
           next_room = room.go(action)
 
           if not next_room:
               session['room_name'] = planisphere.name_room(room)
           else:
               session['room_name'] = planisphere.name_room(next_room)

       return redirect(url_for("game"))

# YOU SHOULD CHANGE THIS IF YOU PUT ON THE INTERNET
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'

if __name__ == "__main__":
    app.run()