-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLife.java
More file actions
75 lines (54 loc) · 2.15 KB
/
Life.java
File metadata and controls
75 lines (54 loc) · 2.15 KB
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
70
71
72
73
74
75
// =============================================================================
/**
* The <code>Life</code> class. This class is the entry point -- that is, it is
* the class that is invoked on the command line to begin the creation of
* objects used to play the game.
*
* @author Scott F. Kaplan -- sfkaplan@cs.amherst.edu
**/
// =============================================================================
// =============================================================================
public class Life {
// =============================================================================
// =========================================================================
/**
* The program's entry point.
*
* @param args Command line arguments containing the pathname to the initial
* state of the universe and the number of generations to
* compute.
**/
public static void main (String[] args) {
if (args.length != 3) {
showUsageAndExit();
}
else {
String initialStatePathname = args[0];
int generations=0;
boolean graphics=true;
try {
generations = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
showUsageAndExit();
}
if (args[2].equals("nographics"))
graphics=false;
// Create and play the game, evolving one generation at a time.
Game game = new Game(initialStatePathname,generations,graphics);
game.play();
}
} // main ()
// =========================================================================
// =========================================================================
/**
* Print the correct command-line usage and then exit.
**/
protected static void showUsageAndExit () {
Support.abort("USAGE: java Life <initial state pathname>\n" +
" <number of generations to compute>\n"+
" <\"graphics\" or \"nographics\">");
}
// =========================================================================
// =============================================================================
} // class Life
// =============================================================================