1
Reply

Effective Arrays

Mike

Mike

Nov 14 2005 8:10 AM
1.8k

Ok, a friend and myself are making our own RPG from scratch using C# as our language, so I thought that maybe someone here could help out. What im trying to do is build 2 layers, 1 is for the movement layer (0's for able to move into the next square, 1's for unpassable etc) and one to set the coordinates for where characters are. Anyone whos played Shining Force or Vandal Hearts should know what were trying to do :)

Anyway, at the moment ive got the array as an object type, and I just fill it and display it when a menu button is clicked. At the moment this is a private array, not exactly what I want because the characters have to move inside of this array...this is the code so far:

private void mnuGameAddPlayers_Click(object sender, System.EventArgs e)
  {
   //Create charecter profiles
   //Clear Label
   lblCharacterInfo.Text = "";
   CreateCharacters();
   //declare the 10 by 10 array of charecters for each player
   object[,] UnitLayer = {{Unit[1].Name,"0","0","0","0","0","0","0","0",Unit[3].Name},
         {"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"},
         {"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"},
         {Unit[2].Name,"0","0","0","0","0","0","0","0",Unit[0].Name}};

   //loop to display the grid layer
   for (int r=0;r<10;r++)
   {
    
    string line = "";
    for (int c= 0 ;c<10;c++)
    {
     line += UnitLayer[r,c];
     if (c <9)
      line += ",";
    }
    lblCharacterInfo.Text += line + "\n";
   }
  }

Now ive tried this and it hasnt worked...what am I doing wrong?

public object[,] UnitLayer = new object[11,11]; //Declared up top with global/designer variables

UnitLayer = {{Unit[1].Name,"0","0","0","0","0","0","0","0",Unit[3].Name},
            {"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"},
            {"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"},
            {Unit[2].Name,"0","0","0","0","0","0","0","0",Unit[0].Name}};


Answers (1)