arrays in a class
in
Programming Questions
•
2 years ago
I'm stuck with a simple matter. I want to make an array of booleans to check each pixel for being take. Like a board class.
I want to pass the size of the board in the constructor. So once i don't know the size off the array before making the object how do i declare the class variable? Following is the proto code not compiling cause the array is size 0 as that's
total value at the time i create the array. But if i declare the array after
total has been calculated it will be local so i can't access it trough the rest of class code... I' sure that's easy one, but i'm stuck here...
thanks
- Tabuleiro t = new Tabuleiro(100,100);
- void setup() {
- size(100,100);
- t.setUp();
- }
- void draw() {
- t.show();
- }
- class Tabuleiro {
- int size_x,size_y,total;
- boolean free[]=new boolean [total];
- Tabuleiro(int _size_x, int _size_y) {
- size_x=_size_x;
- size_y=_size_y;
- total = size_x*size_y;
- }
- void setUp() {
- for(int i=0; i<total-1; i++) {
- free[i]=true;
- }
- }
- void show() {
- for(int i=0; i<total-1; i++) {
- println(free[i]);
- }
- }
- }
1