Windows Phone 7 Pelmanism

image

Spent some of today converting an old XNA version of Pelmanism to run on Windows Phone 7. It was actually very easy, particularly once I started using the gesture support in XNA 4.0 With that I could  just pick up tap events and use them in the program to select matching tiles.

At the moment the game uses 50 different images which I had originally scaled for an Xbox 360. This gave me a game size of 16Mb, which is quite large for Windows Phone game. But it downloaded to the device and ran quite happily. I’ve resized the pictures now and taken 10M off the size.

Next step is to use Flickr images from the new FlickrNet API that makes it easy to pull images onto the phone.

Unblocking Files from the Internet

image

Sometimes you get a file from the internets, or in an email, which you actually trust. Thing is, Windows doesn’t. This can result in fun and games when you try to use this file or, if it is an archive, files from the archive.

As an example, I downloaded the TouchGestureSample from the Creators Club and I don’t want any messages about un-trusted files in Visual Studio 2010.

Solving this is actually quite easy (and best done before you remove the files from the archive). Right click on the item and then click Unblock to say that you trust this file.

(of course, if you do this with dangerous files it might not have a happy ending)

Getting Diagnostic Output from your Windows Phone programs

Birthday Phone

It is often very useful to find out what your programs are doing. You can put breakpoints into your code, but sometimes you just want print messages. If you are writing Windows Phone apps this is very easy, but it doesn’t use the Console.WriteLine that you might be used to. You can get messages from your Windows Phone program (even when it is running in the device) by using:

System.Diagnostics.Debug.WriteLine ("Your Message Here ");

The output appears in the Output window in Visual Studio 2010  (remember to ask it to show you output from the Debug stream). The best way to control debug output is to use conditional compilation to switch your debug statements on and off:

// Put this at the top of the program to turn debugging on
#define Debug

#ifdef Debug
System.Diagnostics.Debug.WriteLine ("Debug Message Here ");
#endif

Cheap Network Connection

Hull Building

Nice building in Hull today.

If you have an internet enabled phone and want the cheapest way to get on-line with it you really should take a look at Tesco Mobile.  These folks will send you a free pay as you go sim (it costs 99 pence to buy in the store) and you can put credit on it in all the usual ways. You can also have a 2 pounds a week “unlimited use” network connection for your phone. In this case I think “unlimited” means 500 megs in the week, which is OK unless you start streaming “Deal or No Deal” to it. But then again, why would you want to do that?

It does mean that you can have a fully working internet phone for around 8 pounds a month, which has got to be good value. I popped one of these into my Windows Phone and it works a treat. The network is actually provided by O2, which may or may not be good news depending on where you live.

Mystery Object Competition

Mystery Object

So, what was this used for?

Mystery Closeup

Close up of the pointy end

I found this in my drawer today. Not used it for a while. I’ve got a Windows Phone Lanyard (tastefully printed with a Windows Phone logo all along its length) to give to the first person to come to my office in Hull and tell me what is and what we used to use it for.

A clue, it is not directly related to phones as such…

Overlapping Display Elements in Silverlight

Blackjack in White

Overlapping cards in a white version of the game. I just changed the Settings to a white background, everything else was sorted out automatically.

I’ve solved my five card problem. I’m not sure if I’ve cheated or not, but I am sure that it works.

image

The way it works is by giving elements in the StackPanel a negative left margin, so that they go into the element to the left. The StackPanel only seems to use the width remaining width for each item in the panel, so I end up with all the card displays overlapping nicely.

Silverlight Blackjack for Windows Phone 7

Silverlight Blackjack for Windows Phone
Well, what would you do?

For no particular reason (perhaps because I’ve got lots of other, more important, things to do) I’ve been working on a version of Blackjack for Windows Phone 7. I’ve come across an interesting philosophical/moral problem.

At the moment my display has room for only five cards. If a player gets a lot of low cards then they can fall off the end of the screen. I can think of two ways to fix this.

  1. Spend some time re-arranging the display so that cards can overlap and I can fit up to 21 cards (the absolute limit given that you are playing with six decks in the shoe) on the screen.
  2. Make the fifth card you get always a king.

Windows Phone 7 Accelerometer Values

IMG_2120

I’ve been playing with the accelerometer in Windows Phone 7 and trying to make sense of the outputs. If you are interested (and, I guess if you are not) these are the values for the different orientations:

Flat on the desk: X=0, Y=0, Z=-1
Upside down on the desk:X=0, Y=0, Z=1
Standing like a tombstone: X=0,Y=-1, Z=0
Standing like an upside down tombstone: X=0,Y=1,Z=0
Landscape – controls on right: X=-1,Y=0,Z=0
Landscape – controls on left: X=1,Y=0,Z=0

