-2

I need to translate this from Java to ObjC, problem is I'm not sure exactly what the code in Java is doing (to be specific the portion from int num to the closing } on the if statement below it). I'm not looking for a direct translation, but more of an explanation and maybe a pointer in the right direction.

-Java portion

 //make array and display match
 for(int row = 0; row < NUM_ROWS; row ++)
 {
     for(int col = 0; col < NUM_COLUMNS; col ++)
     {
         int num = grid[row][col];
         if(grid[row][col] == 1)
         {
             g.setColor(new Color(100,0,255));
             g.fillRect(col * CELL_WIDTH, row * CELL_WIDTH + Y_OFF_SET, CELL_WIDTH, CELL_WIDTH);
         }
     }
 }

-What I have so far

NSMutableArray* (name) = [[NSMutableArray alloc] init];
for(int row = 0; row < NUM_ROWS; row++)
{
    NSMutableArray* (name) = [[NSMutableArray alloc] init];
    for(int col = 0; col < NUM_COLUMNS; col++)
    {
        Unsure for here
    }
}
Dennis Meng
  • 5,109
  • 14
  • 33
  • 36

1 Answers1

0

g is (almost for sure) object of class java.awt.Graphics

See descriptions for setcolor() and fillRect() methods

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
  • Ok, so the if statement is saying "if the location at [row][col] == 1 color the rectangle". Im not connecting how `int num = grid[row][col];` factors into that though. Sorry if this should be obvious, I'm still new to programming. – user3141166 Dec 28 '13 at 05:08
  • I guess `grid` (2-dimensional array) is the logical representation of the graphical grid. What are they doing? Something like game-board? – PM 77-1 Dec 28 '13 at 05:13
  • That's correct, making the game of life. They give me the source code for it in Java and its my job to recreate the game in ObjC. https://s3.amazonaws.com/mgwu/tutorial/TheGameOfLife.java the grid is originally filled with 0s from my understanding and when a point on the grid is touched it then becomes a 1 but needs three 1s around it in order to survive to the next generation – user3141166 Dec 28 '13 at 05:17
  • `static char[][] grid;` grid is an [array](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) of primitive type [`char`](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html). – PM 77-1 Dec 28 '13 at 05:24
  • In this Java implementation the grid array is filled with characters (not numbers): `*` (asterisk) and `_` (underscore). – PM 77-1 Dec 28 '13 at 05:26