Hey guys.
Not sure if im on the correct forum but anywho...im using c# with XNA to create a 2D board game.
Ive used a tile engine to draw the images of each tile(to make up the entire board) to the screen.
Now im trying to create a 2D array(below) to depicate the actual board
Do I have to initialize the array and go through each tile on the board(with all the 0's)
int[,] myArray = new int[10,5];
int[,] myArray = new int[,] {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, (0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, (0,,0,0,0,0},{0,0,0,0,0}, {0,0,0,0,0}};
PrintArray(myArray);
public class ArrayClass
{
static void PrintArray(int[,] w)
{
// Display the array elements:
for (int i=0; i < 10; i++)
for (int j=0; j < 5; j++)
//is the below line correct?
Console.WriteLine("Element({0},{1})={2}", i, j, w[i,j]);
}
public static void Main()
{
// Pass the array as a parameter:
PrintArray(new int[,] {{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, (0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, (0,,0,0,0,0},{0,0,0,0,0}, {0,0,0,0,0}};
}
}
P.S how do i post code properly on this site?
Thanks in advance for any replies.
John
VulpesPosted Feb 21, 2012, 5:47 PM
I always post code as plain text. As long as it's suitably indented, it's easy enough to read :)
VulpesPosted Feb 22, 2012, 6:01 AM
As far as the articles are concerned if you have a question, then you need to ask this in the comments to the article.
Hopefully, the author will see it and reply but if not you could try sending him/her a message directly via the site.
john Mc kennaPosted Feb 21, 2012, 7:50 PM
and i can only see places to post an article and other stuff but no place to ask a question...im probably just blind lol?.
I was going to ask though...i was thinking of creating a list
VulpesPosted Feb 21, 2012, 6:29 PM
john Mc kennaPosted Feb 21, 2012, 6:16 PM
I see the print array method goes through the array and writes the line but what does the piece of code ("Element({0},{1})={2}", i, j, w[i,j]); at the end of the print array method do?
Yeah i want to set all the elements of the int array to 0 at the beginning (as the board will have no letters placed on it yet)
As I said im trying to write a 2d board game using XNA. would you be able to offer any advice on what to do next.
Each image of the seperate tiles are displayed on screen using a tile engine to make up the physical appearance of a board.
10001
01010
00100
01010
10001
At the minute the user can drag and drop letters onto the board.(but its display purposes at the minute) How can I map the array(you have just shown me) to the board.
So when a user drops a letter on a tile it will store the 'letter' in the array?
thanks again