Late one Friday afternoon, while working at my desk, a coworker asked, "Does anyone want a foosball table? My friend's office is getting rid of one, but we have to pick it up now." Even if I didn't like foosball, carrying a table a mile through the streets
of Chicago would have made a great story. I had to get it.

Because we're competitive software developers, we started recording the games in an Excel spreadsheet to track stats. While arguing whether I had lost my last four games or my last five games, I realized there had to be a better way. And so the inspiration
for the .NET foosball tracker was born. In this article, I'm going to cover a few ways to harness the power of Visual Studio 2005, SQL Server 2005, and a free foosball table to create the ultimate break room accessory.

Hacking the Table

The first step in building the foosball scoreboard application was to wire the table to a spare computer via the I-Pac, a PC interface for arcade buttons purchased from
Ultimarc. Using what little carpentry skills were available in our software development consultancy office, we drilled several holes in the table to mount the buttons. The I-Pac translates button presses into
keystrokes. Each player has a button to select his or her account at the beginning of a game (we have a very competitive woman's division) or to signal that he or she scored a goal. Three other buttons were added for game setup and other special features.
We used the KeyUp event, so the Visual Basic .NET scoreboard WinForm application could respond to any of the button presses. It's not the most exciting code, but hey, this is just the beginning of the article.

Designing the Scoreboard

Lucky for us, our break room contains a 30-inch TV with VGA inputs near the foosball table to display the scoreboard application. The scoreboard consists of a form with several picture boxes and labels with transparent backgrounds on a foosball background
image. Each set of player names and icons is a user control that tracks information such number of goals scored. Using the new table adapters in Visual Studio 2005, it's easy to bind the controls to a data table. The following code loads player attributes
such as the player image and sounds from SQL Server.

After cycling through a list of employee accounts in the database using the player's button, it's time to play some foosball. Without budget enough to hire Keith Jackson to provide game commentary full-time, we added our own virtual announcer using the
Microsoft Speech API. To make your application speak, all you need to do is add a reference to SpeechLib.dll and declare a new speech object.

Taunting Your Opponent

When playing office foosball, nothing is more important than a witty taunt to demoralize your opponent. When a player scores a goal, he presses the button in his corner, which fires a goal scored event which then triggers several actions. One action is to
play a random sound clip from the player's personal sound collection retrieved from SQL Server. I'm mostly a C# developer, so the new Visual Basic .NET My Classes was something I wanted to try out. My Classes make it simple to perform dozens of tasks like
playing any .wav file.

Archiving the Results

It's game over and there is an 80 percent chance that I lost in a blowout; time to put that box score in the record books. For those of you keeping score at home, the table adapters make it simple to save the game record to the database.

With all the game stats recorded in SQL Server, we can produce dozens of reports such as win percentage, total goals scored, shutouts, average goals scored per game, average goals allowed per game, and using a formula based loosely on the BCS (U.S. college
football) computer rankings, the top overall player. Sadly, I wrote the application and I still can't get my name into the top 10 players.

These stats are displayed on an arcade-like teaser screen that loads after the application has been idle for a few minutes. The teaser screen cycles through several dozen datasets to provide a different set of stats on the screen.

Conclusion

Visual Basic.NET has dozens of new features that make quickly building an application very easy. In just a few hours I was able to put together an application that has significantly improved the fun of having a foosball table in the office. Unfortunately,
it still can't make me play better. Maybe next version. Speaking of the next version, on my brand new
blog, I'm going to cover some future additions to Visual Foos 2005 like a Web front-end to view game logs and upload sound files. Some other additions I'd like to develop are a RSS feed of games
played, pre-game predictions using SQL Server Analysis Services, player identification through RFID readers, and a foosball speed radar. If anyone has any suggestions, I'd love to hear them! Or if you have a foosball table you don't want.

Remove this comment

Remove this thread

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums, or
Contact Us and let us know.