def not_enough_money(wallet): if wallet <= 0: print( "You have no money in your wallet. Please refill your wallet or sit and just watch the menu." ) time.sleep(3) return MenuNode.current_node()
def email_prompt(cls): # Email prompt while True: print("Enter B to go back.") email_input = input("Enter your e-mail:\n") if email_input.lower() == 'b': return MenuNode.current_node() if cls.email_is_valid(email_input): if cls.email_in_database(email_input): print( "\nUser associated with this e-mail address already exists!\n" ) print( "Try logging in instead or recovering your password.") decision = input(""" Enter M to return to Main Menu. Enter E to try with a different e-mail. """) if decision.lower() == "m": return MenuNode.default_node() elif decision.lower() == "e": continue else: return email_input else: print("\nPlease enter valid e-mail address!\n") continue
def wallet_refill(): # player = User.logged # usr_dict = player.__dict__ req = RefRequest() req.save_request_in_reqs_box() time.sleep(3) return MenuNode.current_node()
def system_wallet(): games = read_data_from_games_database() total_register = games['games_inf']['total_register'] for gamename in games['games']: print(f"\n{gamename}: {games['games'][gamename]['register']}\n") total_register += games['games'][gamename]['register'] write_data_to_games_database(games) from structures.user_class import User if User.logged.is_admin: print(f"Total number of points in the system:\n{total_register}\n") inp = input("Press Enter to continue.") return MenuNode.current_node()
def username_prompt(cls): # Username prompt while True: print("\nEnter B to go back.\n") username = input("\nEnter your username:\n") if username.lower() == 'b': return MenuNode.current_node() elif cls.username_is_valid(username): return username else: print("Please enter a new username.\n") continue
def display_personal_best(gamename): users = read_data_from_users_database() playing_user = User.logged for user in users['users']: if user['username'] == playing_user.username: try: game_best = user['my_best'][gamename] except KeyError: user['my_best'][gamename] = {} user['my_best'][gamename]['score'] = 0 game_best = user['my_best'][gamename] write_data_to_users_database(users) print(f"\nYour personal best in {gamename} is:\n" f"\t\t\t{game_best['score']} points.\n") inp = input("\nPress Enter to continue.\n") return MenuNode.current_node()
def display_top_n(gamename, n=5): os.system('clear') games = read_data_from_games_database() try: top5 = games['games'][gamename]['top5'] except KeyError: games['games'][gamename] = {} games['games'][gamename]['top5'] = [] top5 = games['games'][gamename]['top5'] if len(top5) == 0: print('\nThere are no records yet!\n') else: top5.sort(key=lambda x: x['score'], reverse=True) top5 = top5[:n] print('\n\n\n') for i, result in enumerate(top5): print( f"{i + 1}| {result['username']} | {result['score']} | {result['datetime_details']}\n" ) inp = input('\nPress Enter to continue.\n') return MenuNode.current_node()
def start_game(game): playing_user = game.setting_player() while True: players_choice, drawn_value, players_money_bet = game.game( playing_user) game.evaluating_results(players_choice, drawn_value, players_money_bet, playing_user) print(f"\nSession's score: {game.score}.") print( f"\nCurrent's session results: {game.current_session_results}." ) print(f"\nYour wallet's status: {playing_user.wallet}.") # Updating user's wallet in the database if User.logged: users = read_data_from_users_database() for user in users['users']: if user['username'] == playing_user.username: user['wallet'] += game.score write_data_to_users_database(users) # Updating game's register in the database. games = read_data_from_games_database() games['games'][game.name]['register'] += -game.score write_data_to_games_database(games) rnd = game.round_end(game.score, playing_user) if rnd: break else: continue print("Coming back to the previous menu...") time.sleep(5) return MenuNode.current_node()
def wallet_status(): user = User.logged print(f'\nYou have {user.wallet} points in your wallet.\n') inp = input("Enter any key to go back.") return MenuNode.current_node()
def login_script(): # Searching for user in database identified_user = None while not identified_user: print('\n\nEnter R to return to main menu.') username_input = input('\nEnter your username or e-mail:\n') if username_input.lower() == 'r': return MenuNode.current_node() users = read_data_from_users_database() admins = read_data_from_admins_database() all_users = [] for adm in admins['admins']: all_users.append(adm) for usr in users['users']: all_users.append(usr) for user in all_users: if username_input == user['username'] or username_input == user[ 'email']: identified_user = User(dictionary=user) # if not dict_: ---> ---> identified_user.dictionary # dict_ = user # print(type(user)) # TODO Animation print("\nUser found!") break if not identified_user: print( "\nThis user does not exist. Try different username or register instead." ) time.sleep(2) continue # Verifying password count = 0 while count < 4: print('\n\nEnter R to return to main menu.') password_to_check = getpass.getpass("\nEnter your password:\n") if password_to_check.lower() == 'r': return MenuNode.current_node() salt = bytes.fromhex(identified_user.salt) new_key = hashlib.pbkdf2_hmac('sha256', password_to_check.encode('utf-8'), salt, 100000) if new_key.hex() == identified_user.key: print("\nPassword correct.\n") if identified_user.is_admin: Admin.logged = identified_user elif not identified_user.is_admin: User.logged = identified_user time.sleep(1) break else: print('\nPassword incorrect. Try again.\n') count += 1 if count > 3: print( "\nToo many tries. Please use 'Forget password' to regain access to your account.\n" ) print("\nResetting password...\n") # password_reset(identified_user) print(f'Returning to {MenuNode.default_node.name} in:') stop_watch_to_default_node(3) else: if identified_user.is_admin: User.logged = identified_user MenuNode.default_node = admin_Menu MenuNode.current_node = admin_Menu else: User.logged = identified_user MenuNode.default_node = MainMenuForUsers MenuNode.current_node = MainMenuForUsers return MenuNode.default_node()