-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.cbl
283 lines (224 loc) · 10.3 KB
/
app.cbl
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
******************************************************************
* Author: Gaëtan Hrlt
* Purpose: The game of the Hangman, in COBOL! (Completely useless)
* Tectonics: cobc
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. HANGMAN-GAME.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 a PIC x(1).
77 g PIC x(1).
77 trash PIC x(1).
77 i PIC 9(2).
77 goodGuess PIC 9. *> 0 is False, 1 is True
77 red PIC 99.
77 white PIC 99.
77 black PIC 99.
77 playing PIC 9. *> 0 is False, 1 is True
77 loseLevel PIC 9.
77 hangLine1 PIC x(40).
77 hangLine2 PIC x(40).
77 hangLine3 PIC x(40).
77 hangLine4 PIC x(40).
77 hangLine5 PIC x(40).
77 hangLine6 PIC x(40).
77 hangLine7 PIC x(40).
77 hangLine8 PIC x(40).
77 hangGuessed PIC x(20). *> No word length > 20
77 hangWord PIC x(20).
1 hangWords.
2 word1 PIC X(20) VALUE "hello".
2 word2 PIC X(20) VALUE "world".
2 word3 PIC X(20) VALUE "goodbye".
2 word4 PIC X(20) VALUE "programming".
77 random-index PIC 9(1) COMP.
SCREEN SECTION.
1 titre.
*> Display "HANGMAN GAME!" in ASCII Art
2 BLANK SCREEN.
2 LINE 2 COL 1 VALUE
' _ _ _ _ _ ___ __ __ _ _ _ ___ _'
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
2 VALUE ' __ __ ___ _ '
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
2 LINE 3 COL 1 VALUE
' | || | /_\ | \| |/ __| \/ | /_\ | \| | / __| /_'
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
2 VALUE '\ | \/ | __| | |'
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
2 LINE 4 COL 1 VALUE
' | __ |/ _ \| .` | (_ | |\/| |/ _ \| .` | | (_ |/ _'
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
2 VALUE ' \| |\/| | _| |_|'
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
2 LINE 5 COL 1 VALUE
' |_||_/_/ \_\_|\_|\___|_| |_/_/ \_\_|\_| \___/_/ '
BACKGROUND-COLOR 9
FOREGROUND-COLOR 15.
2 VALUE '\_\_| |_|___| (_)'
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
1 menu.
*> Display the home menu, ask for action to exec
2 LINE 7 COL 7 VALUE
'1) Start a game'
BACKGROUND-COLOR 0
FOREGROUND-COLOR 15.
2 LINE 9 COL 1 VALUE 'What do you want to do? '.
2 action PIC x(1) TO a REQUIRED.
1 start-game.
*> Start the game and all its logic
2 LINE 6 COL 15 VALUE 'The game has started!'.
2 LINE 8 COL 2 FROM hangLine1.
2 LINE 9 COL 2 FROM hangLine2.
2 LINE 10 COL 2 FROM hangLine3.
2 LINE 11 COL 2 FROM hangLine4.
2 LINE 12 COL 2 FROM hangLine5.
2 LINE 13 COL 2 FROM hangLine6.
2 LINE 14 COL 2 FROM hangLine7.
2 LINE 15 COL 2 FROM hangLine8.
2 LINE 11 COL 35 VALUE 'Current guess:'.
2 LINE 13 COL 40 FROM hangGuessed.
2 LINE 17 COL 1 VALUE 'Another guess? '.
2 guess PIC x(1) TO g REQUIRED.
1 you-won.
*> Display win screen
2 BLANK SCREEN.
2 LINE 2 COL 1 VALUE 'YOU WON!'.
1 you-lose.
*> Display lose screen
2 BLANK SCREEN.
2 LINE 2 COL 1 VALUE 'YOU LOSE :('.
1 invalid-action.
*> Warn user and reset
2 BLANK SCREEN.
2 LINE 10 COL 10 VALUE
'Invalid action!'
BACKGROUND-COLOR red
FOREGROUND-COLOR white.
2 LINE 20 COL 1 VALUE
'Press any key to continue...'
BACKGROUND-COLOR black
FOREGROUND-COLOR white.
2 PIC x(1) TO trash REQUIRED.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
*> Assign all colors int to their respective variables
MOVE 12 TO red.
MOVE 15 TO white.
MOVE 0 TO black.
*> Start the game
PERFORM UNTIL action = '1'
INITIALIZE action
DISPLAY titre
DISPLAY menu
ACCEPT action
EVALUATE action
WHEN '1'
MOVE 1 TO playing
*> Obtain word to guess
MOVE FUNCTION RANDOM() TO random-index
*> Not sure how to get a random INTEGER
*> between 1 and hangWords length
*> Actually, it returns 0
ADD 1 TO random-index
MOVE hangWords(random-index:) TO hangWord
PERFORM VARYING i FROM 1 BY 1
UNTIL i > LENGTH OF hangWord
IF hangWord(i:1) = '' THEN
CONTINUE
ELSE
MOVE '_' TO hangGuessed(i:1)
END-IF
END-PERFORM
*> Start the game loop
PERFORM UNTIL playing = 0
MOVE 0 TO goodGuess
*> Assign hang man parts
IF loseLevel = 0 THEN
MOVE ' ' TO hangLine1
MOVE ' ' TO hangLine2
MOVE ' ' TO hangLine3
MOVE ' ' TO hangLine4
MOVE ' ' TO hangLine5
MOVE ' ' TO hangLine6
MOVE ' ' TO hangLine7
MOVE ' ' TO hangLine8
END-IF
IF loseLevel = 1 THEN
MOVE ' ---------------- '
TO hangLine8
END-IF
IF loseLevel = 2 THEN
MOVE ' || '
TO hangLine2
MOVE ' || '
TO hangLine3
MOVE ' || '
TO hangLine4
MOVE ' || '
TO hangLine5
MOVE ' || '
TO hangLine6
MOVE ' || '
TO hangLine7
END-IF
IF loseLevel = 3 THEN
MOVE ' -------------------- '
TO hangLine1
END-IF
IF loseLevel = 4 THEN
MOVE ' || | '
TO hangLine2
END-IF
IF loseLevel = 5 THEN
MOVE ' || O '
TO hangLine3
END-IF
IF loseLevel = 6 THEN
MOVE ' || /|\ '
TO hangLine4
END-IF
IF loseLevel = 7 THEN
MOVE ' || / \ '
TO hangLine5
END-IF
DISPLAY titre
DISPLAY start-game
ACCEPT guess
PERFORM VARYING i FROM 1 BY 1
UNTIL i > LENGTH OF hangWord
IF hangWord(i:1) = guess THEN
MOVE guess to hangGuessed(i:1)
MOVE 1 to goodGuess
END-IF
END-PERFORM
IF goodGuess = 0 THEN
ADD 1 TO loseLevel
IF loseLevel = 8 THEN
MOVE 0 TO playing
END-IF
ELSE
IF hangGuessed = hangWord THEN
MOVE 0 TO playing
END-IF
END-IF
END-PERFORM
IF hangGuessed = hangWord THEN
DISPLAY you-won
ELSE
DISPLAY you-lose
END-IF
WHEN OTHER
DISPLAY invalid-action
END-EVALUATE
END-PERFORM
STOP RUN.
END PROGRAM HANGMAN-GAME.