Guide Text Entry in Windows Phone

image
The layout may not be perfect, but it is a lot easier than writing your own text input.

Some of our students are making quite a good job of Evil Squash. There are even a few Windows Phone versions out there, which is nice. One of the things that the game must do is ask the player for their name. Anyone who is using XNA for the game has a problem here, as text entry in XNA can be non-trivial. Unless you use the XNA Guide.

The Guide is a way that you can ask the user questions and do lots of other interesting things. I used it to write a silly program that asks the user for their name.

if (text.Length == 0)
{
    if (!Guide.IsVisible)
    {
        // display the guide

        Guide.BeginShowKeyboardInput(PlayerIndex.One, 
            "Name entry",       // title for the page
            "Enter your name",  // question for user
            "Fred",             // default text
            new AsyncCallback(gotText),  // callback method 
            this);                       // object reference
    }
}

This is the code that I wrote. It is part of the Update method. The variable text is going to hold the name that the user enters. If it is empty I must display the guide to read it. The first thing I do is to check that the guide is not already visible. If it is I don’t need to display it again. Remember that Update is called 30 times a second on the phone, I don’t want to be overwhelmed by loads of guides.

The BeginShowGuide puts the guide on the screen. The first three parameters make very good sense, the last two are a bit more confusing. The fourth parameter gives the Guide the method to call when the user has finished typing in their name and pressed OK to close the Guide down. The fifth parameter just needs to be a reference to an object that can identify the request. I’ve given it the value of this, which is a reference to the current game. The result of this method call is that the guide is displayed, as you can see in the screenshot at the top.

When the user closes the guide, either by pressing ok or cancel, the Guide will call the gotText method that I told it about:

void gotText(IAsyncResult result)
{
    if (result.IsCompleted)
    {
        text = Guide.EndShowKeyboardInput(result);
        if (text == null)
        {
            // user pressed cancel
            text = "Cancelled";
        }
    }
}

This checks to see if the request is completed. If it is the method gets the text from the Guide by calling EndShowKeyboardInput. If the user pressed cancel the Guide will return a null string. The code above sets the text to Cancelled, otherwise the text is left as whatever the user typed in.

My program just draws the name string on the screen:

image

You can find a sample project with this code in it here.

Rampant Robots

DSCF5281

We let the students give their robots names. As well as “Pet Art” above we have two Daves and one Eric.

We had a proper session of robot control today. We were making robots that don’t fall off the desk. We had a few miss-wired connections and people discovered that two motors told to go at full speed don’t actually go at the same speed. So the program can’t just assume that things will happen the way they should….

Next week we are going to see about making the control software multi-threaded so that we can drive the motors and monitor the sensors at the same time. Great fun.

Windows Phone Camp Hull

Hull Phone Camp 1

Ben addresses the audience.

Ben and Joanna from Microsoft came to see us today and deliver a full afternoon of Windows Phone sessions. We had phones, programs, pizza and tea and coffee. But no biscuits. Sorry about that. Anyhooo, a great time was had by all. Thanks to Ben and Joanna (I keep thinking of ice-cream when I type their names like this) for coming all this way and back in a day.

We did some silly development and we spent some time making a really funky windows phone camera. I promised a download of the code, here it is.

Programming Humans with Evil Squash

Main Board Hi Res

I’m gaining a new respect for board game designers. It turns out to be quite difficult to create rules for the games that are unambiguous and easy to understand. Even what I thought was a simple game, Evil Squash, has turned out to have some nasty edge conditions that we have had to think quite hard about.

Of course, a game design is really a “program for humans”. It is a sequence of instructions that involve the processing of data, with decisions and outcomes. The tricky part is that the rules are written in English, which is a language in which it is very hard to make yourself completely clear.

Perhaps as an introduction to programming we could get a bunch of people to design the rules for a game of some kind, and then “debug” it by playing the game. I’m certainly going to invent a new “imaginary” game for each first year programming course from now on, just exploring the rules and getting students to think about how they work has given a nice new dimension to the coursework.

You can find out more about the game itself at www.evilsquash.com.

Building a Robot Army

DSCF5252

Spent some time this morning building robots. Actually I didn’t, students on a hardware interfacing course did all the hard work. They are all Fez Micro Framework powered and great fun. They are based on the same platform as Oscar, who has been all over the place with me over the last couple of years.

