Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Wednesday, August 27, 2008

One down! 200,000 to go!

Since my wife has already blogged about our great adventure into the great unknown, I decided to blog about a problem I finally solved with my monopoly game. (Note, I only solved one of my many many problems I will have to solve.)

I was assigned to write a monopoly program and use a SQL database in the solution. Well, the important thing of this assignment was to not have a working game, but to write all of the documentation and to have a good amount of work be put into the game. Well one of the problems I ran into was deleting players from the game at the conclusion of a game. I would have to go in and manually delete them after each game. This was not a viable option if I ever wanted to produce this game. But after many many MANY hours I finnaly figured it out.

Now, just some background information, I have an SQL database called PlayerData where I store all the player's data in the game. The primary key in the database is TurnNum. Each player is assigned a TurnNum of their turn in the game. This may cause a problem in the game later. If player 1 goes bankrupt, then he should leave the game. I'll have to decide later on what I'll do then, either delete player 1 and reassign the player numbers or automatically skip players who have gone bankrupt. But anyways, I finally figured out how to delete the players from the PlayerData database. SqlDataSource1 connects to the PlayerData database.

SqlDataSource1.DeleteCommand = "DELETE FROM [PlayerData] WHERE [TurnNum]='1'";
SqlDataSource1.Delete();

So, what it does is change the SQL delete command from "DELETE FROM [PlayerData] WHERE [TurnNum]=@TurnNum" and assigns it to delete player one in the game.

This whole thing was rather frustrating to figure out, but that is the headache of computer programming. I thought I could just use the SqlDataSource1.Dispose() function, but the failed to do anything.

Oh, and just to close this blog, I would like to make sure you all know that I am NOT a nerd!