def __init__(self, description_factory): self.descriptions = description_factory self.levels = [Level()] self.player = Player.create(self.levels[0], self.levels[0].get_random_walkable()) for n in self.player.pos.neighbors(): if self.levels[0].locate(n) and self.levels[0][n].is_walkable: self.levels[0][n].items = [HealingPotion()] self.messages = deque() self.commands = deque() self.turn = 0
def getLevel(identifier): """Get a level with its questions and their responses""" # Get the connection conn = getConnection() # Get the question question_cursor = executeRequest( """SELECT Level.Id, Level.Title, Question.Id, Question.Question, Response.Value, Response.Response, Response.Id FROM Level INNER JOIN Question ON Level.Id = Question.IdLevel INNER JOIN Response ON Question.Id = Response.IdQuestion WHERE Level.Id = """ + identifier + """ ORDER BY Question.Id, Response.Value""", conn) if question_cursor is not None: level = None current_question = None for row in question_cursor.fetchall(): # Title if level is None: level = Level() level.id = row[0] level.title = row[1] # Question if current_question is None or current_question.id != row[1]: current_question = Question() current_question.id = row[2] current_question.question = row[3] current_question.id_level = level.id level.questions.append(current_question) # Responses Level.Id, Level.Title, Question.Id, Question.Question, Response.Value, Response.Response, Response.Id response = Response() response.value = row[4] response.response = row[5] response.id = row[6] response.id_question = current_question.id current_question.responses.append(response) # Set the result result = getHTTPResponse(200, level) else: # Level does not exist result = getHTTPResponse(500, "This level does not exist", False) conn.close() return result
def put(self): payload = request.get_json(force=True) if payload is None: payload = {} new_level = Level(level_number=payload.get('level_number'), category_id=payload.get('category'), points_to_unlock=payload.get('points_need')) db.session.add(new_level) db.session.commit() return {'message': 'Successfully added'}, 200
def put(self): payload = request.get_json(force=True) category_id = payload.get('level') level = payload.get('level') points = payload.get('points') if payload is None: payload = {} new_category_level = Level(level_number=level, points_to_unlock=points, category_id=category_id) db.session.add(new_category_level) db.session.commit() return {'message': 'Level successfully added'}, 200
def getAll(): """Get all levels with their questions and their responses""" # Get the connection conn = getConnection() # Get the question question_cursor = executeRequest( """SELECT Level.Id, Level.Title, Question.Id, Question.Question, Response.Value, Response.Response, Response.Id FROM Level INNER JOIN Question ON Level.Id = Question.IdLevel INNER JOIN Response ON Question.Id = Response.IdQuestion ORDER BY Level.Id, Question.Id, Response.Value""", conn) levels = [] current_level = None current_question = None for row in question_cursor.fetchall(): # New level with title if current_level is None or current_level.id != row[0]: current_level = Level() current_level.id = row[0] current_level.title = row[1] levels.append(current_level) # Question if current_question is None or current_question.id != row[2]: current_question = Question() current_question.id = row[2] current_question.id_level = current_level.id current_question.question = row[3] current_level.questions.append(current_question) # Responses response = Response() response.value = row[4] response.response = row[5] response.id = row[6] response.id_question = current_question.id current_question.responses.append(response) # Set the result result = getHTTPResponse(200, levels) conn.close() return result
def begin(start=0): for i in range(start, len(ranks)): level_score = 0 level_attempts = 0 level_rank = ranks[i] level = Level(level_rank) start = time.time() while (time.time() - start < 60): level.read() key = console.getch() if key == level.key: level_score += 1 level_attempts += 1 level.restart() accuracy = round(level_score / level_attempts, 3) * 100 print("{} {} {}".format("Results for", user.rank, user.name)) print("{} {}".format("Your Score:", str(level_score))) print("{} {}".format("Attempts:", str(level_attempts))) print("{} {} {}".format("Efficiency:", str(accuracy), "%")) if accuracy > 75 and level_attempts > 45: if user.rank == "General": print("You Won!") return user.rank = ranks[i] print("{} {}{}".format("You've been promoted to ", ranks[i + 1], ".")) input('press enter to continue') else: desire = input("retry? Y/N\n") if desire.lower() == "y": begin(i) else: sys.exit()
def initialize_levels(self): database: Database = Database() evolution: Evolution = Evolution() level_01: Level = Level( 'level_01', '01', TextFileReader().read_text_file('level_01.txt')) level_02: Level = Level( 'level_02', '02', TextFileReader().read_text_file('level_02.txt')) level_03: Level = Level( 'level_03', '03', TextFileReader().read_text_file('level_03.txt')) level_04: Level = Level( 'level_04', '04', TextFileReader().read_text_file('level_04.txt')) level_05: Level = Level( 'level_05', '05', TextFileReader().read_text_file('level_05.txt')) level_06: Level = Level( 'level_06', '06', TextFileReader().read_text_file('level_06.txt')) level_07: Level = Level( 'level_07', '07', TextFileReader().read_text_file('level_07.txt')) level_08: Level = Level( 'level_08', '08', TextFileReader().read_text_file('level_08.txt')) tutorial: Level = Level( 'tutorial', 'tutorial', TextFileReader().read_text_file('tutorial.txt')) level_01 = Helper.clean_level(level_01) level_02 = Helper.clean_level(level_02) level_03 = Helper.clean_level(level_03) level_04 = Helper.clean_level(level_04) level_05 = Helper.clean_level(level_05) level_06 = Helper.clean_level(level_06) level_07 = Helper.clean_level(level_07) level_08 = Helper.clean_level(level_08) database.store_level_prototype(level_01) database.store_level_prototype(level_02) database.store_level_prototype(level_03) database.store_level_prototype(level_04) database.store_level_prototype(level_05) database.store_level_prototype(level_06) database.store_level_prototype(level_07) database.store_tutorial(tutorial) level_01 = evolution.evolve('random_distribution', level_01) level_02 = evolution.evolve('random_distribution', level_02) level_03 = evolution.evolve('random_distribution', level_03) level_04 = evolution.evolve('random_distribution', level_04) level_05 = evolution.evolve('random_distribution', level_05) level_06 = evolution.evolve('random_distribution', level_06) level_07 = evolution.evolve('random_distribution', level_07) level_08 = evolution.evolve('random_distribution', level_08) database.store_initial_level(level_01) database.store_initial_level(level_02) database.store_initial_level(level_03) database.store_initial_level(level_04) database.store_initial_level(level_05) database.store_initial_level(level_06) database.store_initial_level(level_07) database.store_initial_level(level_08)