The best way to visualise this is as a weight on a piece of string of unit length tied to the phone. If you hold the phone flat in portrait mode the the weight hangs straight down, giving X=0, Y=0 and Z=-1. Then as you tip the phone up to make it into a tombstone (as it were) the weight moves so that it is hanging directly below the phone, giving a Y of -1 and a Z of 0 and so on.

Apparently these values will be the same irrespective of how the program sets the orientation of the phone, i.e. they are set to give values as if you were using the phone in portrait mode. If you want to use different orientations you will have to transform these values.

I’ve found the readings to be quite accurate, at least as good as my real spirit level.

Windows Phone taskhost.exe error

(Thanks to Diego H for his solution to this one. He posted the solution on the Windows Phone Jump Start forum and I’ve found it very useful.)

image

When I’m writing Windows Phone programs I’ve noticed that I sometimes get the above error when I try to deploy a Windows Phone 7 project to the emulator. This is usually after I have moved or copied the Visual Studio solution to another directory. 

If I don’t get this error I might notice an even stranger manifestation, where changes I’ve made to the program don’t seem to be reflected in the running code. It turns out that this is due to a build setting getting corrupted. To fix it you must go to the Build menu and select Configuration Manager. Then re-select Windows Phone as the Active solution platform, so that the dialog looks as shown below:

image

Then your programs will deploy and run OK. I’ve no idea why this happens, but sometimes this gets set to “Any Platform” with no build or deploy options set, which stops programs from being built or deployed.

Quick Number Formatting in C#

IMG_2184

I’ve been playing with the Windows Phone accelerometer, and displaying results. Thing is, it gives me values which have lots of decimal places that I don’t really want. They make the numbers flicker in a way that hurts my head. What I want is a way to just display them to two decimal places.

I must admit that previously I’ve resorted to very dodgy behaviour at this point, such as multiplying by 100, converting to an integer and then dividing by 100 again. Must be my old assembler ways coming back to haunt me. Turns out that there is a much easier way of doing this in C# which is to use the string formatter:

message = "Accelerometer" +
    "\nX: " + string.Format( "{0:0.00}",accelState.X) +
    "\nY: " + string.Format( "{0:0.00}", accelState.Y) +
    "\nZ: " + string.Format( "{0:0.00}", accelState.Z) ;

This little block of magic gets the X, Y and Z values out of a vector and then displays them to two decimal places in a string I can display in my XNA program.

The key is the {0:0.00} bit in the format, which gives a pattern for the display of the first (and only) value to be converted. This pattern says a single leading digit and two decimal places.

If you want to do interesting things like put commas into numbers (so that you can print 1,234,567 type values) then you can do that too. You can find out more about how the format strings work in my C# Yellow book (subtle plug) starting on page 50.

Windows Phone Jump Start Ends

making your mind up
We used seat colours to get answers from delegates. Purple for true, yellow for false. Here is the audience making its mind up.

Final day of the course today. Great turnout, great interaction and some really good questions.

Rob Miles with the Jetliner

“Win your own private jet” – more pictures from pinksugarface here.

At the end we gave away the big prize along with two smaller, passenger ones. Thanks to everyone who turned up, I hope you enjoyed it, Andy and I certainly did.

the audience
Audience pictures are not the same though…..

Then it was out for a meal to celebrate.

Jump Start Crew

This course was brought to you by (left to right) Sharon, Jeff, Bob, Andy, Rob and Elese. Thanks to Ben for taking the picture.

Remember, you can keep track of the course and find links to the videos and other cool stuff at:

http://borntolearn.mslearn.net/wp7/default.aspx

Windows Phone 7 Jump Start

You're on camera!

Nerves of steel in the studio.. Thanks to pinksugarface for the picture.

Andy and I did our first day of Windows Phone 7 training today. Fantastic fun with an incredible turnout.  We did these silly quizzes where delegates had to answer true/false questions by changing their seat colours and it was amazing to see all the flags switching over to the right answer before our eyes. Folks, you were great.

I gave out the phone number of my Windows Phone 7 device and asked for some jokes via SMS  (my “emergency” supply of humour ran out around 45 minutes in….). Got loads of texts in response, I’ve not got time to type them all in, but here is a choice selection:

  • What did the blind man say when handed a cheese grater? “That’s the most violent book I’ve ever read”
  • Where do you find a no-legged dog? Right where you left him.
  • On which side does a tiger have the most stripes? The outside.
  • Why do the French only have one egg for breakfast? Because one egg is an oeuf”
  • A man is smoking a cigarette and blowing smoke rings in the air. His girlfriend becomes irritated with the smoke and says “Can’t you see the warning label on the box? Smoking is hazardous to your health.” The man replies “I’m a programmer, we don’t worry about warnings, we only worry about errors”.

