Lionel Clarke

Software Engineer - Red Gate Software

A Sql Game

Published Friday, December 30, 2005 5:23 PM

There seems to be computer game written in almost every language out there but I haven’t yet found one written in Transact SQL. I thought that poor old DBAs should have some form of game to play so I have written a little 3D maze game in Transact SQL. Since there is no obvious way of interacting with the game it is designed to be used from within Query Analyzer.

You can download the SQL from the following address:
http://www.red-gate.com/downloads/CreateTheMazeGame.txt

Instructions on how to play:

First run:
EXEC spNewGame

This creates a new game. You can then move around the maze using
EXEC spFowards  -- Move you forwards
EXEC spBackwards -- Move you backwards
EXEC spLeft  -- Rotates you Left
EXEC spRight -- Rotates you Right 

All of these stored procedures return a single column results set that shows the view from you current position in the maze rendered in text. It works best if you have Query Analyser in view results in text mode and make sure your results are displayed in a fixed with font! Unfortunately since the maze is all drawn in text it takes a little bit of time to work out what is going on. When you run spNewGame for the first time you will find yourself looking down a corridor with much the same view you got in the old 3D games like Wolfenstein 3D. So what you are seeing is a corridor stretching out in front of you and there is a wall at the end.  You should also note that there is a slight ‘Fish Eye’ Effect as well so if the walls will look a little curved when you look at them straight on (The reason for this is that I am using a rather large Field of View which make it easy to see what is going on).  The goal of the game is to find the exit. You can tell where the exit is as the wall texture changes to the letter ‘E’ rather than ‘-‘ or ‘|’. When you reach the exit you will be given a little message to tell you that you have finished the maze.

It is very easy to add levels. The levels themselves are just an Varchar strings. If you look at the example below The letter ‘S’ is where you start, ‘E’ is where you end, ‘1’ is a normal wall, ‘2’ is the ‘E’ wall texture use to show where the exit is an 0 is open space. You will also need to specify the width and height of your map.  The example below adds a new maze with the name ‘Long’ 

INSERT INTO Levels (LevelName, Maze, MazeWidth, MazeHeight)
            SELECT 'Long',
                        '1111111222' +
                        '1S100012E2' +
                        '1010101101' +
                        '1010101101' +
                        '1010101101' +
                        '1010101101' +
                        '1010101101' +
                        '1010101101' +
                        '1000100001' +
                        '1111111111',
                        10, 10 

Will add a new level called long. To try this level run:
EXEC spNewGame 'Long' 

I hope you have fun with this very silly piece of code and if you feel the need to make it better or even make the game fun to play please feel free to use the code in anyway you like.  

Lionel

 

 

 

 

 

by Lionel

Comments

 

Bart Read said:

Lionel, you're a genius and no mistake. That's excellent.
January 3, 2006 11:26 AM
 

Mike Labosh said:

Quite excellent. I am actually currently working on translating to T-SQL, a text-based Star Trek video game from long ago.
January 3, 2006 2:31 PM
 

Phil Factor said:

A Tour de Force. Wonderful. It is a shame, though that one never gets to kill anything. As regards sound effects, I actually tried out the possibility using a command-line utility that plays tunes through the keyboard speaker, via XP_CmdShell. The problem is that the sound effects all take place in the server room. There must be a use for this idea, in alerting passing DBAs to a critical error maybe. The funeral march for a disk failure perhaps. Hmm. Maybe not.
January 4, 2006 11:26 AM
 

Terry Grignon said:

Very impressive! Your perspective and sense of it are excellent.
January 13, 2006 2:11 PM
 

Irfan Sayed said:

Great Work ..
June 6, 2006 1:17 PM
 

jcs said:

you should have gotten far more compliments on this.  very clever!
July 3, 2006 11:43 AM
 

Dave said:

WOW...that's really really impressive.  hmmm, now what if we base the mazes on ERD's?  Then we could judge their merit on whether you can get from customers to order details without getting lost.
July 6, 2006 11:53 AM
 

Phil Factor's Phrenetic Phoughts said:

Phil Factor announces the Simple-Talk SQL Prettifier, a tool that enables you to put SQL Code into forums and Blog entries in full colour just like the Query Analyser or SSMS. It converts SQL Code into HTML format.
July 13, 2006 10:15 AM
 

K. Chandos said:

I must agree, sheer genius!  The next step, of course, is a corresponding maze solver written entirely in T-SQL.
September 1, 2006 1:03 PM
 

keith.duaime said:

Another much smaller and easier game that might be interesting to try is Towers of Hanoi
November 27, 2007 12:18 PM
You need to sign in to comment on this blog


















<December 2005>
SuMoTuWeThFrSa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Finding Stuff in SQL Server Database DDL
 You'd have thought that nothing would be easier than using SQL Server Management Studio (SSMS) for... Read more...

Mission Critical: SQL Server 2008 Performance Tuning Task List
 In which Buck Woody imagines how the US military would have tackled DBA checklists for... Read more...

Simple Query tuning with STATISTICS IO and Execution plans
 A great deal can be gleaned from the use of the STATISTICS IO and the execution plan, when you are... Read more...

Switching rows and columns in SQL
 When they use SQL Server, one the commoner questions that Ms Access programmers ask is 'Where's the... Read more...

Writing Efficient SQL: Set-Based Speed Phreakery
 Phil Factor's SQL Speed Phreak challenge is an event where coders battle to produce the fastest code to... Read more...