Next week we are going to get some C# code into them and get them running around the desks and not falling off the edge. Then we are going to get another Micro Framework board running and see if we can control them via the internet.

Great fun.

Lego Addict

DSCF5243

I think I might have a problem. (actually, I think I might have lots of problems, but I’m not particularly keen to blog about any of those).

Anyhoo, I was taking back some Lego to the toy store because we needed some different prizes for Three Thing Game and I succumbed to the rather nice little truck design. I then spent a happy hour watching Naff Telly (so naff I’ve forgotten the program) and building the vehicle. It is now amongst the other Lego toys collecting dust on a shelf. And Lego keep sending me catalogues, and I keep buying things, and making them.

I wonder if there is an organisation for Lego Addicts. If there is, I hope it is much more than a 12 step program for recovery. I’d hope for at least 150 steps and a nice instruction manual to work through. With pictures.

Filthy Hands

DSCF5207

My hands keep changing colour. They go from a healthy pink to a dingy grey. I was ready to put it down to old age (well, perhaps middle age) the first time I saw it. Then I realised what was happening. My new, nicely trendy, black jeans were dropping some of their colour onto my hands each time put my hands in my pockets.

The other snag with trendy black jeans is that you wash them once and they turn instantly into streaky grey ones. But hopefully they’ll keep my hands cleaner.

Visiting the Iron Duke

DSCF5188

View from the pointy end, which I’m reliably informed is called the “bow”.

We went to see HMS Iron Duke today. This is a warship that has “adopted” the city of Hull and drops by whenever it is passing, although perhaps it is a bit more complicated than that. Anyhoo, we went off to take a look round and grab some pictures. Thanks to the crew for letting a bunch of folks traipse around your decks.

DSCF5181

I love this sign. I just worry that I don’t know what the alarm sounds like…

DSCF5221

The Lord Mayor came to see the ship too. That’s his Jag.

Uncharted 3–Drake’s Deception

image

Bought the third in the Uncharted series of video games today. I must admit I’ve not actually quite finished the second one yet. I got stuck taking on some really nasty crossbow wielding goblin thingies that were very hard to kill. But I was very close to the end.

The third instalment of “Tomb Raider with a bloke” is very much in the same vein as the previous two, but very, very well done. One of the best bits for me is that in this one you usually have a partner with you and they are actually quite useful to have around. Unlike some games, where your comrades stand around getting shot while you solve the puzzle and take out the bad guys, these folks are quite engaged and will even give you problem solving tips if you stagger around dumbly for long enough.

The locations that I’ve been to so far have all been excellent. I feel kind of guilty not taking in the beautifully rendered environments while I’m going for a headshot on the rocket launching zombie on the other side of the valley, but it all looks very nice.

The scenario with its strange maps from the past, underground tombs and “Say, do you think that statue might rotate?” moments is very like the earlier ones, but in a good way.

The stern message at the start says that you should take a break of at least 15 minutes in each hour of gameplay. But this is not a game you can really play in 45 minute chunks. Me, I keep getting dry eyes because I forget to blink during the gameplay.

If you liked the earlier ones you’ll love this. If you’ve always wanted to take part in an Indiana Jones movie, you’ll love it too.

The Best Way to Write Programs

Main Board Hi Res

So, how would you represent the arrows?

The Software Development for the First Year C# Programming course this year is a game I have invented. I’ve called it Evil Squash. It even has its own web site:

www.evilsquash.com

The game is very like Snakes and Ladders, but with a twist that makes it a bit like Ludo as well. At the moment we are working on the player movement, which uses a board like the one above. When a player lands on the tail of an arrow they must then follow it to the destination. We have decided that there are three ways that you can implement this behaviour.

  • A whole bunch of conditions that hard wires the arrows into the program
  • An array with a location for each square that provides a redirection to the destination square.
  • An array of “redirects” that holds the behaviour of the 10 arrows

You might want to consider which is the “best” one. To me, the answer is “you can’t say”. Each of them has advantages and disadvantages. Some of them use less memory, some go quicker. Some are easier to test and some are easier to understand.

