6ad88e1eb439767e95592284b5a2b295a57d4280
9 #include "constantstrings.h"
11 void set_clue_across_word (Puzzle
*p
)
14 if (p
->grid_frozen
== false)
16 printf (UNFROZEN_GRID
);
25 fgets (clue
, MAX_CLUE_LENGTH
, stdin
);
26 char* cl
= strtok (clue
, "\n");
28 bool res
= set_across_clue (p
, cl
, index
);
30 printf (NO_WORD_INDEX
);
33 /* clear a cell in the grid */
34 void clear_cell (Puzzle
*p
)
37 if (p
->grid_frozen
== true)
48 if (row
>= p
->grid_size
|| col
>= p
->grid_size
)
50 printf (EXCEED_GRID_SIZE
);
54 p
->chars
[row
][col
] = ' ';
60 /* add a down word to the grid */
61 void add_down_word (Puzzle
*p
)
64 if (p
->grid_frozen
== true)
70 char wd
[MAX_PUZZLE_SIZE
];
73 fgets (wd
, MAX_PUZZLE_SIZE
, stdin
);
74 char *word
= strtok (wd
, "\n");
75 if (! is_valid_word (word
))
77 printf (INVALID_WORD
);
85 if (row
>= p
->grid_size
|| col
>= p
->grid_size
)
87 printf (EXCEED_GRID_SIZE
);
91 if (strlen (word
) > (p
->grid_size
- row
))
93 printf (WORD_TOO_LONG
);
98 for (int i
= row
; i
< row
+ strlen(word
); i
++)
99 p
->chars
[i
][col
] = toupper(word
[i
- row
]);
102 char ch
= getchar ();
105 /* add an across word to the grid */
106 void add_across_word (Puzzle
*p
)
109 if (p
->grid_frozen
== true)
111 printf (FROZEN_GRID
);
112 char ch
= getchar ();
115 char wd
[MAX_PUZZLE_SIZE
];
118 fgets (wd
, p
->grid_size
, stdin
);
119 char *word
= strtok (wd
, "\n");
120 if (! is_valid_word (word
))
122 printf (INVALID_WORD
);
123 char ch
= getchar ();
130 if (row
>= p
->grid_size
|| col
>= p
->grid_size
)
132 printf (EXCEED_GRID_SIZE
);
133 char ch
= getchar ();
137 if (strlen (word
) > (p
->grid_size
- col
))
139 printf (WORD_TOO_LONG
);
140 char ch
= getchar ();
144 for (int i
= col
; i
< col
+strlen (word
); i
++)
145 p
->chars
[row
][i
] = toupper(word
[i
- col
]);
148 char ch
= getchar ();
151 void puzzle_editor_loop (Puzzle
*p
, const char *filename
)
156 print_menu (WHITE
, RED
, PUZZLE_MENU_TITLE
, PUZZLE_EDIT_MENU
, 9, 50);
157 printf (INPUT_CHOICE
);
161 case 1: print_puzzle (p
);
162 char ch
= getchar ();
164 case 2: add_across_word (p
);
166 case 3: add_down_word (p
);
168 case 4: clear_cell (p
);
170 case 5: freeze_puzzle (p
);
174 case 6: unfreeze_puzzle (p
);
178 case 7: set_clue_across_word (p
);
182 case 8: save_puzzle (p
, filename
);
183 printf ("%s\n",FILE_SAVED
);
186 case 9: loop
= false;
192 /* open an existing puzzle */
198 fgets(fname
, 256, stdin
);
199 char* filename
= strtok (fname
, "\n");
200 p
= load_puzzle (filename
);
201 puzzle_editor_loop (&p
, filename
);
204 /* create a new blank puzzle */
210 fgets (fname
, 256, stdin
);
211 char* filename
= strtok (fname
, "\n");
212 printf (INPUT_GRID_SIZE
);
215 if (size
> MAX_PUZZLE_SIZE
)
217 printf (EXCEED_MAX_GRID_SIZE
);
222 init_puzzle (&p
, size
);
223 puzzle_editor_loop (&p
, filename
);
227 /* The main loop of the program */
230 /* Print the main menu */
233 print_menu (WHITE
, BLUE
, MAIN_MENU_TITLE
, MAIN_MENU
, 3, 50);
234 printf (INPUT_CHOICE
);
238 case 1: new_puzzle ();
240 case 2: open_puzzle ();
247 int main (int argc
, char* argv
[])
249 return (main_loop ());