Sign on Options
Theme: [Light Selected] To Dark»

My Friends

My Recent Ratings

21Nov 12

After 9 functions, 6 procedures and 3 tables I have finally managed to get a working version of minesweeper in Oracle SQL Developer. At best this is of very limited interest to a tiny handful of people that just happen to use a certain querying language but I am pretty pleased with myself. For reference it's like making a game using Microsoft Access although that would probably look better. Still, it's quite a challenge and now I can play Minesweeper and it looks like I am working!

For those that are interested here's how I did it (for the rest goodbye and thanks for getting this far):

Step 1: I created a table with 11 columns and 10 rows. A procedure (which itself references a further 'randomiser' procedure) then takes in the number of mines as a parameter and distributes them randomly through the first 10 columns as an X. Where there is no mine it adds an a, b,c,d,e,f,g,h, i or j depending on the column and in the last column it just numbers it from 1-10. These last two steps are important as reference data.

Step 2: Now the mines (and reference data) are in place next comes the numbers. For this I needed a second table and another procedure to populate it (the reason I needed a second table was to overcome the mutating table issue that comes when you try and update a table that is currently in use). This new procedure moves down each of the first ten columns of the first table and populates the second table with either the mine (X) or a number which is determined by one of 9 functions (top left, top right, bottom left, bottom right, left, right, top, bottom or centre) that concatenates the content of all the adjacent positions and then counts the number of mines.

Step 3: A third table (the game table) was created that was entirely populated by blank values. A 'guess' procedure was made (where you specify a column and row ie. 'B7') which then looks at the second reference table and populates it's value into this final game table (the main problem is that after each guess I have to re-query the table with a simple select statement but it still works). The final piece of the puzzle is to create a flag procedure that then populates an F into a field that I think is a mine (and then re-query of course).

There you have it. All this took me about a day and a half and although I confess that is was during work time it's still teaching myself valuable skills in PL/SQL that I can apply to my job. Probably. But just in case my manager is not a Minesweeper fan be sure to tell him I was just doing basic technical exercises. On the other hand if he is a fan then tell him that Battleships is only days away!

18 comments
Gen_Warbuff
Gen_Warbuff

I have no idea what you just wrote about, but I'm pretty sure it's some type of classified information.

-INKling-
-INKling-

 @Gen_Warbuff The beauty is that as long as you make the description as dry as possible then nobody understands what you are on about. Next I am intending to claim that I recreated BF3 in MS Paint!

2ndWonder
2ndWonder ranger

this seems to be out of my league although I wouldn't mind learning this someday :P

-INKling-
-INKling-

 @2ndWonder I use it daily for work (PL/SQL not Minesweeper) and it's pretty straighforward. However without real-life practical examples it's difficult to teach yourself this sort of stuff.

GunnyHath
GunnyHath ranger

I may just say you have way way way too much time on your hands :)  But it's still pretty cool, make a YT vid lol.

jellyman68
jellyman68 like.author.displayName 1 Like

That's pointless, very nerdy, and extremely awesome. I'd give it a go myself, but I never want to see SQL again after a year of it for Computer Science.

-INKling-
-INKling-

 @jellyman68 Thanks. I quite enjoy doing SQL but that's probably because I never had to learn it in school/college/uni. It's like those books you read for school that you automatically hate!

WorldOfHurt
WorldOfHurt

insert into game (aMineIsHere) select * from mines where mines.cellContent like 'X';

 

!!! I HAZ HAXORED UR GAME, SUKA !!!

 

:)

-INKling-
-INKling-

 @WorldOfHurt Damn pirates ruining it for everyone. This must be how Activision feels. Violated!

wavey_gravey
wavey_gravey

Nice!  Although I have no idea what you are talking about :P

 

Oh BTW... I came to this blog via "Awesome Users Blogs"  YAY!

angryfodder
angryfodder

Good work dude bro!

 

Using a game as the bases as training isn't such a bad idea.  Although that is what I did when I started learning a programming language....and if its something I did, then maybe its not wise

-INKling-
-INKling-

 @angryfodder Cheers. It's good to have an actual real-life project to work on when you are trying to learn something. I am not sure that Minesweeper is exactly what my employer are thinking but I learned doing it.

biggest_loser
biggest_loser like.author.displayName 1 Like

Why does this sound like more fun than Hitman: Absolution?! :( 

-INKling-
-INKling-

 @biggest_loser It certainly looks a lot more difficult than Hitman: Absolution! Maybe I should build in an X-Ray bonus procedure for all pre-orders.

Conversation powered by Livefyre

My Recent Ratings