Kill mega-sena.sh
[lcapit-junk-code.git] / games / hangman / main.c
blobbecabaed55c070d0fb981eba5c62272bced611f5
1 /*
2 * hangman: hangman game implementation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Luiz Fernando N. Capitulino
19 * <lcapitulino@gmail.com>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <errno.h>
26 #include "dict.h"
27 #include "misc.h"
28 #include "game.h"
30 #define UNUSED(x) (x = x)
32 enum options {
33 NEW_GAME = 1,
34 CHANGE_DICT,
35 EXIT_GAME
38 static void usage(void)
40 printf("Usage: hangman [ -h | -d ]\n");
43 int main(int argc, char *argv[])
45 enum options op;
46 struct dict_line line;
48 UNUSED(argv);
50 if (argc > 1) {
51 if (!memcmp(argv[1], "-h", 2)) {
52 usage();
53 exit(0);
55 if (!memcmp(argv[1], "-d", 2))
56 game_debug = 1;
59 for (;;) {
60 clear_screen();
62 printf("\nJogo da forca\n\n");
63 printf("1. Novo jogo\n"
64 "2. Manipular dicionario\n"
65 "3. Sair\n"
66 "\n-> opcao: ");
67 scanf("%d", (int *) &op);
68 flush_all();
70 switch (op) {
71 case NEW_GAME:
72 dict_pick_up_word(&line);
73 run_game(line.word, line.tip);
74 break;
75 case CHANGE_DICT:
76 dictionary_menu();
77 break;
78 case EXIT_GAME:
79 printf("\nBye, bye!\n");
80 exit(0);
81 default:
82 errno = EINVAL;
83 eprint("Function not implemented");
87 return 0;