10_hangman/src/Outcome.java

/*
 * Copyright 2001-2006 Geert Bevin <gbevin[remove] at uwyn dot com>
 * Distributed under the terms of either:
 * - the common development and distribution license (CDDL), v1.0; or
 * - the GNU Lesser General Public License, v2.1 or later
 * $Id: Outcome.java 3364 2006-07-10 10:33:29Z gbevin $
 */
import com.uwyn.rife.engine.annotations.Elem;
import com.uwyn.rife.engine.annotations.Flowlink;
import com.uwyn.rife.engine.annotations.SubmissionHandler;
import com.uwyn.rife.template.Template;
import model.Game;

@Elem(
    flowlinks = {@Flowlink(srcExit = "guess", destClass = Guess.class, redirect=true)}
)
public class Outcome extends AbstractHangmanElement {
    @SubmissionHandler
    public void doPlayAgain() {
        getGame().newGame();
        exit("guess");
    }
    
    public void processElement() {
        Template t = getPropertyTyped("template", Template.class);
        
        Game game = getGame();
        if (t.hasValueId("guesses")) {
            t.setValue("guesses", game.getGuessesRemaining());
        }
        t.setValue("word", encodeHtml(game.getWord().asString()));
        
        print(t);
    }
}