File size: 1,357 Bytes
8210d08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import streamlit as st
from utils.login import get_login
import os

def initialize_level():
    if 'level' not in st.session_state:
        if get_login()["status"]:
            if not os.path.exists(f".sessions/{get_login()['username']}/level.txt"):
                with open(f".sessions/{get_login()['username']}/level.txt", "w") as f:
                    f.write("0")
                st.session_state['level'] = 0
            else:
                with open(f".sessions/{get_login()['username']}/level.txt", "r") as f:
                    st.session_state['level'] = int(f.read())

def get_level():
    return st.session_state['level']

def render_page(page, level):
    if get_login()["status"]:
        if st.session_state['level'] < level:
            st.error(f"You need to complete Level {st.session_state['level']} first!")
        else:
            page()
    else:
        st.error("You need to login first!")

def complete_level(level):
    if st.session_state['level'] > level:
        st.info(f'You have Already completed Level {level}!')
    else:
        st.session_state['level'] = level + 1
        with open(f".sessions/{get_login()['username']}/level.txt", "w") as f:
            f.write(str(st.session_state['level']))
        st.balloons()
        st.success(f'You have completed Level {level}! You can now move on to the next level.')