Phil Trelford's Array
POKE 36879, 255

Tetris

June 25, 2011 12:40 by phil

Playable Silverlight mini-game implemented with a couple of hundred lines of F#!

Keys: Left Arrow = Left, Right Arrow = Right, Up Arrow = Rotate, Down Arrow = Drop

 

Can also be run as an editable script inside TryFSharp.org.

The main game loop:

let rec gameLoop () =  async {
    do! prompt "Click To Start" awaitingClick                                    
    do! inGameLoop ()         
    do! prompt "Game Over" paused        
    well.Clear()
    return! gameLoop ()
    }

The game makes use of F#’s Asynchronous Workflows to simplify the asynchronous flow. The game loop above looks as if it is run synchronously. But by simply wrapping the code in an async block it can be run asynchronously!

Resources


Tags:
Categories: F# | Silverlight | .Net
Actions: E-mail | Permalink | Comments (6) | Comment RSSRSS comment feed

Comments

June 25. 2011 14:48

Apali

Great, now make it playable.

Apali

June 25. 2011 15:10

reno

Sweet!  Thxs for the code also!

reno

June 26. 2011 02:39

Don

Nice sample, lovely code Smile

I think it needs the space-bar-drops-brick-to-the-bottom?

Don

June 28. 2011 01:13

Phil

Thanks Don,

You can now press the down arrow key to drop the bricks quickly to the bottom.

Phil

August 4. 2011 12:02

pingback

Pingback from 1flewoverthenest.wordpress.com

The SPR as a National Piggy Bank « 1flewoverthenest

1flewoverthenest.wordpress.com

August 9. 2011 01:05

pingback

Pingback from 1flewoverthenest.wordpress.com

Vanished – Book Review « 1flewoverthenest

1flewoverthenest.wordpress.com

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading