NonConForm State Engine for Java Script. The first example

3 10 2014

I started to port my NonConForm library from the Falcon to Python a while ago. Now I started to port it to JavaScript as well. Today the state engine, the heart of the gaming menu framework is finished.

Here the first example:


-------------------------------------------------
declare states
-------------------------------------------------
var stGame = new NcfState("Game");
var tFinishFromGame = new NcfTransition("FinishFromGame","End",function() {});
stGame.addTransition(tFinishFromGame);
Ncf.addState(stGame);
-------------------------------------------------
define view
-------------------------------------------------
Ncf.getState("Game").setView(
function() {
Ncf.log("View");
Ncf.transit("FinishFromGame");
}
)
-------------------------------------------------
define controller
-------------------------------------------------
Ncf.getState("Game").setController(
function() {
Ncf.log("Controller");
Ncf.transit("FinishFromGame");
}
)
-------------------------------------------------
start engine
-------------------------------------------------
Ncf.setDebugMode(true);
Ncf.init(50,"Game");

and here is the output

initialize NonConForm
—————————–
start NonConForm state engine
—————————–
Leaving:Start
|——————Transit to——————|:Game
Entering:Game
NonConForm main loop started
Main Loop
View
Controller
Leaving:Game
|——————Transit to——————|:End
—————————–
finishing NonConForm
—————————–
NonConForm main loop stopped

Advertisements