One of the things that we try very hard to do in the programming course is to get people to think that often there is no “best” way to solve a problem, merely ones that are better than others against certain criteria. We give extra marks to students who manage to use arrays (I’ve nothing against hard wiring the arrows, but I thing showing you can use an array is something that should be rewarded).

Next week we are going to get the player and the “Evil Squash” behaviour sorted, on the way to making a complete game and maybe even some AI powered opponents.

I’m keeping the domain in case we get some good ones (maybe even phone based) that we might want to distribute.

Don’t Take Your iPad to Meetings

University Trees

I took my iPad to a meeting today. I do love the device to bits (although the battery life seems to have taken a bit of a hit since I upgraded it to the latest operating system) as it is a great way to consume content. Unfortunately I was reminded again of how hard it is to make good use of it to take notes. While some of those around me were confidently tapping text into their netbooks and laptops I was trying to persuade the shift key to do what I wanted and writing “auto-corrected” rubbish. If I had remembered to bring the Bluetooth keyboard to type text in things might have been easier, but as it was I ended up with a few lines of garbled text. Oh well.

Windows Phone Event at Hull University

DSCF5126

Microsoft are coming to Hull on Wednesday the 16th of November for some intensive Windows Phone Development action.  The event will run from 1:15-5:00pm in Lecture Theatre D in the Robert Blackburn Building. It includes an afternoon tea break, and takeaway pizza at the end.

If you want to find out how you can take your C# skills and apply them the phone, sell you applications and maybe even make some money, then you you should come along.

Spaces are limited so register on EventBrite for free here: http://hullwindowsphonecamp.eventbrite.com/

October Three Thing Game Winners

Survivors
These folks are the true survivors.

[Cross posted from www.threethinggame.com/]

Well, we lost a few on the way. The effects of fatigue and the lure of Halloween parties meant that some of our teams didn’t make it to the finish line. However, a good time was had by all and I’ve never seen so much pizza eaten by so many so quickly. The pizza company had to send two cars to deliver all 40. And it all got eaten…

This morning at 7:30 Simon and I went around with a camera and got presentations from all the teams of their games. The videos will be up tomorrow so you can see for yourself how just how good they are. We had some especially impressive solutions from First Year teams who, with only five or so weeks of C# under their belt, produced some highly playable results. Then, at 9:00 sharp the three judges, Warren, Neil and Simon watched the top ten teams and picked the winners. Which was so difficult we had to award two second prizes.

DSCF5104
Judges and videos

DSCF5113
You’d think they’d look pleased with prizes of this quality….

This is the team that won the award for best interpretation of their Three Things.  “Tactical Nuclear Penguins”, made up of Josh Crowther, Alex Beamer and Dan Burns had to make something from “Funky, Robot, goes underground”. And make something they did. An underground exploring robot agent working down through caverns to fight the devil no less. Hooked up with great dance move beat matching action and coming to Windows Phone Marketplace near you soon.

DSCF5106

The first Second Place team, if you see what I mean, “The Double A's”. Anthony Quinn and Aaron Ridge produced a fast moving, pretty much market ready for Windows Phone take on “Extreme Hamster in a Graveyard”. Great work, even if they couldn’t keep their eyes open at the end.

DSCF5108

This is the second, Second Placed, team. “I chose this weekend over Battlefield 3” , aka Lindsay Cox, Devon Hansen, David Hart and Michael Bumby. Their game based on “Gun-toting, Volcano, in Space” combined Bejewelled style action with a sideways blast-em-up which had the player matching threes to arm Space Marines attacking the Volcano.  Lots of guns, and lots of toting.  Great work guys. And don’t worry, we’ll have Lego prizes for all of you once we’ve been down to ToysRUs.

DSCF5110
The Winners, with their prizes.

The Winners were praised by the judges for producing a game for Windows Phone that was good enough to sell right now, with delightful graphics, a well honed mechanic and good adherence to the theme. And you could slice the moon in half. These guys are making a bit of a habit of winning,  having nabbed the prizes in the last competition too. “The Infamous Two Sirs”, Christophe Lionet and Robert Marshall produced a game based on “Tomb, Ninja, Travelodge” that looks excellent and plays great. Well done guys.

The next Three Thing Game will be on the weekend of 17th and 18th March 2012. Start planning now.