Exercise 2

משחק החיים

public class GameOfLife {

    public static void main(String[] args) {
        gameOfLife(240,10);
    }

    //YOU CAN ADD MORE FUNCTIONS IF YOU WANT

    public static void gameOfLife(int n, int cellSize){
        //n = 240; cellSize = 10;
        //TODO
    }
    public static void clearCells(boolean[][]cells) {
        //TODO
    }


    public static void drawCells(boolean[][]cells, int cellSize, Color color) {
        StdDraw.setPenColor(color);
        for (int i=0; i<cells.length; i++) {
            for(int j=0; j<cells[0].length; j++) {
                if (cells[i][j]) {
                    double p = (i*cellSize*2 + cellSize)/2;
                    double q = (j*cellSize*2 + cellSize)/2;
                    StdDraw.filledSquare(p, q, cellSize/2);
                }
            }
        }
    }
}

Functions that can help

StdDraw.setXscale(minX, maxX);
StdDraw.setYscale(minY, maxY);
StdDraw.setPenColor(Color.LIGHT_GRAY);

for (int i = 0; i <= n; i+=cellSize) {
		//line(x0, y0, x1, y2)
		StdDraw.line(i, y0, i, y2);
}

for (int i = 0; i <= n; i+=cellSize) {
		//line(x0, y0, x1, y2)
		StdDraw.line(x0, i, x1, i);
}

Running: The Game of Life

Last updated