Exemple #1
0
void
main(int argc, char *argv[])
{
	int delay = 1000;

	setrules(".d.d..b..d.d.d.d.d");			/* regular rules */
	ARGBEGIN {
	case '3':
		setrules(".d.d.db.b..d.d.d.d");
		break;					/* 34-life */
	case 'o':
		setrules(".d.d.db.b.b..d.d.d");
		break;					/* lineosc? */
	case 'r':					/* rules from cmdline */
		setrules(EARGF(usage()));
		break;
	default:
		usage();
	} ARGEND
	if (argc != 1)
		usage();

	initdraw(g9err, 0, argv0);
	einit(Emouse|Ekeyboard);	/* implies rawon() */

	cen = divpt(subpt(addpt(screen->r.min, screen->r.max),
		Pt(NLIFE * PX, NLIFE * PX)), 2);
	box  = allocimage(display, Rect(0, 0, BX, BX), RGB24, 1, DBlack);
	assert(box != nil);

	redraw();
	readlife(argv[0]);
	do {
		flushimage(display, 1);
		idle();
		sleep(delay);
		idle();
	} while (generate());
	exits(nil);
}
Exemple #2
0
//---------------------------------------------------------------------
//   Function:    main(void)
//   Title:       Main
//   Description: Main function for the game of life
//   Programmer:  TSZ HIN FUNG
//   Date:        12/1/2014
//   Version:     1.00
//   Environment: Intel Xeon PC 
//                Software:   MS Windows 7 for execution; 
//                Compiles under Microsoft Visual Studio.Net 2010
//   Parameter:   void
//   Input:       NONE
//   Output:      Generation with frame
//   Calls:       printGeneration
//                swapPointer
//                calcNextGeneration
//                readlife
//   Return:      EXIT_SUCCESS
//   History Log:
//                12/1/2014  THF completed version 1.0
// --------------------------------------------------------------------
int main(void)
{
	int generation[ROW][COLUMN] = {0};
	int nextGeneration[ROW][COLUMN] = {0};
	int (*pointerOne)[COLUMN] = generation;
	int (*pointerTwo)[COLUMN] = nextGeneration;
	int numberOfGeneration = 0;
	char token = ' ';
	readlife(pointerOne);
	do
	{
		system("cls");
		printf("Generation: %d\n", numberOfGeneration);
		numberOfGeneration++;
		printGeneration(pointerOne);
		calcNextGeneration(pointerOne, pointerTwo);
		swapPointer(&pointerOne, &pointerTwo);
		printf("Press Enter to continue, other keys to quit...");
		token = getch();
	}
	while(token == '\r' || token == '\n' );
	return EXIT_SUCCESS;
}