CISC181 S2019 Lab3

From class_wiki
Jump to: navigation, search


This assignment continues our use of the Swing library for basic drawing, but also requires mouse interaction and timer events. For review, here again is the documentation for the JFrame, JComponent, Graphics, and Color classes. But also: MouseListener and Swing Timer.

Just like last time:

  • Make a new project (but now n = 3) following these instructions.
  • Name your class "Lab3". This happens when you are creating a new module, in the Java class name field


Modify as you did last week:

For this exercise you will implement the "Game of Life", a cellular automaton on 2-D grid invented by mathematician John Conway in 1970. There is a link to a web-based implementation here.

The update rules are as follows:

  • For a space that is 'populated'
    • Each cell with one or zero neighbors dies, as if from loneliness
    • Each cell with four or more neighbors dies, as if by overpopulation
    • Each cell with two or three neighbors survives
  • For a space that is 'empty' or 'unpopulated', each cell with exactly three neighbors becomes populated

Your implementation does not need to look like the web version above. Rather, at a minimum you must have the following features:

  • At least 100 x 100 grid (larger window, of course)
  • The grid is on a torus (i.e., it wraps horizontally and vertically)
  • No sliders or menus -- just buttons outside of grid area. Don't use JButtons -- just draw rectangles with explanatory labels (strings) and react to mouse clicks inside them.
    • You should provide at least "Clear" (revert grid to all empty), "Start" (begin running simulation steps automatically at some regular time interval), "Stop" (pause simulation animation), "Next" (take exactly one step of the simulation and show result)
    • Buttons that correspond to 4 or more common patterns (e.g., glider, exploder, tumbler). If you choose one of these, then click on the grid, the currently-selected pattern should be "dropped" at that location. Otherwise clicking on a grid square should toggle it from empty to full or back.
    • A "Random" button should randomly populate the entire grid with a well-chosen uniform probability

Finishing up

Remember to use proper naming and formatting style throughout your code, and submit your and on Canvas by midnight (or just after) on Tuesday, March 12