-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlife.c
69 lines (57 loc) · 1.3 KB
/
life.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* life.c : Conway's Game of Life in C */
/* Author: Trevor Bramwell
Date: 04/20/2011
Version: 0.1 */
#include <stdlib.h>
#include <ncurses.h>
#include "board.h"
#include "life.h"
int main(void) {
WINDOW *my_win;
int x, y;
int h, w;
Board *b;
int ch,count;
initscr(); //initialize window
keypad(stdscr, TRUE);
noecho(); // disable echoing of input
/* Setup Window */
h = BOARD_SIZE+4;
w = (BOARD_SIZE*2)+2;
getmaxyx(stdscr, y, x);
my_win = newwin(h, w, (y-h)/2, (x-w)/2);
/* Setup Board */
b = newBoard(BOARD_SIZE);
count=0;
/* Print Command Menu */
refresh();
printMenu();
do {
werase(my_win);
box(my_win, 0, 0);
printBoard(b, my_win);
mvwprintw(my_win, h-2, 1, "Iter:%i", count);
refresh();
wrefresh(my_win);
updateCells(b);
changeState(b);
count++;
} while((ch = getch()) != 'q');
deleteBoard(b);
delwin(my_win);
endwin();
return 0;
}
void printMenu(void) {
WINDOW *win;
int x, y;
int h, w;
h = 8;
w = 20;
x = (COLS/2)+BOARD_SIZE+2;
y = (LINES - BOARD_SIZE)/2;
win = newwin(h, w, y-1, x);
mvwprintw(win, 0, 0, "COMMANDS");
mvwprintw(win, 1, 0, " q: Quit");
wrefresh(win);
}