How to create custom level set¶
-
class
asterios.level.
BaseLevel
(difficulty)¶ Asterio groups the levels by module name. The levels in the module should be named from Level1 to LevelN. Each level is a BaseLevel subclass and redefines two methods. generate_puzzle and check_answer. The docstring of level count. This is a tip to resolve the puzzle send to users.
Example, you can create a class that send a list to sort:
import random from asterios.level import BaseLevel, Difficulty class Level1(BaseLevel): """ help(list.sort) ;-) """ def generate_puzzle(self): puzzle = list(range(200)) self.expected = list(range(200)) random.shuffle(puzzle) return puzzle def check_answer(self, answer): if answer == self.expected: return (True, 'Good job :-D') if not isinstance(answer, list): return (False, 'You should send me a list') if len(answer) != len(self.expected): return (False, 'The list should have {} elements'. format(len(self.expected))) return (False, 'Send me a sorted list')
When a BaseLevel subclass is instantiate, the difficulty parameters is provided. The difficulty value is a level.Difficulty member.