This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| identification division. | |
| program-id. hangman. | |
| data division. | |
| working-storage section. | |
| 01 word pic X(100). | |
| 01 word-length pic 9(3). | |
| 01 guess pic X. | |
| 01 filler. | |
| 05 guesses occurs 256 times pic 9. | |
| 05 lives pic 9 value 8. | |
| 01 filler pic X. | |
| 88 won value "1" false "0". | |
| 01 filler pic X. | |
| 88 correct value "1" false "0". | |
| 01 i pic 9(3). | |
| procedure division. | |
| main. | |
| perform pick-word | |
| * TODO: show this in debug mode only | |
| display "word: " word | |
| perform until won or lives = 0 | |
| perform display-lives | |
| perform accept-guess | |
| perform display-guesses | |
| display " " | |
| perform check | |
| end-perform | |
| if won then | |
| display ":)" | |
| else | |
| display ":(" | |
| end-if | |
| goback | |
| . | |
| pick-word. | |
| * TODO: pick random word. | |
| move "hello" to word | |
| move 5 to word-length | |
| . | |
| accept-guess. | |
| display "> " with no advancing | |
| accept guess | |
| move 1 to guesses(function ord(guess)) | |
| . | |
| display-guesses. | |
| perform varying i from 1 by 1 until i > word-length | |
| if guesses(function ord(word(i:1))) = 1 then | |
| display word(i:1) with no advancing | |
| else | |
| display "_" with no advancing | |
| end-if | |
| end-perform | |
| display " " | |
| . | |
| display-lives. | |
| display "lives: ", lives | |
| . | |
| check. | |
| set won to true | |
| set correct to false | |
| perform varying i from 1 by 1 until i > word-length | |
| if guesses(function ord(word(i:1))) <> 1 then | |
| set won to false | |
| end-if | |
| if word(i:1) = guess then | |
| set correct to true | |
| end-if | |
| end-perform | |
| if not correct then | |
| subtract 1 from lives | |
| end-if | |
| . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment