Monday, March 7, 2011

[Revit] Tic Tac Toe for Revit with online play

This is a ‘for fun’ project that I have been working on this week. It started out as something interesting to code while I was up late due to having too many coffees, but then I decided to add a few more features to it throughout the week.

The game is a version of Tic Tac Toe (naughts and crosses) using rooms in Revit as the squares.

image

The game can be played either locally, or online via sever connection.

image

The local game is intended to be played by two people sitting at the same computer, swapping the mouse between each other in between turns. When the game starts, the user must click inside the room that they wish to place their X or O in:

image

Then it is the other players turn, and so on until the game is won, or all rooms are filled. When the game is won, the text notes on the view are updated to add to the score:

image

After getting this working, I decided I could try and take it one step further, by adding online play. To play this the user selects online play when starting the game, and then they must either create or join a new session:

image

Clicking Create New Session will get a new session ID from the server.

image

That session ID must be then passed to the opponent who enters it in the textbox on the same screen. Once both people are ready, click ‘Start Game’.

The game then plays out in a similar way to the local game, but after each turn you’ll see the ‘waiting on other player’ screen:

image

When the other player takes their turn, your view will be updated with their input.

image

This continues until the game is won or board is filled.


To install the game, download it from HERE and unzip the files to C:\RevitTicTacToe\. Then move the TicTacToe-Manifest.addin file to your Revit Addins directory, which will be one of the following:

Vista/7 Users:
C:\ProgramData\Autodesk\Revit\Addins\2011

XP Users:
C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2011\

image

image

Then simply open GameBoard.rvt from C:\RevitTicTacToe\ and run the the addin from Add-Ins tab, External Tools menu:

image


While this is a bit of a silly project, it was a bit of fun, and I got to use a few cool techniques which will form the base of some blog posts to come, including manual transactions in Revit, RESTful web services in ASP.NET MVC, interacting with rooms via the API, making web requests from Revit and more.

When showing an early version of this game to some Revit users it was mentioned that they believed some of this functionality could be implemented in a Revit family, I mentioned to Jason Grant on Twitter that I’d love to see if any expert Revit Family makers can rise to the challenge and give a working version of Tic Tac Toe in a family!

Feel free to give the game a go, let me know if you find any bugs in it. If you want to take a look at the source code, it’s available on GitHub. You can download it all using the Git verison control system, or you can click on files online to view them in browser.

1 comment:

Joe said...

Very nice - quite possibly the most unique addin out there.