This site requires JavaScript, please enable it in your browser!
Greenfoot back
Omletti
Omletti wrote ...

2013/6/17

Help me with the right condition in the If-Else-expression

1
2
danpost danpost

2013/6/17

#
Omletti wrote...
@danpost I tried it, but then all lines in which "getX" or "getY" appear are highlighted :(( and it says "cannot find symbol - method getX()"
Just replace all 'getX' calls with 'i' and all 'getY' calls with 'j'.
Omletti Omletti

2013/6/17

#
Okay thank you! It workes now (the program itself) it's just that as soon as I click on run all the cells turn into red :D
Also, from line 116 on, you are changing the objects while in the process of determining what they all should be (within the loop). In doing so, you are changing the neighbours of cells you have not check yet, possibly altering what they should be in the next frame. You should determine what all cells need to become before changing any of them; then, change all of them to their new state at once.
@danpost I'm sorry I did not understand anything of that? Could you maybe show me what you exactly mean?
danpost danpost

2013/6/17

#
Let us say there is a cell that has four neighbours. If, upon checking one of its neighbours, you end up removing it, the cell would now only have three neighbours. So now, when you finally check said cell, it will stay instead of being removed (like it should have been). You need to determine and record the number of neighbours for ALL cells, first. Then, update All the cells using the recorded counts.
// in pseudo-code
public void act()
{
    for each cell
    {
        count neighbors
    }
    for each cell
    {
        use neighbors counted to determine new state
    }
}
Omletti Omletti

2013/6/17

#
Ah okay! Thank you :)
You need to login to post a reply.
1
2