-
Notifications
You must be signed in to change notification settings - Fork 1
/
spacemines.ldpl
301 lines (253 loc) · 7.86 KB
/
spacemines.ldpl
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# Space Mines
# Ported from BASIC to LDPL by Simon Dann in 2019
# Originally authored by Daniel Isaaman and Jenny Tyler in 1982
DATA:
game/year is number
game/numMines is number
game/numPeople is number
game/money is number
game/food is number
game/foodPrice is number
game/oreProduction is number
game/oreStorage is number
game/satisfaction is number
game/minePrice is number
game/orePrice is number
scratch/r is number
scratch/i is number
scratch/n is number
scratch/s is number
rand/min is number
rand/max is number
rand/r is number
rand/result is number
collect/i is number
PROCEDURE:
##
# Random number generator
# set rand/min for minimum value
# set rand/max for maximum value
# get rand/result for resulting random value
##
sub-procedure roll-random-dice
get random in rand/r
in rand/result solve rand/max - rand/min
in rand/result solve rand/r * rand/result
in rand/result solve rand/result + rand/min
end sub-procedure
##
# Generate Mine Price
##
sub-procedure roll-mine-price
store 2000 in rand/min
store 4000 in rand/max
call sub-procedure roll-random-dice
store rand/result in game/minePrice
floor game/minePrice
end sub-procedure
##
# Generate Ore Price
##
sub-procedure roll-ore-price
store 7 in rand/min
store 12 in rand/max
call sub-procedure roll-random-dice
store rand/result in game/orePrice
floor game/orePrice
end sub-procedure
##
# Initiate Game Variables
##
sub-procedure setup-game
store 1 in game/year
store 0 in game/oreStorage
store 1 in game/satisfaction
store 3 in rand/min
store 6 in rand/max
call sub-procedure roll-random-dice
store rand/result in game/numMines
floor game/numMines
store 40 in rand/min
store 60 in rand/max
call sub-procedure roll-random-dice
store rand/result in game/numPeople
floor game/numPeople
store 10 in rand/min
store 50 in rand/max
call sub-procedure roll-random-dice
store rand/result in game/money
in game/money solve game/money * game/numPeople
floor game/money
store 40 in rand/min
store 80 in rand/max
call sub-procedure roll-random-dice
store rand/result in game/foodPrice
floor game/foodPrice
call sub-procedure roll-random-dice
store rand/result in game/oreProduction
floor game/oreProduction
end sub-procedure
##
# Collect ORE at the end of the game year
# This is called by display-tick and only seperated
# out here for readability.
##
sub-procedure collect-ore
in collect/i solve game/oreProduction * game/numMines
in game/oreStorage solve collect/i + game/oreStorage
end sub-procedure
##
# Display stats for the current game year
##
sub-procedure display-tick
call sub-procedure collect-ore
display "==================================================" CRLF
display "YEAR " game/year ":" CRLF
display CRLF
display "There are " game/numPeople " people in the colony." CRLF
display "You have " game/numMines " mines, and $" game/money CRLF
display "Satisfaction Factor " game/satisfaction CRLF
display CRLF
display "Your mines procuced " game/oreProduction " tons each." CRLF
display "ORE IN STORE=" game/oreStorage " tons." CRLF
display "==================================================" CRLF
end sub-procedure
sub-procedure selling
display CRLF
display "SELLING" CRLF
display "Ore selling price: " game/orePrice CRLF
display "Mine selling price: " game/minePrice "/mine" CRLF
while 1 is equal to 1 do
display "How much ore to sell? "
accept scratch/i
floor scratch/i
if scratch/i is equal to 0 then
break
end if
if scratch/i is greater than 0 then
if scratch/i is less than or equal to game/oreStorage then
in scratch/n solve game/orePrice * scratch/i
floor scratch/n
in game/money solve game/money + scratch/n
in game/oreStorage solve game/oreStorage - scratch/i
break
end if
end if
display "Please enter a number between 1 and " game/oreStorage CRLF
repeat
while 1 is equal to 1 do
display "How many mines to sell? "
accept scratch/i
floor scratch/i
if scratch/i is equal to 0 then
break
end if
if scratch/i is greater than 0 then
if scratch/i is less than or equal to game/numMines then
in scratch/n solve game/minePrice * scratch/i
floor scratch/n
in game/money solve game/money + scratch/n
in game/numMines solve game/numMines - scratch/i
break
end if
end if
display "Please enter a number between 1 and " game/numMines CRLF
repeat
end sub-procedure
sub-procedure buying
display CRLF "You have $" game/money CRLF CRLF
display "BUYING" CRLF
while 1 is equal to 1 do
display "How much to spend on food? $"
accept scratch/i
floor scratch/i
display "Buying $" scratch/i " food" CRLF
if scratch/i is equal to 0 then
break
end if
if scratch/i is greater than 0 then
if scratch/i is less than or equal to game/money then
in game/money solve game/money - scratch/i
in scratch/s solve scratch/i / game/numPeople
if scratch/s is greater than or equal to 120 then
in game/satisfaction solve 0.1 + game/satisfaction
end if
if scratch/s is less than or equal to 89 then
in game/satisfaction solve game/satisfaction - 0.2
end if
break
end if
display "You don't have enough money to afford that amount of food." CRLF
end if
repeat
while 1 is equal to 1 do
display "How many mines to buy? "
accept scratch/i
floor scratch/i
if scratch/i is equal to 0 then
break
end if
if scratch/i is greater than 0 then
in scratch/s solve scratch/i * game/minePrice
floor scratch/s
if scratch/s is less than or equal to game/money then
in game/numMines solve scratch/i + game/numMines
in game/money solve game/money - scratch/s
break
end if
display "That many mines would cost $" scratch/s " you only have $" game/money CRLF
end if
repeat
end sub-procedure
call sub-procedure setup-game
##
# Main Game Loop
##
while 1 is equal to 1 do
call sub-procedure roll-ore-price
call sub-procedure roll-mine-price
call sub-procedure display-tick
call sub-procedure selling
call sub-procedure buying
# Depending on satisfaction between 1 and 10 people will join or leave
store 1 in rand/min
store 10 in rand/max
call sub-procedure roll-random-dice
floor rand/result
# If satisfaction is high, more people arrive
if game/satisfaction is greater than or equal to 1.1 then
in game/numPeople solve rand/result + game/numPeople
end if
# People leave if satisfaction is low
if game/satisfaction is less than 0.9 then
in game/numPeople solve game/numPeople - rand/result
end if
# You win the game if you last ten years
if game/year is equal to 10 then
display "Hurrah! You survived your term of office." CRLF
break
end if
# If the satifaction is too low then its game over
if game/satisfaction is less than 0.6 then
display "The people revolted! Game Over!" CRLF
break
end if
# If there are less than 10 people per mine then its game over
in scratch/s solve game/numPeople / game/numMines
if scratch/s is less than 10 then
display "You have over worked everyone, Game Over!" CRLF
break
end if
# If there are less than 30 people then the game is over
if game/numPeople is less than 30 then
display "Not enough people left, Game Over!" CRLF
end if
# Introduce a small chance of failure, to make things more "FUN"
get random in scratch/r
if scratch/r is less than 0.1 then
display "RADIOACTIVE LEAK... MANY DIE!" CRLF
in game/numPeople solve game/numPeople / 2
floor game/numPeople
end if
in game/year solve 1 + game/year
repeat