Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you work with arrays the neighbors of an example cell a[1][1] can be a[0][1], a[2][1], a[1][0] and a[1][2] if you only work in 4 directions.</p> <p>You can also create a class for the cells, which knows its direct neighbor cells, so you can get the left neighbor like cell.getLeftNeighbor().</p> <p><strong>Edit:</strong></p> <p>Ok, so now that you have your code so far we can help a bit more specific. :)</p> <p>The way you implemented it, you would have to access the disease logic in your class PlayingArea. I do not quite understand what your methods in the class Disease do, forTwo() will assign 'E' or 'F' to the char D for example.</p> <p>You need to determine on which coordinates the disease is, you can do it on different ways:</p> <ul> <li><p>Specify the coordinates in PlayingArea, like 5 and 4 = grid[5][4].The direct neighbors are now grid[x-1][x], grid[x+1][x], grid[x][x-1] and grid[x][x+1].</p></li> <li><p>Replace the char[][] with a Cell[][]. You would have to create a class Cell, which only needs to know with a boolean, which letter is in it and if it is diseased. Additionally you can give it other Cells as attributes, this way you can access a cells neighbors directly.</p> <pre><code>public class Cell{ public char letter; public boolean diseased; public Cell leftCell, rightCell, topCell, bottomCell; public Cell(char newLetter){ letter = newLetter; } } </code></pre> <p>This example is without setter/getter methods, you can create cells in the PlayingArea, set the state of disease of each cell and assign/access neighbor cells.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload