You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Week4/prep-exercises/2-game-of-life/README.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,8 @@ This class represents a single cell.
29
29
|----------|-------------|
30
30
| constructor() | Initializes the cell's `x` and `y` coordinates from arguments passed to the constructor. It randomly sets the initial `alive` boolean state of the cell and initializes its next `alive` state. |
31
31
| draw() | Draws the cell on the canvas. The visual representation depends on whether the cell is alive or dead. |
32
+
| liveAndLetDie() | Determines the next state (alive or dead) depending on the number of living neighbors of the cell, by applying the rules of the Game Of Life. |
33
+
| update() | Updates the state of the cell (alive or dead) as set previously by `liveAndLetDie()`.
32
34
33
35
### `class Grid`
34
36
@@ -41,7 +43,7 @@ This class manages the game grid, made up of cells.
41
43
|`forEachCell()`| Executes a callback function for each cell in the two-dimensional grid array, passing the cell as a parameter to the callback. |
42
44
|`isAlive()`| Determines whether a cell at the given coordinates is alive or dead. The coordinates could potentially be off-grid. Off-grid cells are presumed to be dead. The function returns one if the given cell is alive or zero if its dead. |
43
45
|`countLivingNeighbors()`| Counts the number of living neighbors for a given cell. Each cell has eight neighbors, some of which may be off-grid if the cell is located at an edge or a corner of the grid. |
44
-
|`update()`| Iterates through all cells of the grid and computes the new state of each cell by applying the rules of the Game Of Life. |
46
+
|`update()`| Iterates through all cells of the grid and computes the new state of each cell. |
45
47
|`render()`| Iterates through all cells of the grid and draws each cell onto the canvas. |
46
48
47
49
### `class Game`
@@ -83,7 +85,7 @@ In the supplied JavaScript code the color of all living cells is a single shade
83
85
| 3 | 0.75 |
84
86
| 4+ | 1 |
85
87
86
-
3. In the `update` method of the `Grid` class add code to update the `lifeTime` value of each cell:
88
+
3. In the `liveAndLetDie()` method of the `Cell` class add code to update the `lifeTime` value of each cell:
87
89
88
90
- A living cell that remains living should have its `lifeTime` incremented by one.
89
91
- A living cell that dies should have its `lifeTime` reset to zero.
0 commit comments