-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.js
160 lines (150 loc) · 5.39 KB
/
draw.js
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
hamurabi-almost-from-scratch
This is an attempt of making the game hamurabi using modern programming languages
Copyright (C) 2016 Luiz Eduardo Amaral - <luizamaral306@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
// Functions
function blitScreen(textArr, user, cursor) {
/* Draws a 61 character line at a time until the
end of the `text` string
HAS SIDE EFFECT! messes with textArr
*/
let lineSize = 60;
let totalLines = 19;
let carry = 0;
let printArr = []
// prepare text
textArr.slice(0, textArr.length-1).forEach(value => {
do {
printArr.push(value.slice(0, lineSize));
value = value.slice(lineSize, value.length);
carry++;
} while (value.length > 0)
});
// prepare user input
let lastLine = textArr.slice(textArr.length-1)[0]+user;
let cursorX = (lastLine.length % lineSize + 2)*11.7 + 25;
do {
printArr.push(lastLine.slice(0, lineSize));
lastLine = lastLine.slice(lineSize, lastLine.length);
carry++;
} while (lastLine.length > 0);
let idx;
let slice = (printArr.length-(printArr.length<totalLines? printArr.length: totalLines));
printArr.slice(slice).forEach((value, index) => {
Game.ctx.fillText(value, 50, 50+28*index);
idx = index;
});
let cursorY = 50 + 28 * (idx + (printArr[printArr.length-1].length == lineSize ? 1 : 0));
if (cursor) {
Game.ctx.fillText("_", cursorX, cursorY);
}
}
let gameText = {
intro: [
` HAMURABI ALMOST FROM SCRATCH`,
` A REPRODUCTION OF THIS ANCIENT GAME BY`,
` LUIZ EDUARDO AMARAL - 2016 - ${VERSION}`,
``,
``
],
help: [
`CONGRATULATIONS, YOU ARE THE NEWEST RULER OF ANCIENT SUMERIA`,
`ELECTED FOR A TEN YEAR TERM OF OFFICE. YOUR DUTIES ARE TO`,
`DISPENSE FOOD, DIRECT FARMING, AND BUY/SELL LAND AS NEEDED`,
`TO SUPPORT YOUR PEOPLE.`,
`WATCH OUT FOR RAT INFESTATIONS AND PLAGE! GRAIN IS THE`,
`GENREAL CURRENCY, MEASURED IN BUSHELS`,
` * EACH PERSON NEEDS AT LEAST 20 BUSHELS OF GRAIN PER YEAR`,
` TO SURVIVE`,
` * EACH PERSON CAN FARM AT MOST 10 ACRES OF LAND`,
` * IT TAKES 2 BUSHELS OF GRAIN TO FARM AN ACRE OF LAND`,
` * THE MARKET PRICE FOR LAND FLUCTUATES YEARLY`,
`RULE WISELY AND YOU WILL BE SHOWERED WITH APPRECIATION AT`,
`THE END OF YOUR TERM. RULE POORLY AND YOU WILL BE KICKED OUT`,
`OF OFFICE!`
],
reset: [
`TRY YOU HAND AT GOVERNING ANCIENT SUMERIA`,
`FOR A TEN YEAR TERM OF OFFICE`,
``,
``
],
buyAcres: [`HOW MANY ACRES DO YOU WISH TO BUY? `],
sellAcres: [`HOW MANY ACRES DO YOU WISH TO SELL? `],
feed: [`HOW MANY BUSHELS DO TO FEED YOUR PEOPLE? `],
plant: [`HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? `],
fink: [
`DUE THIS EXTREME MISMANAGEMENT YOU`,
`HAVE NOT ONLY BEEN IMPEACHED AND THROWN`,
`OUT OF OFFICE, BUT YOU HAVE ALSO BEEN DECLARED,`,
``,
` 'NATIONAL FINK!!!'`,
`SO LONG FOR NOW.`
],
cantDo: [
`I CANNOT DO WHAT YOU WISH.`,
`GET YOURSELF ANOTHER STEWARD!!!!!`,
``,
`SO LONG FOR NOW.`
],
plague: [``, `A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED.`],
bountiful: [`HAMURABI: A BOUNTIFUL HARVEST!`],
fantastic: [
`A FANTASTIC PERFORMANCE!!! CHARLEMAGNE, DISRAELI, AND`,
`JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!`
],
heavy: [
`YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV.`,
`THE PEOPLE (REMAINING) FIND YOU AN UNPLEASANT RULER, AND,`,
`FRANKLY, HATE YOUR GUTS!!`
]
}
function reassignText() {
gameText.report = [
`HAMURABI: I BEG TO REPORT TO YOU, IN YEAR ${Game.year},`,
`${Game.starved} PEOPLE STARVED, ${Game.came} CAME TO THE CITY,`,
`POPULATION IS NOW ${Game.population}`,
`THE CITY NOW OWNS ${Game.acres} ACRES.`,
`YOU HARVESTED ${Game.harvest} BUSHELS PER ACRE`,
`RATS ATE ${Game.rats} BUSHELS.`,
`YOU NOW HAVE ${Game.bushels} BUSHELS IN STORE`,
``,
`LAND IS TRADING AT ${Game.trade} BUSHELS PER ACRE`
];
gameText.cantBuy = [
`HAMURABI: THINK AGAIN. YOU HAVE ONLY`,
`${Game.bushels} BUSHELS OF GRAIN. NOW THEN,`
];
gameText.cantSell = [
`HAMURABI: THINK AGAIN. YOU OWN ONLY ${Game.acres} ACRES. NOW THEN,`
];
gameText.cantPlant = [
`BUT YOU HAVE ONLY ${Game.population} PEOPLE TO TEND THE FIELDS! NOW THEN,`
];
gameText.starved = [`YOU STARVED ${Game.starved} PEOPLE IN ONE YEAR!!!`];
gameText.endReport = [
`IN YOUR 10-YEAR TERM OF OFFICE, ${Game.percent} PERCENT OF THE`,
`POPULATION STARVED PER YEAR ON THE AVERAGE, I.E. A TOTAL OF`,
`${Game.died} PEOPLE DIED!!`,
`YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH`,
`${Game.acrePerson} ACRES PER PERSON.`,
``
]
gameText.better = [
`YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER, BUT`,
`${Game.assassin} PEOPLE REALLY LIKE TO SEE YOU ASSASSINATED BUT WE ALL`,
`HAVE OUR TRIVIAL PROBLEMS.`
];
}