The Code Works FYI
I do not get this code at all. Could someone help me understand it in and out please. Please keep in mind I understand what an int is. I know what parameters are. I know what Booleans are. I know what addObject means. I just need to know more about the Arrays. I never really understood it in class.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import greenfoot.*; public class Tiles extends World{ private Tile[] tiles; private int TRACKER; public Tiles(){ this ( 4 ); } public Tiles( int SIZE){ super ((SIZE+ 2 )* 50 , (SIZE+ 2 )* 50 , 1 ); TRACKER = 0 ; tiles = new Tile[(SIZE+ 2 )*(SIZE+ 2 )]; setUp(SIZE); } private void setUp( int SIZE){ for ( int t = 0 ; t < tiles.length; t++){ if (t < SIZE + 2 || t > tiles.length - (SIZE + 2 )) tiles[t] = new Tile( true ); //true means the tile is flipped up else { if (TRACKER == SIZE + 1 || TRACKER == 0 ) tiles[t] = new Tile( true ); else tiles[t] = new Tile( false ); TRACKER++; if (TRACKER == SIZE + 2 ) TRACKER = 0 ; } } int x = 25 , y = 25 , TRACKER = 0 ; for ( int m = 0 ; m < tiles.length; m++){ if (TRACKER == SIZE + 2 ){ x = 25 ; y += 50 ; TRACKER = 0 ; } addObject(tiles[m],x,y); x += 50 ; TRACKER = TRACKER + 1 ; } } } |