What is the best way to create a multi variable array?

edited October 2016 in How To...

I want to create a 2D grid of squares that have about 6 different variables associated with each square. I can't figure out the best way to do this. I tried using XML to store all the position data and other data but had trouble with reading and writing the different attributes. What "technique" should I be using for the desired result?

Tagged:

Answers

  • edited October 2016 Answer ✓

    it could help to see your code for us to help

    3D array

    but you could use a 3D array

    int[][][] grid = new int[8][8][6]; 
    

    usage is the same as with 2D - see tutorial

    when you use oop / classes

    when you use oop / classes

    just say

    Cell[][] grid = new Cell[8][8]; 
    

    and in the class

    class Cell {
    
        // value 
        int cellValue=0; 
    
        int[] possibleValues = new int[6]; 
    
        void display() {
              // ......
        }
    
    }
    

    store your 6 different variables in an 1D-array: possibleValues

    Chrisir ;-)

Sign In or Register to comment.