Great stuff. Normally I have to buy a whole bunch of Christmas crackers to get material of this quality.

Tomorrow (Wednesday) we are open “office hours” (1:00pm to 4:00 PST) on the course web site. If you are having a play with Windows Phone 7 drop by and say hello.

http://borntolearn.mslearn.net/wp7/default.aspx

And remember, you can still sign up for the Thursday sessions here:

July 22 – 8am (PST): Session Three:  Advanced Windows Phone Development

July 22 – 1pm (PST): Session Four:  Selling Your Windows Phone Solutions & Wrap Up

Windows Phone 7 Jump Start Studio Prep

WP7 Course Presenter View

Bob sets up the webcam while we sort out the introductions.

Today we went over to the room where we are doing our mammoth Windows Phone 7 Jump Start. It starts Tuesday morning and you can sign up here if you like. I was expecting a room with a desk and a webcam. They were there alright, in a studio with two proper cameras, a backdrop and all the trappings of a professional broadcast.

Oh gosh.

WP7 Course Camera View

Andy settling in.

We did some dry runs where we found out a couple of things:

  1. Both of us speaking at the same time– bad.
  2. Neither of us speaking at all – bad.

However, I think we should be OK on the day.

Got Phone

Windows 7 Phone

Mine

Got my Windows 7 phone working today (I’m calling it mine in case anyone tries to take it away). Works a treat. Once I got it to talk to the hotel WiFi it started to show just how nice Windows Phone 7 actually is. I really like it, but this week my focus is on writing programs, not phone user interface design.

So it was on with the fun and games getting my programs deployed to the device from Visual Studio. Which I had not done before. For this I had to lean on the expertise of fellow MVPs who came to my assistance with advice and software in equal measure.

Thanks to Ginny, Joel and Nick for sterling support which paid off in the end. It really was nice to see my program running on a device, and I love the feeling that I can get any of my silly ideas deployed to a real phone (and maybe even sell them)

Then we went out for a walk and I bought a Pay as You Go sim for my phone.  I’ll let you all know the number later, so you can ring me and talk to a real Windows Phone if you want.

Hello Seattle (again)

Mountain View

Nice view from the plane

The lady at US Immigration looked at the stamps in my passport and said “You come here a lot, don’t you”. I suppose I do, wouldn’t have it any other way.

Anyhoo, we had a very smooth couple of flights thanks to Continental airlines (although the airline food version of a cheeseburger is something I only want to experience once in my life) and finally arrived in Bellevue in time for a walk around. During which I broke my shoes in half. Fortunately they had a huge mall just around the corner which had loads of shoe shops and so I was able to get something I’ve always wanted, a pair of Converse All Stars. Excellent.

Downtown Seattle

Downtown Bellevue looking good.

Then Sharon arrived at the hotel with a Windows Phone each for Andy and me. Truly, the day could have got any perfecter.

Windows Phone 7 Training Mayhem

Meerkat

Who? Me?

I got an email a couple of weeks ago asking if I would like to do some Windows Phone 7 training. Thinking that this might be a useful stepping stone to getting my hands on a device, and it might be fun to do I said why not? Actually, it was a bit more complicated than that

I fly out to Seattle on Saturday. I started off thinking that I would be doing this using Live Meeting in a little room in our house, it turns out that I will be using Live Meeting out of a studio in Bellevue, Washington State, USA. 

At the moment I’m working on the content. We have 12 hours to fill…

Windows Phone 7 Jump Start

Windows Phone Jump Start

As announced earlier today in The Guardian among other places Microsoft is running a Windows Phone 7 Jump Start course next week to get developers started writing applications and games for Windows Phone 7. Andy and I are doing it, live from Bellevue Seattle on Tuesday and Thursday.  Using the magic of Live Meeting anyone can take part and it is free to sign up.

Should be fun.

Free Windows Phone for Imagine Cup Students

Poland Imagine Cup 2010 Judging Amazing Phone

We found this phone in our dressing room at the Warsaw Opera house. The design and style are fantastic. But I think on balance I’d rather have a Windows Phone.

One statement by Jon Perera on Thursday got the biggest cheer of the night. All the students who attended the competition, in all the teams, are getting free Windows Phone 7 developer devices as soon as they become available. Bearing in mind he had just given two real devices to the winners of the Imagine Cup Windows Phone RockStar competition I reckon this will be quite soon. Must find out how I can get hold of a device myself….