Edit4:
Moved the original (2009) code I had here to a gist.
Recently (August 2012) I wrote a series of blog posts on writing tetrix in Scala. I hope it answers some of the questions I asked three years ago.
Edit: Updated the code to use Scala's Swing API as suggested by @thatismatt. Also, I've found that the way to learn Scala style coding is to read the book by Martin Odersky called Programming in Scala. In essence, the Scala way is gradually shift from imperative style to functional style by using immutable data structure, functions without side-effects, pattern matching, traits, etc.
Edit2: Updated the code to use immutable data structure etc. For example Block#rotate now returns a new Block object instead of modifying itself.
Block#rotate
Edit3: Updated the code to work on Scala 2.8 RC3.
Aleksander's answer is correct, but Programming in Scala offers an additional alternative:
sealed trait Foo { // interface } object Foo { def apply(...): Foo = // public constructor private class FooImpl(...) extends Foo { ... } // real class }
Edit4:
Moved the original (2009) code I had here to a gist.
Recently (August 2012) I wrote a series of blog posts on writing tetrix in Scala. I hope it answers some of the questions I asked three years ago.
Edit: Updated the code to use Scala's Swing API as suggested by @thatismatt. Also, I've found that the way to learn Scala style coding is to read the book by Martin Odersky called Programming in Scala. In essence, the Scala way is gradually shift from imperative style to functional style by using immutable data structure, functions without side-effects, pattern matching, traits, etc.
Edit2: Updated the code to use immutable data structure etc. For example
Block#rotate
now returns a new Block object instead of modifying itself.Edit3: Updated the code to work on Scala 2.8 RC3.
Aleksander's answer is correct, but Programming in Scala offers an additional alternative: