My Silverlight Game

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Thought some of you guys might like to take a look at the Silverlight 2 project I have been hacking away on over the holidays.

Google Image Memory

The game basically searches Google Images based on some words you provide, and arranges the resulting pictures into a "memory" game where you try to match up the duplicates.

I messed with Silverlight 1 and it had quite a few warts and limitations (not least of which was that you couldn't do cross-domain webservices calls the way this game does). Version 2 is greatly improved and much more stable, but not without warts. I'm going to be writing a little bit about those in the coming days on my blog, but basically it's fun to work in, and you can do some pretty slick stuff.

To play you'll need Silverlight 2.0.

Update: Here's the source code and project files, for anyone who is interested.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
My pet peeve is the amount of network traffic that goes back and forth - not specific to your application, but for Silverlight in general. It becomes even more obvious when certain WPF API's are invoked. Nevertheless, I haven't developed enough applications for Silverlight yet, so I'll hold on to my thoughts before I pass any adverse judgment.

But good job with the game. I can only wonder about *all* the JavaScript and the HTML it would take to write a similar app! Such technologies are only a boon to programmers and productivity in general.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Thanks for the comments :). Silverlight is all client-side, so assuming no ajax or soap calls then after the initial load of the XAP file and resources there isn't much reason for a ton of network traffic. However, if the apps are larger then developers often split them up into multiple assemblies to speed load time, and in that case you will see additional resources fetched as you use the program. And of course a game like this one makes a few calls as part of its core operation.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Looks good :) Nice and simple!

Are all of the graphics custom or does silverlight come with some decent UI widgets to use? Can it use existing .NET forms?
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
Originally posted by: Crusty
Looks good :) Nice and simple!

Are all of the graphics custom or does silverlight come with some decent UI widgets to use? Can it use existing .NET forms?

Windows Forms and WPF are mutually exclusive (I know we're talking about Silverlight, but the XAML constructs in WPF and Sliverlight are the same). You can host Windows Forms in a WPF app using something called Windows Forms Integration control.

For graphics, you have Expression Blend (for desktop apps) and Expression Web (for Silverlight and Web apps). Basically, all the constructs in the new API's in .NET 3.5 (things like DoubleAnimation, Splines, etc.) can be used for generating graphics - be it WPF or Silverlight. In short, there are no out-of-the-box widgets. But creating simple graphics, animations, etc. is not at all hard given the tools. The learning curve is simpler assuming you have extensive .NET experience.

Having said that, I have done minimal deployment using Silverlight, so don't know all the logistics. Maybe Mark can throw some light on that. For WPF, you get the usual .NET .exe up on compilation.
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,675
146
106
www.neftastic.com
Mine is betterer..... :p

I should also point out that this is also an exercise in learning .Net 3.5 and Silverlight 2.0 for myself. Flash is undoubtedly "easier" in some respects, but I like the idea of not having to learn "a whole" API and language, not that Flash/AS3 is very hard in my opinion.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: Crusty
Looks good :) Nice and simple!

Are all of the graphics custom or does silverlight come with some decent UI widgets to use? Can it use existing .NET forms?

Thanks! As Dhaval pointed out, WPF and Windows Forms are different technologies. There is an interop bridge between them, so that you can host Forms in a WPF app and vice versa, but outside of a few areas there isn't a ton of reasons to do it.

Silverlight is a sandboxed version of WPF and the .NET framework optimized to run in a browser. The class library includes quite a few controls, and you follow the typical path of compositing the primitive controls into more complex types. In the case of the game I created a new UserControl called a MemoryCell that uses an Image control to host the images, and supports the animations and events needed to open and close the cover, etc. Pretty ordinary approach.

The challenging part of the project was actually figuring out the Google json data from their REST API, and getting it to deserialize properly. That and a few quirks with the way that WebClient and async image downloads work.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: Kenji4861
This is actually quite fun.. .... if ... you search the right terms.

Haha, and uncheck the "safe search" checkbox ;).

Sorry about the Chrome thing, but I guess there is no plugin for it yet.
 

Rangoric

Senior member
Apr 5, 2006
530
0
71
Why do you need .Net 3.5? Silverlight 2 doesn't require it to run on a client machine.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: Rangoric
Why do you need .Net 3.5? Silverlight 2 doesn't require it to run on a client machine.

DataContractJsonSerializer.ReadObject()

FYI, it doesn't work with Safari. It just shows like 1/10th of a rectangle image.

Pretty cool appl though!

Thanks. Is there actually a Silverlight plugin for Safari? If the only problem is sizing of the iframe I can fix that.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
Originally posted by: Markbnj
Originally posted by: Rangoric
Why do you need .Net 3.5? Silverlight 2 doesn't require it to run on a client machine.

DataContractJsonSerializer.ReadObject()

FYI, it doesn't work with Safari. It just shows like 1/10th of a rectangle image.

Pretty cool appl though!

Thanks. Is there actually a Silverlight plugin for Safari? If the only problem is sizing of the iframe I can fix that.

