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 44 45 46 47 48 49
   |  
int main ( int argc, char** argv )
{
    int i,ii,iii,iiii;
    int nbOfRow = 4; // Number of Rows (will be dynamic value)
    int nbOfCol = 6; // Number of Cols (will be dynamic value)
 
    // Case structure
    typedef struct Sokoban_Stage_Case Sokoban_Stage_Case;
    struct Sokoban_Stage_Case {
        int x;
        int y;
    };
 
 
    // Stage structure
    typedef struct Sokoban_Stage Sokoban_Stage;
    struct Sokoban_Stage {
        int nbOfCase;
        int nbOfRow;
        int nbOfCol;
        Sokoban_Stage_Case* cases;
    };
 
    // New stage
    Sokoban_Stage Stage;
    Stage.nbOfRow  = nbOfRow;
    Stage.nbOfCol  = nbOfCol;
    Stage.nbOfCase = (nbOfRow * nbOfCol);
    Stage.cases    = (Sokoban_Stage_Case*) malloc(sizeof(Sokoban_Stage_Case) * Stage.nbOfCase);
 
    // Fill coord to all stage.cases
    iii=0;
    for (i=0;i<Stage.nbOfRow;i++) {
        for (ii=0;ii<Stage.nbOfCol;ii++) {
            printf("(%d,",i);
            printf("%d)\n",ii);
 
            (Stage.cases + iii)->x = i;
            (Stage.cases + iii)->y = ii;
 
            printf("  (%d,",*(Stage.cases + iii)); // Get the X cool
            printf("%d)\n",*(Stage.cases + iii+1)); // how i target the y?
            iii++;
        }
    }
 
    return 0;
} | 
Partager