Chess board-like
by Nathan Huffman · in Torque Game Builder · 02/02/2007 (12:59 am) · 6 replies
Hey,
I've been messing with Torque quite a bit and I'm rather new to programming. Well, I can write a lot of things but I'm not well versed enough to answer a question such as this:
Say I wanted to code a chess-like board. A grid, but each square could contain different data, like what color it is, etc...
How would I start to do this in code?
Just looking for advice. I'm sure theres a few ways to pull it off, but seeing what you guys have to say.
thanks in advance ;)
I've been messing with Torque quite a bit and I'm rather new to programming. Well, I can write a lot of things but I'm not well versed enough to answer a question such as this:
Say I wanted to code a chess-like board. A grid, but each square could contain different data, like what color it is, etc...
How would I start to do this in code?
Just looking for advice. I'm sure theres a few ways to pull it off, but seeing what you guys have to say.
thanks in advance ;)
#2
02/02/2007 (3:33 am)
Tilemap or a well-controlled two-deminsion array, any other ideas?
#3
02/02/2007 (7:06 pm)
In the CheckersDemo I use a Tile Map for placing of the pieces (and as a logical + interactive board). In the end I stored no data on it since I simply used either an array or two-dimensional array for that. For Chess I'd say a Tile Map would be perfect (even if invisible if you have a board image).
#4
This isn't exactly my idea, but for saving typing a lot, think Chess, with walls. Each square could contain a wall between the two, preventing certain moves. So I'd think I'd need a "square"/"tile" to represent the wall (if there is one there).
If I used a tilemap and displayed it, theres no way to make thin or invisible "every other tile" for walls. I guess I could use it as just an invisible object... then move on another imagemap/tilemap....
Plus each square could contain data such as what peice is in it, what color it is, and 4 or 5 different peices of data.
Right now being new to programming, I thought of using like
$gameBoardArray[10,10]
then say square 2,2 has a knight, is black, is on fire and has 10 coins in it
i'm not sure how i'd save all that different data to the variable
$gameBoardArray[2,2] = ?
because things like $gameBoardArray[2,2].coins or .bIsOnFire
doesn't seem to be legit syntax or possible
so could you guys throw me some advice on how I'd basicaly setup a tilemap or 2d array to contain lots of data for each bucket, or how that is typically done?
I suppose I could always use just a long string and parse it for data but that seems ... hacky?
thanks in advance
02/02/2007 (9:59 pm)
A tilemap seems like a good resource; let me explain what I'm trying to do and perhaps you can swing me some advice.This isn't exactly my idea, but for saving typing a lot, think Chess, with walls. Each square could contain a wall between the two, preventing certain moves. So I'd think I'd need a "square"/"tile" to represent the wall (if there is one there).
If I used a tilemap and displayed it, theres no way to make thin or invisible "every other tile" for walls. I guess I could use it as just an invisible object... then move on another imagemap/tilemap....
Plus each square could contain data such as what peice is in it, what color it is, and 4 or 5 different peices of data.
Right now being new to programming, I thought of using like
$gameBoardArray[10,10]
then say square 2,2 has a knight, is black, is on fire and has 10 coins in it
i'm not sure how i'd save all that different data to the variable
$gameBoardArray[2,2] = ?
because things like $gameBoardArray[2,2].coins or .bIsOnFire
doesn't seem to be legit syntax or possible
so could you guys throw me some advice on how I'd basicaly setup a tilemap or 2d array to contain lots of data for each bucket, or how that is typically done?
I suppose I could always use just a long string and parse it for data but that seems ... hacky?
thanks in advance
#5
$GameBoardArray[2, 2, Piece] = "Knight";
$GameBoardArray[2, 2, Colour] = "Black";
$GameBoardArray[2, 2, Coins] = 10;
I don't see why
$gameBoardArray[2,2].coins = 10;
wouldn't work? It does look a little strange but it's perfectly legitimate. You have an array item, at position 2, 2, with member variables.
07/09/2007 (6:57 pm)
I know this is an old thread but why not,$GameBoardArray[2, 2, Piece] = "Knight";
$GameBoardArray[2, 2, Colour] = "Black";
$GameBoardArray[2, 2, Coins] = 10;
I don't see why
$gameBoardArray[2,2].coins = 10;
wouldn't work? It does look a little strange but it's perfectly legitimate. You have an array item, at position 2, 2, with member variables.
#6
07/18/2007 (5:33 am)
Or just store everything within the tilemap itself.
Torque Owner Andrew Douglas
-Andrew