// --------------------------------------------------------------------
//    csc 148f, 1997, Assignment 0: The Game of Life
//    name:            >> Insert your name here <<
//    student number:  >> Insert your student number here <<
//    lecturer:        >> Insert your lecturer's name here <<
//    lecture time:    >> Insert your lecture time here <<
//    tutor:           >> Insert your tutor's name here <<
// --------------------------------------------------------------------


// Author of the starter code: Paul Gries, with small revisions by Diane Horton
// Written: 13 September 1997
// Last revised: 13 September 1997

// An extension of class Life; the number of milliseconds it takes to
// run the program is printed.  There is a third choice for the
// program arguments; they now are 'pretty', 'text', and 'none'.  The
// first two mean exactly what they meant for Life.  If 'none', then
// there is no output except the time it takes to run.

import java.io.*;
import java.awt.*;

// The class TimeOfYourLife contains all the methods needed to track
// how many milliseconds it takes to run Life.
// ----------------------------------------------------------------------
public class TimeOfYourLife extends Life {

    // There must be at least one argument, which is either "file" or
    // "standard".  If there is a second argument, set prettyOutput and
    // textOutput so we know what kind of output to use.
    // ------------------------------------------------------------------
    public static void parseArgs (String[] args) {
        if (args.length > 0) {
            inputPlace = args[0];
        }

        if (args.length == 2 && args[1].equals("none")) {
            prettyOutput = false;
            textOutput = false;
            delay = 0;
        } else if (args.length == 2 && args[1].equals("nodelay")) {
            delay = 0;
        } else {
            Life.parseArgs(args);
        }
    }
    

    // Override.  Keep track of how many milliseconds it takes to run
    // the program.
    // ------------------------------------------------------------------
    public static void main (String[] args) {

        parseArgs(args);

        // Create an instance of class Life; we need to do this since we
        // want to use the instance variables and methods.

        Life lifeRunner = new Life ();
        
        lifeRunner.buildGrid();

        if (prettyOutput) {
            // Make the Frame the right size and location, and show it on the computer
            // screen.
            lifeRunner.resize (Cell.size * (3 + lifeRunner.theGrid.numCols ()),
                      Cell.size * (3 + lifeRunner.theGrid.numRows ()));
            lifeRunner.move(100,100);
            lifeRunner.setBackground(Color.black);
            lifeRunner.show();
        }
        
        if (textOutput) {
            System.out.print("Generation number: ");
            System.out.println(0 + "\n");
            lifeRunner.theGrid.showText();
        }

        long startTime = System.currentTimeMillis();
        lifeRunner.computeGenerations ();
        long stopTime = System.currentTimeMillis();
        
        System.out.println("Total number of milliseconds: " + (stopTime-startTime));

        // System.exit (0);

    }
}
