The Source for Java Technology Collaboration
User: Password:



Joshua Marinacci

Joshua Marinacci's Blog

LightsOut, a JavaFX Script game

Posted by joshy on December 05, 2007 at 09:01 AM | Comments (18)

Since I joined the JavaFX team a few months ago I have spent some of my free time creating demos and learning the language. Most of my demos have been simple single class applications that highlight a particular language feature or graphical effect. After a while, though, I decided to write something bigger to prove it could be done and really stress test the language. As a result of feedback from me (and many other dedicated early adopters) we have some great improvements coming down the pipe.

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 :).

net.java.javafx.FXShellScreenSnapz002.png
Losing badly at Lights Out

I had planned to release it earlier but decided to wait until NB 6 was final in case there were any last minute changes.

You can run the program using Java WebStart or download a zip of the NetBeans project. I went through the code this morning to clean up a few things and add documentation. Let me know what other demos you'd like to see.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Hi Josh

    Won't run:

    java.lang.SecurityException: Bad main-class name
    at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1040)
    at com.sun.javaws.Launcher.run(Launcher.java:105)
    at java.lang.Thread.run(Thread.java:619)

    Java Web Start 1.6.0_05-ea
    Using JRE version 1.6.0_05-ea Java HotSpot(TM) Client VM

    Patrick

    Posted by: pdoubleya on December 05, 2007 at 09:09 AM

  • It runs nicely on mine. I have update 2 though on XP. Hey Josh, care to share with us what are some these great improvements that are coming down the pipe. Or is that going to be the subject of another post? Also, have have you ever experimented with pop up dialogs/tooltips translucent or otherwise, in JavaFX? I would really like to know how to go about doing such things in JFX?

    Thanks,
    Mike

    Posted by: mikeazzi on December 05, 2007 at 09:21 AM

  • There's no way I could cover everything so I'll wait until it's released and do a series of blogs. There's a ton of under the cover changes that will improve speed and stability. There are also a few language changes/additions that will make complex animations a lot easier to do.

    Posted by: joshy on December 05, 2007 at 09:22 AM

  • I have been doing lightweight popups with translucent rectangles and such (as you can see in this game). For true heavyweight translucent popups, we are working on that but I can't say when we'll have something for you to download.

    Posted by: joshy on December 05, 2007 at 09:24 AM

  • I noticed you're using the deployment toolkit from update N. Since I am running update N EA JVM, is this a fair representation of how download and deployment of JavaFX stuff will be with it?

    Posted by: mrmorris on December 05, 2007 at 11:06 AM

  • I still had to manually make a JNLP file and provide my own copy of the JavaFX runtime. In the future it will be easier than what I've done to deploy JavaFX applications. I believe the javascript hooks loaded from Sun's servers are fairly represenative, though I'm sure they will improve over time.

    Posted by: joshy on December 05, 2007 at 11:28 AM

  • Josh, on my Mac (Tiger) the demo runs without a problem--so am not sure what the issue on my Ubuntu box is (I did try clearing the cache, to no avail). The game is cool and a nice improvement over your first demo a few weeks ago. Keep it up!

    Posted by: pdoubleya on December 05, 2007 at 12:41 PM

  • Patrick, are u sure it was launched with sun javaws and not the gcj version? Run's just fine on my ubuntu box.

    Posted by: rah003 on December 05, 2007 at 11:39 PM

  • @rah003: yeah, I just double-checked. It appears to be a problem with 1.6.0_05-ea. If I run with 1.6.0_03 it works on this machine.


    Patrick

    Posted by: pdoubleya on December 06, 2007 at 01:03 AM

  • Joshy, One of the things that u pointed out abt the declarative style of javafx seems one of the most difficlut things to adopt to in my opinion especially for procedural programmers.

    Posted by: psychostud on December 07, 2007 at 01:10 AM

  • I really hope they start working on allowing javafx apps to run as applets sometime.
    I do educational software, and for example a lot of times students don't have permission to download even a small jnlp file.
    Plus, it would make java more competitive with flash's features.

    Posted by: dug on December 07, 2007 at 08:20 AM

  • dug: Yep. We are aware of the applet issues and are working to fix them. Trust me, we *know* how important applets are. When we are done they will rock!

    Posted by: joshy on December 07, 2007 at 08:31 AM

  • Nice game. Does level advancement increase the difficulty? After level 30 I grew tired :-)

    One little thing: while the "Finished Level..." popup is shown, you can still click on the blue squares, and the game "resets" your score to level 1.

    All in all, great proof of concept. I'm looking forward to using JavaFx in a real Java app.

    Thanks!

    Posted by: agusmba on December 08, 2007 at 02:39 AM

  • The game does increase with each level because it pre-initializes more cells. There's a limit, however, to how complicated a 5x5 board can be. A more polished version could have larger boards. Sorry about the clickability bug. I need to put a transparent shape above the board to block input.

    Posted by: joshy on December 08, 2007 at 09:02 AM

  • Nice example runs fine once downloaded. However are there any other deployment models available other than webstart. i'm sure you woudl agree that 2.5mb is more than a little excessive for an application of this type. Kind Regards, Mark

    Posted by: medgington on January 03, 2008 at 10:31 AM

  • medgington the current deployment scheme is temporary. We will have aggressive library caching and applet support in the future. This is planned for the next big update of the JRE (Update N).

    Posted by: joshy on January 03, 2008 at 10:45 AM

  • excellent news. Thanks, Mark

    Posted by: medgington on January 04, 2008 at 03:31 AM

  • Great, would love some step-by-step blogs to give some nice ideas about what to do with this interesting language.

    Posted by: elwis on January 24, 2008 at 10:38 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds