建立康威的iPad生活游戏

时间:2014-01-23 14:02:42

标签: ipad class conways-game-of-life

我正在尝试在Xcode(用于iPad)中构建康威的生活游戏,但我似乎无法弄清楚如何使其合理的尺寸。因为它现在是10 * 10并且花了很长时间才能拼凑起来。我甚至认为这不对。

- (void) drawRect: (CGRect) rect {
if (first == false) {
     first = true;
    for (int x = 0; x < 10; ++x) {
        for (int y = 0; y < 10; ++y) {
            ask[x][y] = false;

        }
    }
   // ask[7][7] = true;
    ask[3][9] = true;
    ask[3][8] = true;
    ask[4][9] = true;
    ask[3][7] = true;
    ask[5][2] = true;
    ask[1][4] = true;
    ask[2][3] = true;
    ask[1][3] = true;
    ask[4][2] = true;
}



for (int x = 0; x < 10; ++x) {
    for (int y = 0; y < 10; ++y) {
        counter1 = 0;
        if((ask[x][y]) == true){

            if(ask[x][y+1] == true){
                counter1+= 1;
            }
            if(ask[x][y-1] == true){
                    counter1+= 1;
            }
            if(ask[x-1][y-1] == true){
                    counter1+= 1;
            }
            if(ask[x-1][y+1] == true){
                counter1+= 1;
            }
            if ((ask[x-1][y] = true)){
                counter1+= 1;
            }
            if(ask[x+1][y+1] == true){
                counter1+= 1;
            }
            if(ask[x+1][y] == true){
                counter1+= 1;
            }
            if(ask[x+1][y-1] == true) {
                counter1+= 1;
            }

            if (counter1 < 2){
                ask[x][y] = false;
            }else if (counter1 > 3){
                ask[x][y] = false;
            }
        }else if (ask[x][y] == false){

            if(ask[x][y-1] == true){
                counter1+= 1;
            }
            if(ask[x][y+1] == true){
                counter1+= 1;
            }
             if ((ask[x-1][y] = true)){
                counter1+= 1;
            }
            if(ask[x-1][y-1] == true){
                counter1+= 1;
            }
            if(ask[x-1][y+1] == true){
                counter1+= 1;
            }
            if(ask[x+1][y+1] == true){
                counter1+= 1;
            }
            if(ask[x+1][y] == true){
                counter1+= 1;
            }
            if(ask[x+1][y-1] == true) {
                counter1+= 1;
            }
            if (counter1 == 3) {
                ask[x][y] = true;
            }
        }
    }
}

if (ask[0][0] == false) {
    one = [UIImage imageNamed:@"w.png"];
}else{
    one = [UIImage imageNamed:@"b.png"];
}

if (ask[0][1] == false) {
    two = [UIImage imageNamed:@"w.png"];
}else{
    two = [UIImage imageNamed:@"b.png"];
}

if (ask[0][2] == false) {
    three = [UIImage imageNamed:@"w.png"];
}else{
    three = [UIImage imageNamed:@"b.png"];
}

if (ask[0][3] == false) {
    four = [UIImage imageNamed:@"w.png"];
}else{
    four = [UIImage imageNamed:@"b.png"];
}

if (ask[0][4] == false) {
    five = [UIImage imageNamed:@"w.png"];
}else{
    five = [UIImage imageNamed:@"b.png"];
}

if (ask[0][5] == false) {
    six = [UIImage imageNamed:@"w.png"];
}else{
    six = [UIImage imageNamed:@"b.png"];
}
if (ask[0][6] == false) {
    seven = [UIImage imageNamed:@"w.png"];
}else{
    seven = [UIImage imageNamed:@"b.png"];
}
if (ask[0][7] == false) {
    eight = [UIImage imageNamed:@"w.png"];
}else{
    eight = [UIImage imageNamed:@"b.png"];
}
if (ask[0][8] == false) {
    nine = [UIImage imageNamed:@"w.png"];
}else{
    nine = [UIImage imageNamed:@"b.png"];
}
if (ask[0][9] == false) {
    ten = [UIImage imageNamed:@"w.png"];
}else{
    ten = [UIImage imageNamed:@"b.png"];
}
if (ask[1][0] == false) {
    eleven = [UIImage imageNamed:@"w.png"];
}else{
    eleven = [UIImage imageNamed:@"b.png"];
}
if (ask[1][1] == false) {
    twelve = [UIImage imageNamed:@"w.png"];
}else{
    twelve = [UIImage imageNamed:@"b.png"];
}
if (ask[1][2] == false) {
    thirteen = [UIImage imageNamed:@"w.png"];
}else{
    thirteen = [UIImage imageNamed:@"b.png"];
}
if (ask[1][3] == false) {
    fourteen = [UIImage imageNamed:@"w.png"];
}else{
    fourteen = [UIImage imageNamed:@"b.png"];
}

if (ask[1][4] == false) {
    fifteen = [UIImage imageNamed:@"w.png"];
}else{
    fifteen = [UIImage imageNamed:@"b.png"];
}

if (ask[1][5] == false) {
    sixteen = [UIImage imageNamed:@"w.png"];
}else{
    sixteen = [UIImage imageNamed:@"b.png"];
}
if (ask[1][6] == false) {
    seventeen = [UIImage imageNamed:@"w.png"];
}else{
    seventeen = [UIImage imageNamed:@"b.png"];
}
if (ask[1][7] == false) {
    eighteen = [UIImage imageNamed:@"w.png"];
}else{
    eighteen = [UIImage imageNamed:@"b.png"];
}
if (ask[1][8] == false) {
    nineteen = [UIImage imageNamed:@"w.png"];
}else{
    nineteen = [UIImage imageNamed:@"b.png"];
}
if (ask[1][9] == false) {
    twenty = [UIImage imageNamed:@"w.png"];
}else{
    twenty = [UIImage imageNamed:@"b.png"];
}
if (ask[2][0] == false) {
    twentyone = [UIImage imageNamed:@"w.png"];
}else{
    twentyone = [UIImage imageNamed:@"b.png"];
}
if (ask[2][1] == false) {
    twentytwo = [UIImage imageNamed:@"w.png"];
}else{
    twentytwo = [UIImage imageNamed:@"b.png"];
}
if (ask[2][2] == false) {
    twentythree = [UIImage imageNamed:@"w.png"];
}else{
    twentythree = [UIImage imageNamed:@"b.png"];
}
if (ask[2][3] == false) {
    twentyfour = [UIImage imageNamed:@"w.png"];
}else{
    twentyfour = [UIImage imageNamed:@"b.png"];
}
if (ask[2][4] == false) {
    twentyfive = [UIImage imageNamed:@"w.png"];
}else{
    twentyfive = [UIImage imageNamed:@"b.png"];
}
if (ask[2][5] == false) {
    twentysix = [UIImage imageNamed:@"w.png"];
}else{
    twentysix = [UIImage imageNamed:@"b.png"];
}
if (ask[2][6] == false) {
    twentyseven = [UIImage imageNamed:@"w.png"];
}else{
    twentyseven = [UIImage imageNamed:@"b.png"];
}
if (ask[2][7] == false) {
    twentyeight = [UIImage imageNamed:@"w.png"];
}else{
    twentyeight = [UIImage imageNamed:@"b.png"];
}
if (ask[2][8] == false) {
    twentynine = [UIImage imageNamed:@"w.png"];
}else{
    twentynine = [UIImage imageNamed:@"b.png"];
}
if (ask[2][9] == false) {
    thirty = [UIImage imageNamed:@"w.png"];
}else{
    thirty = [UIImage imageNamed:@"b.png"];
}

if (ask[3][0] == false) {
    thirtyone = [UIImage imageNamed:@"w.png"];
}else{
    thirtyone = [UIImage imageNamed:@"b.png"];
}
if (ask[3][1] == false) {
    thirtytwo = [UIImage imageNamed:@"w.png"];
}else{
    thirtytwo = [UIImage imageNamed:@"b.png"];
}
if (ask[3][2] == false) {
    thirtythree = [UIImage imageNamed:@"w.png"];
}else{
    thirtythree = [UIImage imageNamed:@"b.png"];
}
if (ask[3][3] == false) {
    thirtyfour = [UIImage imageNamed:@"w.png"];
}else{
    thirtyfour = [UIImage imageNamed:@"b.png"];
}
if (ask[3][4] == false) {
    thirtyfive = [UIImage imageNamed:@"w.png"];
}else{
    thirtyfive = [UIImage imageNamed:@"b.png"];
}
if (ask[3][5] == false) {
    thirtysix = [UIImage imageNamed:@"w.png"];
}else{
    thirtysix = [UIImage imageNamed:@"b.png"];
}
if (ask[3][6] == false) {
    thirtyseven = [UIImage imageNamed:@"w.png"];
}else{
    thirtyseven = [UIImage imageNamed:@"b.png"];
}
if (ask[3][7] == false) {
    thirtyeight = [UIImage imageNamed:@"w.png"];
}else{
    thirtyeight = [UIImage imageNamed:@"b.png"];
}
if (ask[3][8] == false) {
    thirtynine = [UIImage imageNamed:@"w.png"];
}else{
    thirtynine = [UIImage imageNamed:@"b.png"];
}
if (ask[3][9] == false) {
    forty = [UIImage imageNamed:@"w.png"];
}else{
    forty = [UIImage imageNamed:@"b.png"];
}

if (ask[4][0] == false) {
    forty1 = [UIImage imageNamed:@"w.png"];
}else{
    forty1 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][1] == false) {
    forty2 = [UIImage imageNamed:@"w.png"];
}else{
    forty2 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][2] == false) {
    forty3 = [UIImage imageNamed:@"w.png"];
}else{
    forty3 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][3] == false) {
    forty4 = [UIImage imageNamed:@"w.png"];
}else{
    forty4 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][4] == false) {
    forty5 = [UIImage imageNamed:@"w.png"];
}else{
    forty5 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][5] == false) {
    forty6 = [UIImage imageNamed:@"w.png"];
}else{
    forty6 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][6] == false) {
    forty7 = [UIImage imageNamed:@"w.png"];
}else{
    forty7 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][7] == false) {
    forty8 = [UIImage imageNamed:@"w.png"];
}else{
    forty8 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][8] == false) {
    forty9 = [UIImage imageNamed:@"w.png"];
}else{
    forty9 = [UIImage imageNamed:@"b.png"];
}
if (ask[4][9] == false) {
    fifty = [UIImage imageNamed:@"w.png"];
}else{
    fifty = [UIImage imageNamed:@"b.png"];
}
if (ask[5][0] == false) {
    fifty1 = [UIImage imageNamed:@"w.png"];
}else{
    fifty1 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][1] == false) {
    fifty2 = [UIImage imageNamed:@"w.png"];
}else{
    fifty2 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][2] == false) {
    fifty3 = [UIImage imageNamed:@"w.png"];
}else{
    fifty3 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][3] == false) {
    fifty4 = [UIImage imageNamed:@"w.png"];
}else{
    fifty4 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][4] == false) {
    fifty5 = [UIImage imageNamed:@"w.png"];
}else{
    fifty5 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][5] == false) {
    fifty6 = [UIImage imageNamed:@"w.png"];
}else{
    fifty6 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][6] == false) {
    fifty7 = [UIImage imageNamed:@"w.png"];
}else{
    fifty7 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][7] == false) {
    fifty8 = [UIImage imageNamed:@"w.png"];
}else{
    fifty8 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][8] == false) {
    fifty9 = [UIImage imageNamed:@"w.png"];
}else{
    fifty9 = [UIImage imageNamed:@"b.png"];
}
if (ask[5][9] == false) {
    sixty = [UIImage imageNamed:@"w.png"];
}else{
    sixty = [UIImage imageNamed:@"b.png"];
}
if (ask[6][0] == false) {
    sixty1 = [UIImage imageNamed:@"w.png"];
}else{
    sixty1 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][1] == false) {
    sixty2 = [UIImage imageNamed:@"w.png"];
}else{
    sixty2 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][2] == false) {
    sixty3 = [UIImage imageNamed:@"w.png"];
}else{
    sixty3 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][3] == false) {
    sixty4 = [UIImage imageNamed:@"w.png"];
}else{
    sixty4 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][4] == false) {
    sixty5 = [UIImage imageNamed:@"w.png"];
}else{
    sixty5 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][5] == false) {
    sixty6 = [UIImage imageNamed:@"w.png"];
}else{
    sixty6 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][6] == false) {
    sixty7 = [UIImage imageNamed:@"w.png"];
}else{
    sixty7 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][7] == false) {
    sixty8 = [UIImage imageNamed:@"w.png"];
}else{
    sixty8 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][8] == false) {
    sixty9 = [UIImage imageNamed:@"w.png"];
}else{
    sixty9 = [UIImage imageNamed:@"b.png"];
}
if (ask[6][9] == false) {
    seventy = [UIImage imageNamed:@"w.png"];
}else{
    seventy = [UIImage imageNamed:@"b.png"];
}


if (ask[7][0] == false) {
    seventy1 = [UIImage imageNamed:@"w.png"];
}else{
    seventy1 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][1] == false) {
    seventy2 = [UIImage imageNamed:@"w.png"];
}else{
    seventy2 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][2] == false) {
    seventy3 = [UIImage imageNamed:@"w.png"];
}else{
    seventy3 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][3] == false) {
    seventy4 = [UIImage imageNamed:@"w.png"];
}else{
    seventy4 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][4] == false) {
    seventy5 = [UIImage imageNamed:@"w.png"];
}else{
    seventy5 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][5] == false) {
    seventy6 = [UIImage imageNamed:@"w.png"];
}else{
    seventy6 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][6] == false) {
    seventy7 = [UIImage imageNamed:@"w.png"];
}else{
    seventy7 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][7] == false) {
    seventy8 = [UIImage imageNamed:@"w.png"];
}else{
    seventy8 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][8] == false) {
    seventy9 = [UIImage imageNamed:@"w.png"];
}else{
    seventy9 = [UIImage imageNamed:@"b.png"];
}
if (ask[7][9] == false) {
    eighty = [UIImage imageNamed:@"w.png"];
}else{
    eighty = [UIImage imageNamed:@"b.png"];
}

if (ask[8][0] == false) {
    eighty1 = [UIImage imageNamed:@"w.png"];
}else{
    eighty1 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][1] == false) {
    eighty2 = [UIImage imageNamed:@"w.png"];
}else{
    eighty2 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][2] == false) {
    eighty3 = [UIImage imageNamed:@"w.png"];
}else{
    eighty3 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][3] == false) {
    eighty4 = [UIImage imageNamed:@"w.png"];
}else{
    eighty4 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][4] == false) {
    eighty5 = [UIImage imageNamed:@"w.png"];
}else{
    eighty5 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][5] == false) {
    eighty6 = [UIImage imageNamed:@"w.png"];
}else{
    eighty6 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][6] == false) {
    eighty7 = [UIImage imageNamed:@"w.png"];
}else{
    eighty7 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][7] == false) {
    eighty8 = [UIImage imageNamed:@"w.png"];
}else{
    eighty8 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][8] == false) {
    eighty9 = [UIImage imageNamed:@"w.png"];
}else{
    eighty9 = [UIImage imageNamed:@"b.png"];
}
if (ask[8][9] == false) {
    ninety = [UIImage imageNamed:@"w.png"];
}else{
    ninety = [UIImage imageNamed:@"b.png"];
}


if (ask[9][0] == false) {
    ninety1 = [UIImage imageNamed:@"w.png"];
}else{
    ninety1 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][1] == false) {
    ninety2 = [UIImage imageNamed:@"w.png"];
}else{
    ninety2 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][2] == false) {
    ninety3 = [UIImage imageNamed:@"w.png"];
}else{
    ninety3 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][3] == false) {
    ninety4 = [UIImage imageNamed:@"w.png"];
}else{
    ninety4 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][4] == false) {
    ninety5 = [UIImage imageNamed:@"w.png"];
}else{
    ninety5 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][5] == false) {
    ninety6 = [UIImage imageNamed:@"w.png"];
}else{
    ninety6 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][6] == false) {
    ninety7 = [UIImage imageNamed:@"w.png"];
}else{
    ninety7 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][7] == false) {
    ninety8 = [UIImage imageNamed:@"w.png"];
}else{
    ninety8 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][8] == false) {
    ninety9 = [UIImage imageNamed:@"w.png"];
}else{
    ninety9 = [UIImage imageNamed:@"b.png"];
}
if (ask[9][9] == false) {
    hundred = [UIImage imageNamed:@"w.png"];
}else{
    hundred = [UIImage imageNamed:@"b.png"];
}



[one drawAtPoint:CGPointMake(100, 0)];
[two drawAtPoint:CGPointMake(100, 25)];
[three drawAtPoint:CGPointMake(100, 50)];
[four drawAtPoint:CGPointMake(100, 75)];
[five drawAtPoint:CGPointMake(100, 100)];
[six drawAtPoint:CGPointMake(100, 125)];
[seven drawAtPoint:CGPointMake(100, 150)];
[eight drawAtPoint:CGPointMake(100, 175)];
[nine drawAtPoint:CGPointMake(100, 200)];
[ten drawAtPoint:CGPointMake(100, 225)];


[eleven drawAtPoint:CGPointMake(125, 0)];
[twelve drawAtPoint:CGPointMake(125, 25)];
[thirteen drawAtPoint:CGPointMake(125, 50)];
[fourteen drawAtPoint:CGPointMake(125, 75)];
[fifteen drawAtPoint:CGPointMake(125, 100)];

[sixteen drawAtPoint:CGPointMake(125, 125)];
[seventeen drawAtPoint:CGPointMake(125, 150)];
[eighteen drawAtPoint:CGPointMake(125, 175)];
[nineteen drawAtPoint:CGPointMake(125, 200)];
[twenty drawAtPoint:CGPointMake(125, 225)];


[twentyone drawAtPoint:CGPointMake(150, 0)];
[twentytwo drawAtPoint:CGPointMake(150, 25)];
[twentythree drawAtPoint:CGPointMake(150, 50)];
[twentyfour drawAtPoint:CGPointMake(150, 75)];
[twentyfive drawAtPoint:CGPointMake(150, 100)];
[twentysix drawAtPoint:CGPointMake(150, 125)];
[twentyseven drawAtPoint:CGPointMake(150, 150)];
[twentyeight drawAtPoint:CGPointMake(150, 175)];
[twentynine drawAtPoint:CGPointMake(150, 200)];
[thirty drawAtPoint:CGPointMake(150, 225)];



