Chess Board buttons
jcerecke
Posts: 40
Hey,
Been programming some games lately to try and get the brain working again. Come across a problem that I'm having trouble with. Not urgent in any way at all, but your help would be appreciated
I've got a chess board on my TP, when a user pressed a square on the board I want to take the GET_LAST of this press, turn them into x & y coordinates and use them to do things in the squares in the horizontal row, vertical row and diagonal row (queens move possibilities). At the moment my buttons are in a 2D array, but I can't use that in a devchan.
The only way I can think of is to have the button array as single dimensional, and based on the GET_LAST of that array, it looks at an array which is 2D ([56][2]) with every coordinate in it. Which just seems lame.
Ideas?
Been programming some games lately to try and get the brain working again. Come across a problem that I'm having trouble with. Not urgent in any way at all, but your help would be appreciated
I've got a chess board on my TP, when a user pressed a square on the board I want to take the GET_LAST of this press, turn them into x & y coordinates and use them to do things in the squares in the horizontal row, vertical row and diagonal row (queens move possibilities). At the moment my buttons are in a 2D array, but I can't use that in a devchan.
The only way I can think of is to have the button array as single dimensional, and based on the GET_LAST of that array, it looks at an array which is 2D ([56][2]) with every coordinate in it. Which just seems lame.
Ideas?
0
Comments
Why can't you use a 2D devchan array?
Hope that helps.
Alternatively, if the channels must be sequential (a1 = 1, b1 = 2, ..., h1 = 8, a2 = 9, etc.) you can use arithmetic as follows:
nRank = ((BUTTON.INPUT.CHANNEL - 1) / 8) + 1;
nFile = ((BUTTON.INPUT.CHANNEL - 1) % 8) + 1;
One way to approach it might be to set up a dedicated port for your board then assign each button a channel that matches in nicely with array location of the board representation (0x88 might play nicely on the NetLinx box's). The button.input.channel of your data event will then have the array key you need for move calculation.
If you're not wanting to do any movement animations you could also get funky and set all your buttons up as multi-state where the images assigned to each state line up with your piece value constants.
Sounds like an awesome little project, keen to see how it turns out.
They pretty much do with the ME260, but it's a hell of a lot cheaper with a NI700/900. Hell, I picked up a NI900 for my car on ebay for $120.
Kevin D.