ID:154256
 
I'm working on a boardgame right now and nearing completion, but now I face the hardest thing to code in this game. Movement of the game pieces. I've already created a turn base that allows you to click a game piece if its your tune. The game's board is made up of 30 squares. Starting at the top left going right, down 1, left, down 1, and right to the end of the board, that the path all the pieces must follow. Also preceeding this, a random number is generated for movement points. Then the player clicks on a game piece and it moves that many movement points along the board's path. I need to come up with a proc for moving the game pieces along the board. I could code out something for each tile, but I'm hoping there is an easier way. Also I need to add in there a way to check if another game piece is in the tile that it would end up, if other player's then just switch places of game pieces. Any ideas? I hope this doesn't sound too complex.

LJR
LordJR wrote:
I'm working on a boardgame right now and nearing completion, but now I face the hardest thing to code in this game. Movement of the game pieces. I've already created a turn base that allows you to click a game piece if its your tune. The game's board is made up of 30 squares. Starting at the top left going right, down 1, left, down 1, and right to the end of the board, that the path all the pieces must follow. Also preceeding this, a random number is generated for movement points. Then the player clicks on a game piece and it moves that many movement points along the board's path. I need to come up with a proc for moving the game pieces along the board. I could code out something for each tile, but I'm hoping there is an easier way. Also I need to add in there a way to check if another game piece is in the tile that it would end up, if other player's then just switch places of game pieces. Any ideas? I hope this doesn't sound too complex.

Probably the simplest way to implement this would be a list created at world.New(), containing all the squares. If your board is just a square/circular track, you can find a space further along the list like this:
next_space_index = (this_space_index+moves-1)%30+1
next_space = spaces[next_space_index]

Lummox JR