[thirtyone drawAtPoint:CGPointMake(175, 0)];
[thirtytwo drawAtPoint:CGPointMake(175, 25)];
[thirtythree drawAtPoint:CGPointMake(175, 50)];
[thirtyfour drawAtPoint:CGPointMake(175, 75)];
[thirtyfive drawAtPoint:CGPointMake(175, 100)];
[thirtysix drawAtPoint:CGPointMake(175, 125)];
[thirtyseven drawAtPoint:CGPointMake(175, 150)];
[thirtyeight drawAtPoint:CGPointMake(175, 175)];
[thirtynine drawAtPoint:CGPointMake(175, 200)];
[forty drawAtPoint:CGPointMake(175, 225)];

[forty1 drawAtPoint:CGPointMake(200, 0)];
[forty2 drawAtPoint:CGPointMake(200, 25)];
[forty3 drawAtPoint:CGPointMake(200, 50)];
[forty4 drawAtPoint:CGPointMake(200, 75)];
[forty5 drawAtPoint:CGPointMake(200, 100)];
[forty6 drawAtPoint:CGPointMake(200, 125)];
[forty7 drawAtPoint:CGPointMake(200, 150)];
[forty8 drawAtPoint:CGPointMake(200, 175)];
[forty9 drawAtPoint:CGPointMake(200, 200)];
[fifty drawAtPoint:CGPointMake(200, 225)];


[fifty1 drawAtPoint:CGPointMake(225, 0)];
[fifty2 drawAtPoint:CGPointMake(225, 25)];
[fifty3 drawAtPoint:CGPointMake(225, 50)];
[fifty4 drawAtPoint:CGPointMake(225, 75)];
[fifty5 drawAtPoint:CGPointMake(225, 100)];
[fifty6 drawAtPoint:CGPointMake(225, 125)];
[fifty7 drawAtPoint:CGPointMake(225, 150)];
[fifty8 drawAtPoint:CGPointMake(225, 175)];
[fifty9 drawAtPoint:CGPointMake(225, 200)];
[sixty drawAtPoint:CGPointMake(225, 225)];

