Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
140 lines (127 loc) · 2.67 KB
/
Copy pathindex.js
File metadata and controls
140 lines (127 loc) · 2.67 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
showResult();
});
require('./utils');
const recorder = require('./recorder');
const libClass = require('./classCivilization');
const classCiv = libClass.Civilization;
const classSoc = libClass.Society;
var society = new classSoc();
function showResult () {
processStep = 1;
console.log('>> ');
}
var evoluteEra = 200, stepPerEra = 20;
var developEra = evoluteEra;
var era = 0;
function develop () {
var i, step = stepPerEra;
for (i = 0; i < step; i += 1) {
society.develop(era);
}
era += 1;
society.draw(era);
developEra -= 1;
if (developEra > 0) {
process.nextTick(develop);
}
else {
showResult();
}
}
function setVar (command) {
command = command.split('=');
command = command.map(function (item) {return item.trim()});
if (command[0] === 'era') {
recorder.setEraLength(parseInt(command[1]));
console.log('Set Done.');
}
else if (command[0] === 'evolute') {
evoluteEra = parseInt(command[1]);
console.log('Set Done.');
}
else if (command[0] === 'step') {
stepPerEra = parseInt(command[1]);
console.log('Set Done.');
}
else {
console.log('Missing Command: ' + command[0] + " = " + command[1]);
}
}
var processStep = 0;
process.stdin.resume();
process.stdin.on('data', function (chunk) {
if (processStep === 0) return;
chunk = '' + chunk;
chunk = chunk.replace('\n', '').replace('\r', '');
if (chunk === 'quit') {
console.log('Byebye~~');
process.stdin.pause();
process.stdin.end();
return;
}
console.log('::');
if (chunk === 'dead') {
recorder.showDead();
}
else if (chunk === 'new') {
recorder.show(0);
}
else if (chunk === 'die') {
recorder.show(1);
}
else if (chunk === 'live') {
recorder.show(2);
}
else if (chunk === 'civ') {
recorder.show(3);
}
else if (chunk === 'exp') {
recorder.show(4);
}
else if (chunk === 'found') {
recorder.show(5);
}
else if (chunk === 'ally') {
recorder.show(6);
}
else if (chunk === 'atck') {
recorder.show(7);
}
else if (chunk === 'help') {
recorder.show(8);
}
else if (chunk === 'show') {
recorder.show(9);
}
else if (chunk === 'war') {
recorder.show(10);
}
else if (chunk === 'warP') {
recorder.show(11);
}
else if (chunk === 'hlp') {
recorder.show(12);
}
else if (chunk === 'hlpP') {
recorder.show(13);
}
else if (chunk === 'restart') {
era = 0;
developEra = evoluteEra;
society = new classSoc();
recorder.reset();
develop();
return;
}
else if (chunk.indexOf('set ') === 0) {
chunk = chunk.substring(4, chunk.length);
setVar(chunk);
}
else {
console.log('Missing Order: ' + chunk + " " + (chunk === 'quit'));
}
console.log('>>');
});
develop();