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.
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
Load comments