documentation additions
This commit is contained in:
parent
8c1e960702
commit
f73b94d593
|
@ -1,7 +1,11 @@
|
|||
import yaml # reads hint configurations from a .yml file
|
||||
|
||||
class HintGiver:
|
||||
"""Class holding all the possible hints for all levels, and giving them
|
||||
out when asked for."""
|
||||
|
||||
def __init__(self, hint_filename):
|
||||
"""Create a hint giver from file `filename`."""
|
||||
self.total_hints_taken = 0
|
||||
self.hints_taken = {} # dict, level : [hint_name, hint_name]
|
||||
|
||||
|
@ -14,9 +18,11 @@ class HintGiver:
|
|||
self.hints = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
||||
def show_possible_hints(self, level, branch):
|
||||
"""Return all possible hints for given `level` and `branch`."""
|
||||
return list(self.hints[level][level+branch])
|
||||
|
||||
def take_hint(self, level, branch, hint_name):
|
||||
"""Show hint text for a specific hint. Add it to hint log and counter."""
|
||||
if not level+branch in self.hints_taken:
|
||||
self.hints_taken[level+branch] = []
|
||||
if hint_name not in self.hints_taken[level+branch]:
|
||||
|
@ -25,19 +31,23 @@ class HintGiver:
|
|||
return self.hints[level][level+branch][hint_name]
|
||||
|
||||
def show_taken_hints(self, level, branch):
|
||||
"""Show all previously taken hints for `level` and `branch`."""
|
||||
if not level+branch in self.hints_taken:
|
||||
return []
|
||||
return self.hints_taken[level+branch]
|
||||
|
||||
def is_hint_name(self, level, branch, hint_name):
|
||||
"""Check if `hint_name` is a name of a hint for `level` and `branch`."""
|
||||
if hint_name in self.hints[level][level+branch]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def restart_game(self):
|
||||
"""Reset hint counter and hint log to zero."""
|
||||
self.total_hints_taken = 0
|
||||
self.hints_taken = {}
|
||||
|
||||
def log_to_file(self, filename):
|
||||
"""Write taken hints to a file."""
|
||||
with open(filename, 'a') as f:
|
||||
yaml.dump(self, f)
|
|
@ -1,25 +1,35 @@
|
|||
import yaml # reads hint configurations from a .yml file
|
||||
|
||||
class LevelSelector:
|
||||
"""Class handling selection of next level to play, in player's place.
|
||||
|
||||
Needs a file with level requirements, and a file with possibly mastered tools.
|
||||
If a player knows a tool, and is under time limit, they are eligible for that level.
|
||||
|
||||
Levels with None requirements are a "default" that anyone can take."""
|
||||
def __init__(self, tool_list_filename, level_requirements_filename):
|
||||
self.read_level_requirements(level_requirements_filename)
|
||||
self.read_tool_list(tool_list_filename)
|
||||
self.known_tools = []
|
||||
|
||||
def read_level_requirements(self, filename):
|
||||
"""Reads level requirements from file `filename`."""
|
||||
with open(filename) as f:
|
||||
self.level_requirements = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
||||
def read_tool_list(self, filename):
|
||||
"""Reads list of tools from file `filename`."""
|
||||
with open(filename) as f:
|
||||
self.tool_list = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
||||
def add_known_tool(self, tool):
|
||||
"""Add tool `tool` to list of known tools."""
|
||||
if tool in self.known_tools:
|
||||
return
|
||||
self.known_tools.append(tool)
|
||||
|
||||
def next_level(self, current_level, current_time):
|
||||
"""Select what the next level should be after `current_level`."""
|
||||
next_levels = self.level_requirements["level" + str(current_level+1)]
|
||||
if len(next_levels) == 1:
|
||||
return next_levels[0][0]
|
||||
|
|
Reference in New Issue