Tuesday, April 12, 2011

Factor Friends v0.1

After a couple of days of solid game playing, I feel back to normal. The last couple of weeks have been so crazy marking and preparing for classes that I've hardly played a thing (I guess I should get back into GameLogs too).

I woke up this morning with a hankering to code. Might have been some of the TopCoder vids I found on youTube, or just something in my mind wanting to relax in a different way. Anyways, I've found myself happily coding away for the past 3 hours (with a splash of Grepolis).

One of the students at school is working on developing Factor Friends for the iPhone (or Mac at least), but I thought I'd give it a go too using some stock VB stuff. The aim would be how much of the game I can get done in a day.

Well, so far so good. I have the basic game board laid out using buttons and another set of buttons for the player's hand. The pic to the left shows some test data overlaid onto the buttons (showing the coordinate system used for the underlying array) as well as a sample starting hand.

There are 6 arrays so far that store the data for the game: BoardValue, BoardValueOwner, HandValue and HandStatus for each player. With these in place and the refresh subroutines built, I can now simply call RefreshBoard or RefreshHand to display whatever the game logic dictates.

Biggest hurdle so far has been attempting to use pointers. I wanted to store a similar sized array of pointers to the buttons so that I could refactor the refresh code into a simple loop rather than having many repeated lines of code for each array position matching up to the correct button. Wasn't a big deal at the start, but once there started to be 7 or so lines per button, the code looked pretty unmaintainable. Searched around for a bit, but nothing seemed to allow me to reference the buttons using a stored pointer or the like. I eventually came up with a new subroutine that accepts a button, and the current staus and value to set it to. Worked a treat and much neater.

With the board in place, the next thing to do is to get the player interaction working.

Looks like I can bind multiple buttons actions to the dame subroutine, and I can also reference the sender to the event handler as the button clicked. That will make the hand and board UI pretty easy.

I'm also hoping to have the clicked card eventually track to the clicked board position (if legitimate, need to get a validation routine working too), then disappear from the player's "hand". Should be pretty easy using a timer and some slide-in, slide-out animations. Not sure what happens to the button when it's in transition though, can I lock the whole UI down until the animation is finished?