class Tester( val play : PlayDirector, val nextScene : String, val extraValuables : int ) { var testsPending = 0 var checksCompleted = false var whyTestFailed : Input = Game.instance.resources.inputs.find( "whyTestFailed" ) init { println( "Running tests for : " + Game.instance.sceneName ) if ( play.mainStage.findRoleByClass( GateCompleted ) != null ) { testsPending++ } } fun tick() { if (! checksCompleted ) { if (testsPending == 0 && play.valuables <= extraValuables ) { checksCompleted = true if ( checkSquares()) { println( "Success : " + Game.instance.sceneName ) Game.instance.startScene( nextScene ) } } } } fun checkSquares() : boolean { for (actor in Game.instance.scene.findStage( "main" ).actors) { val message = checkActor( actor ) if ( message != null ) { println( "Check failed for " + actor + " : " + message ) return false } } return true } fun checkActor( actor : Actor ) : String { val role = actor.role if (role is Item) { val item = role as Item if (item.square == null) return "No square" if (item.square.occupant != item && item.square.alternateOccupant != item ) return "Not the occupant" } return null } fun onKey( event : KeyEvent ) { if (whyTestFailed.matches( event ) ) { for ( ap in play.mainStage.findRolesByClass( AutoPlayer ) ) { if (!ap.passes()) { println( "${ap} failed" ) } } for ( t in play.extraStage.findRolesByClass( Test ) ) { if (!t.passes() ) { println( "${t} failed" ) } } } } }