Sphynx.Riddle (Sphynx v0.1.1) View Source
Module Riddle
defmodule NumberOfExploitsOfHercules do
use Sphynx.Riddle
end
All functions, which implemented in our example (NumberOfExploitsOfHercules
) is a part of game lifecycle.
Roadmap of riddle looks like:
Creating the riddle. Calling
create/2
function withcontext
(map) andoptions
(keyword). Thecontext
andoptions
params passing throughcontext/1
andinit/1
functions (can be overriden).Send riddle to game. When riddle were sent to game, riddle are makes. In this case, a call
make/1
occurs.Processing the answer of user. In this point system calls
answer/1
and sends result of this call into thecheck/3
.Result of
check/3
redirects toverdict/2
. If result have specific pattern - next riddle will be maken, otherwise - result will be returned to guessing man.
Generally: Need to define your riddle module (lets name it NumberOfExploitsOfHercules
). Riddle module have to
use Sphynx.Riddle
and implement his required functions.
defmodule NumberOfExploitsOfHercules do
use Sphynx.Riddle
end
What is inside:
Your module have to implement collbacks from Sphynx.Riddle
. Some of collbacks are required, some - not. The some
function overridable and have default definition. There functions gonna be called by Sphynx.Clash
in game progress.
Requireds:
answer/1
- function for returning correct answer to your question. And it's not static value necessarily. This function receives the current riddle implementation as argument and you can use it for making a different answers depending on situation.check/3
- Function for checking and returnning result. It receives arguments:- Current module implementation.
- Correct answer. This value - result of calling
answer/1
. - Answer for checking. It's data with user answer, accepts any type.
verdict/2
- Function for delivery of a verdict. Receives 2 argument:- Current module implementation.
- Result of checking. That is data, which been returned by
check/3
Optional:
Link to this section Summary
Types
A struct for user module which implement Sphynx.Riddle
Link to this section Types
Specs
A struct for user module which implement Sphynx.Riddle
Link to this section Functions
Specs
Function for putting custom context data
This function calls context/1
of received riddle and pass exist context
to it. Result are the data,
which will been putted into :context
field of current riddle.
Arguments
User module with implementation of
Sphynx.Riddle
Data, which will been sent as argument into
context/1
function ofriddle
Specs
Function for putting options of riddle instance
This function calls init/1
of received riddle and pass exist options
to it. Result are the data,
which will been putted into :options
field of current riddle.
Arguments
User module with implementation of
Sphynx.Riddle
Data, which will been sent as argument into
init/1
function ofriddle