But you don't require .NET 3.5 on the client, right? I wouldn't know because I have .NET 3.5 on all my machines.
 

SoundTheSurrender

Diamond Member
Mar 13, 2005
3,126
0
0
Originally posted by: Markbnj
Originally posted by: Rangoric
Why do you need .Net 3.5? Silverlight 2 doesn't require it to run on a client machine.

DataContractJsonSerializer.ReadObject()

FYI, it doesn't work with Safari. It just shows like 1/10th of a rectangle image.

Pretty cool appl though!

Thanks. Is there actually a Silverlight plugin for Safari? If the only problem is sizing of the iframe I can fix that.

Yes there is. This program doesn't require .NET 3.5 for clients, it's server side. I'm running Leopard and it works, just not right.

If you want you could get Safari for Windows and see the problem.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: Dhaval00
Originally posted by: Markbnj
Originally posted by: Rangoric
Why do you need .Net 3.5? Silverlight 2 doesn't require it to run on a client machine.

DataContractJsonSerializer.ReadObject()

FYI, it doesn't work with Safari. It just shows like 1/10th of a rectangle image.

Pretty cool appl though!

Thanks. Is there actually a Silverlight plugin for Safari? If the only problem is sizing of the iframe I can fix that.

But you don't require .NET 3.5 on the client, right? I wouldn't know because I have .NET 3.5 on all my machines.

The Silverlight application runs entirely on the client, against a sandboxed version of the .NET 3.5 libraries. The only piece on the server is the HTML page it is embedded in.

Yes there is. This program doesn't require .NET 3.5 for clients, it's server side. I'm running Leopard and it works, just not right.

If you want you could get Safari for Windows and see the problem.

It's almost certainly the javascript I am using to dynamically resize the enclosing iframe. The app is hosted on Microsoft's Silverlight streaming server, and they use a sort of funky scheme that requires an embedded iframe in the page that pulls the Silverlight control. I'll take a look at it.
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,675
146
106
www.neftastic.com
Originally posted by: Markbnj
Originally posted by: Rangoric
Why do you need .Net 3.5? Silverlight 2 doesn't require it to run on a client machine.

DataContractJsonSerializer.ReadObject()

FYI, it doesn't work with Safari. It just shows like 1/10th of a rectangle image.

Pretty cool appl though!

Thanks. Is there actually a Silverlight plugin for Safari? If the only problem is sizing of the iframe I can fix that.

Silverlight 2.0 requires .Net 3.5.

There is a Mac plugin for Silverlight 2.0, but only for x86. PowerPC Macs are limited to 1.0.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
Originally posted by: Markbnj
The Silverlight application runs entirely on the client, against a sandboxed version of the .NET 3.5 libraries. The only piece on the server is the HTML page it is embedded in.

I wasn't alluding to the architecture or makeup of Silverlight - your original post lists .NET 3.5 as a requirement. So I was trying to clarify if the clients need to install .NET 3.5 in order to play with the app. My understanding is all the clients need is Silverlight installed. .NET 3.5 goes on the server side.
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,675
146
106
www.neftastic.com
Originally posted by: Dhaval00
Originally posted by: Markbnj
The Silverlight application runs entirely on the client, against a sandboxed version of the .NET 3.5 libraries. The only piece on the server is the HTML page it is embedded in.

I wasn't alluding to the architecture or makeup of Silverlight - your original post lists .NET 3.5 as a requirement. So I was trying to clarify if the clients need to install .NET 3.5 in order to play with the app. My understanding is all the clients need is Silverlight installed. .NET 3.5 goes on the server side.

I don't believe so. The server has no need to run the bytecode, it's downloaded to the client and run in the browser/runtime there. My site is hosted on Google Apps, which hosts my Silverlight 2 pong game. I seriously doubt Google is running their servers on IIS.
 

tatteredpotato

Diamond Member
Jul 23, 2006
3,934
0
76
FYI it does work on Google Chrome 1.0.154.36, although SunnyD's app really doesn't, the ball just goes back and forth in a straight line.
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,675
146
106
www.neftastic.com
Originally posted by: ObscureCaucasian
FYI it does work on Google Chrome 1.0.154.36, although SunnyD's app really doesn't, the ball just goes back and forth in a straight line.

Works fine in Chrome here... hmm.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: Dhaval00
Originally posted by: Markbnj
The Silverlight application runs entirely on the client, against a sandboxed version of the .NET 3.5 libraries. The only piece on the server is the HTML page it is embedded in.

I wasn't alluding to the architecture or makeup of Silverlight - your original post lists .NET 3.5 as a requirement. So I was trying to clarify if the clients need to install .NET 3.5 in order to play with the app. My understanding is all the clients need is Silverlight installed. .NET 3.5 goes on the server side.

Installing Silverlight 2 might very well also install the .NET 3.5 framework if it isn't there, so you might be right about that. In any case, you need it on the client to run the app. As I said earlier, there's nothing on the server except the .xap file that contains the assembly and resources, and a little html.