0

How can I iterate through an array into my class

I'm trynna implement my function "isCellAliveAtPosition" who takes an integer in argument which is the position(index) of an element of the array. I want to get something telling me that my cell is alive at that position if there is true value(1) and dead if died (0) I tried many things but with OOP it's harder for me https://code.sololearn.com/wEfzwsileUbv/?ref=app

13th Sep 2020, 5:52 PM
Adrien Linares
Adrien Linares - avatar
3 ответов
+ 1
Can you explain to me what the class constructor and buildFixedWorld method was supposed to actually do? I think I'm a bit lost there. And why you make `$cells` member public when you also have a pair of getter and setter?
13th Sep 2020, 8:29 PM
Ipang
+ 1
This is what I came up with, can you check it out once? https://code.sololearn.com/wdiN89EWXc7u/?ref=app
14th Sep 2020, 12:12 PM
Ipang
0
Regarding the encapsulation of cells I was wrong , it's a private variable. The constructor take the number of cells in argument, and initialize the cells array with 100 false boolean values. The buildFixedWorld create an instance of WorldState and has to make 5 cells "alive" so the value of 5 of them must be from false to true But it's another thing I didnt do it well
13th Sep 2020, 8:51 PM
Adrien Linares
Adrien Linares - avatar