Krzysztof Mossakowski
Windows Programming
2005 - Tasks
Drawing simple figures
Version A
Game of Life
Demonstration
The board:
background color - standard for window
grid for 40x25 fields
life cells drawn as red ellipses
refresh the board after every step (2 times per second)
resizeable (make sure it will scale properly to the size of window's client area)
initialize randomly cells after pressing Escape key (probability of life for a cell: 50%)
Rules of the game :
a dead cell with exactly three live neighbors becomes a live cell (birth)
a live cell with two or three live neighbors stays alive (survival)
in all other cases, a cell dies or remains dead (overcrowding or loneliness)
use indices modulo size of the board (i.e. the last cell in a row is a neighbour of the first cell in the same row)
Hints:
all created GDI objects must be deleted
objects selected as current on DC must not be deleted
good scenario:
create new object
select new object on DC and remember old object
draw something
restore old object
delete new object
example:
HBRUSH brush = CreateSolidBrush( RGB( 255, 0, 0 ));
HBRUSH oldBrush = (HBRUSH)SelectObject( hdc, brush );
// drawing
SelectObject( hdc, oldBrush );
DeleteObject( brush );
WM_KEYDOWN
Approximate points:
drawing the board : 2.5
resizing the board: 1.5
refreshing the board 2 times per second: 1.5
initializing randomly after pressing Escape key: 2.0
applying rules of the game: 2.5