[sixty1 drawAtPoint:CGPointMake(250, 0)];
[sixty2 drawAtPoint:CGPointMake(250, 25)];
[sixty3 drawAtPoint:CGPointMake(250, 50)];
[sixty4 drawAtPoint:CGPointMake(250, 75)];
[sixty5 drawAtPoint:CGPointMake(250, 100)];
[sixty6 drawAtPoint:CGPointMake(250, 125)];
[sixty7 drawAtPoint:CGPointMake(250, 150)];
[sixty8 drawAtPoint:CGPointMake(250, 175)];
[sixty9 drawAtPoint:CGPointMake(250, 200)];
[seventy drawAtPoint:CGPointMake(250, 225)];

[seventy1 drawAtPoint:CGPointMake(275, 0)];
[seventy2 drawAtPoint:CGPointMake(275, 25)];
[seventy3 drawAtPoint:CGPointMake(275, 50)];
[seventy4 drawAtPoint:CGPointMake(275, 75)];
[seventy5 drawAtPoint:CGPointMake(275, 100)];
[seventy6 drawAtPoint:CGPointMake(275, 125)];
[seventy7 drawAtPoint:CGPointMake(275, 150)];
[seventy8 drawAtPoint:CGPointMake(275, 175)];
[seventy9 drawAtPoint:CGPointMake(275, 200)];
[eighty drawAtPoint:CGPointMake(275, 225)];


[eighty1 drawAtPoint:CGPointMake(300, 0)];
[eighty2 drawAtPoint:CGPointMake(300, 25)];
[eighty3 drawAtPoint:CGPointMake(300, 50)];
[eighty4 drawAtPoint:CGPointMake(300, 75)];
[eighty5 drawAtPoint:CGPointMake(300, 100)];
[eighty6 drawAtPoint:CGPointMake(300, 125)];
[eighty7 drawAtPoint:CGPointMake(300, 150)];
[eighty8 drawAtPoint:CGPointMake(300, 175)];
[eighty9 drawAtPoint:CGPointMake(300, 200)];
[ninety drawAtPoint:CGPointMake(300, 225)];

[ninety1 drawAtPoint:CGPointMake(325, 0)];
[ninety2 drawAtPoint:CGPointMake(325, 25)];
[ninety3 drawAtPoint:CGPointMake(325, 50)];
[ninety4 drawAtPoint:CGPointMake(325, 75)];
[ninety5 drawAtPoint:CGPointMake(325, 100)];
[ninety6 drawAtPoint:CGPointMake(325, 125)];
[ninety7 drawAtPoint:CGPointMake(325, 150)];
[ninety8 drawAtPoint:CGPointMake(325, 175)];
[ninety9 drawAtPoint:CGPointMake(325, 200)];
[hundred drawAtPoint:CGPointMake(325, 225)];}

- (void)dealloc {

}

@end

1 个答案:

答案 0 :(得分:0)

是的,有几个想法。 :d

http://www.oliverfoggin.com/game-of-life/

我接近构建它的方式(如果我要重新开始),将专门用于游戏模型的类(或类的集合)。即发动机。 (我甚至可能在github上放置一个元胞自动机引擎)。

无论如何,我认为你已经研究过生命游戏是如何运作的?

“世界”的大小

您必须首先决定要在应用中创造“世界”的程度。我建议在无限大小上使用有限大小,因为它使数量级不那么复杂。

<强>模型

您需要将您的单元格存储在某种数据结构中。这可以是2D数组或其他东西。我的初始版本是一个bool值的二维数组(true = alive,false = dead)。

计算邻居

你需要一种计算每个细胞的活着邻居数量的方法。

迭代一代

完成上述所有操作后,您应该可以使用这些来推进地图一代。

就像我说的那样,在为应用程序做任何可视化操作之前,先从数据模型和基本函数开始。

完成后,您可以开始研究如何展示您的模型。

这不是一项简单的任务,你可能在整个项目的最后都有“一千”行代码。

最好的方法是潜入并尝试写下来。