Thursday, December 13th, 2007
LightsOut: JavaFX Script Game
Joshua Marinacci, of Sun, has been playing with JavaFX Script. As a way to learn the new language he developed:
Writing this game really taught me the Zen of JavaFX Script (hmm... sounds like a good book title). I often have to fight my procedural Java instincts and instead use binding and triggers wherever possible. It's really a different way of thinking, closer to Lisp or Prolog (and even a bit of SQL), but quite powerful. I'm sure I didn't get it perfect and I bet I could rewrite it in a few more months using a better style, but this is a good start.
So I'd like to share with you my first real JavaFX Script application. It's a simple puzzle game where you click grid cells to turn off the light. As you click each cell the adjacent cells flip as well. You win the game by turning off all lights (hence the name :).
You can download the code and take a peak at the new language:
-
-
operation init();
-
attribute model: LightsOutModel;
-
}
-
-
//set up the main screen
-
operation LightsOutCanvas.init() {
-
var cc = ColorConstants;
-
model = LightsOutModel;
-
model.init();
-
model.randomize();
-
-
//background and grid
-
insert Rect {width:400,height:300,fill:cc.slate } into content;
-
insert model into content;
-
-
//reset button
-
insert BlueButton {
-
text : "Reset"
-
transform: translate(305,15)
-
width: 80, height: 30
-
onMousePressed : operation(e) { model.randomize(); }
-
} into content;
-
-
//score
-
insert Text {content:"Moves", x:310, y:90, fill:white, font: new Font("Arial","BOLD",20) } into content;
-
insert Text {content: bind model.moveCount.intValue().toString(),
-













JavaFX looks interesting, but reports about it being really slow keeps me from looking more into it: http://metalinkltd.com/?p=139
Also, getting 2-3 scary dialogs to run a JavaFX application makes it unsuitable for the web.
The iphone version of this looks *slightly* better.
http://www.deliciousmonster.org/
#1. old link!
http://blogs.sun.com/chrisoliver/entry/compiled_javafx_script for more accurate performance
Another thing, its a 2.5 MB download…