Commit | Line | Data |
---|---|---|
ef609d98 KB |
1 | /* |
2 | * Copyright (c) 1987 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
11 | */ | |
12 | ||
13 | #ifndef lint | |
85a9d303 | 14 | static char sccsid[] = "@(#)getguess.c 5.2 (Berkeley) %G%"; |
ef609d98 KB |
15 | #endif /* not lint */ |
16 | ||
17 | # include "hangman.h" | |
18 | ||
19 | /* | |
20 | * getguess: | |
21 | * Get another guess | |
22 | */ | |
23 | getguess() | |
24 | { | |
25 | register int i; | |
26 | register int ch; | |
27 | register bool correct; | |
28 | ||
29 | leaveok(stdscr, FALSE); | |
30 | for (;;) { | |
31 | move(PROMPTY, PROMPTX + sizeof "Guess: "); | |
32 | refresh(); | |
33 | ch = readch(); | |
34 | if (isalpha(ch)) { | |
35 | if (isupper(ch)) | |
36 | ch = tolower(ch); | |
37 | if (Guessed[ch - 'a']) | |
38 | mvprintw(MESGY, MESGX, "Already guessed '%c'", ch); | |
39 | else | |
40 | break; | |
41 | } | |
85a9d303 | 42 | else if (ch == CTRL('D')) |
ef609d98 KB |
43 | die(); |
44 | else | |
45 | mvprintw(MESGY, MESGX, "Not a valid guess: '%s'", | |
46 | unctrl(ch)); | |
47 | } | |
48 | leaveok(stdscr, TRUE); | |
49 | move(MESGY, MESGX); | |
50 | clrtoeol(); | |
51 | ||
52 | Guessed[ch - 'a'] = TRUE; | |
53 | correct = FALSE; | |
54 | for (i = 0; Word[i] != '\0'; i++) | |
55 | if (Word[i] == ch) { | |
56 | Known[i] = ch; | |
57 | correct = TRUE; | |
58 | } | |
59 | if (!correct) | |
60 | Errors++; | |
61 | } | |
62 | ||
63 | /* | |
64 | * readch; | |
65 | * Read a character from the input | |
66 | */ | |
67 | readch() | |
68 | { | |
69 | register int cnt, r; | |
70 | auto char ch; | |
71 | ||
72 | cnt = 0; | |
73 | for (;;) { | |
74 | if (read(0, &ch, sizeof ch) <= 0) | |
75 | { | |
76 | if (++cnt > 100) | |
77 | die(); | |
78 | } | |
85a9d303 | 79 | else if (ch == CTRL('L')) { |
ef609d98 KB |
80 | wrefresh(curscr); |
81 | mvcur(0, 0, curscr->_cury, curscr->_curx); | |
82 | } | |
83 | else | |
84 | return ch; | |
85 | } | |
86 | } |