Example #1
0
void Ocean::run(void) {
  unsigned numIterations = DefaultNumIterations; // instead of cin
  if (numIterations > 1000) numIterations = DefaultNumIterations;
  for (unsigned iteration = 0; iteration < numIterations; iteration++) {
    if (numPredators > 0 && numPrey > 0) {
      for (unsigned row = 0; row < numRows; row++)
	for (unsigned col = 0; col < numCols; col++)
	  cells[row][col]->process();
      displayStats(iteration);
      displayCells();
      displayBorder();
    }
  }
}
Example #2
0
//////////////////////////////////////////////////////////////////////////////
//                         Program Entry Point
int main(int argc, char **argv)
{
    int argNumCells;

    (void) randomize();

    if (argc == 2) {
        // Grab argument, convert to integer; init cells with passed arg.
        argNumCells = (int)atoi((char*)argv[1]);
        (void) initializeCells(argNumCells);

        // Display message, showing # of init'ed cells.
        printf("[Game of Life:] Initialized %d Cells.", argNumCells);

        // Wait a second.
        delay(1000);
    }
    // No arguments were passed? Initialize Default # of cells.
    else {
        (void) initializeCells(INIT_CELLS);
        delay(1000);
    }

    // Initialize 0x13H Graphics Mode, 320x200x256
    (void) initgraph();

    // Display program message, copyright etc.
    (void) displayMessage();

    // Draw a border around the cell area.
    (void) drawShadedBorder();

#ifdef __MOUSE_ENABLED
    (void) ShowMouse();
#endif


    // Enter main loop
    while ( !kbhit() )
    {

//////////////////////////////////////////////////////////////////////////////
// From my general feelings I am guessing that opening a bracket in an #ifdef
// expecting to close that bracket if there is a following #ifdef a few lines
// down is somewhat of a different idea.  This technique allows me to let the
// user click per iteration that they want to see.
#ifdef __MOUSE_ENABLED
        (void)ReadMouse();

        if (MOUSE_BUTTON_1_PRESSED) {
#endif
// Display & Process cells, then wait delay time, Reapeat until
// keystroke is enacted.
            (void) displayCells();
            (void) processCells();

#ifdef __MOUSE_ENABLED
            (void) processCells();
        }                           // <-- END funky idea.
#endif

        // @see #define DELAY_TIME
        (void) delay(DELAY_TIME);
    }

#ifdef __MOUSE_ENABLED
    (void) HideMouse();
#endif

    // End graphics mode.
    (void) endgraph();

    // Exit politely.
    return EXIT_SUCCESS;
}