本文已参与「新人创作礼」活动,一起开启掘金创作之路。
要求 CPT109 C Programming and Software Engineering 1-ASSESSMENT 2
猜单词的作业
The game of hangman is a popular children’s word guessing game aimed at improving spelling and general knowledge. A secret word is chosen (usually related to a chosen topic e.g. a country or a fruit or vegetable) and the player tries to work out what the word is by guessing letters. Each time a player correctly guesses a letter in he word, then the letters should be filled in at their ppropriate location in the word (see below). Note that he letters can be guessed in any order. If the player uesses a letter incorrectly, then the hangman’s gallows (See igure 1a) are constructed one line at a time for each wrong letter till the player dies after 8 wrong guesses. A possible text-based version of the hangman’s gallows is shown in Figure 1b. Example game:
Secret word entered by player 1 is: Guangzhou
Displayed on the screen is: ???
Player 2 guesses: G
Displayed on the screen is: G???g???..and so on
刽子手游戏是一种流行的儿童猜字游戏,旨在提高拼写能力和常识。 玩家会选择一个秘密单词(通常与所选择的主题相关,如国家或水果或蔬菜),然后通过猜字母来猜出这个单词是什么。 每次玩家猜对单词中的一个字母,这些字母就应该被填在单词中相应的位置(见下文)。 注意,字母的排列顺序是可以猜出来的。 如果玩家猜错了一个字母,那么刽子手的绞刑架(见图1a)就会针对每一个错误的字母一次排成一行,直到玩家在猜错8次后死亡。 图1b显示了一个可能的基于文本的小人上吊版本。
成果展示
三个版本程序下载地址
download.csdn.net/download/re…
主函数如下:
int main()
{
int ret, idx_history = 0;
char user_name[MAX_LETTER_LEN], user_password[MAX_LETTER_LEN],history[128];
while (1) {
int opt_1 = page_1();
switch (opt_1){
case 1: {
if (page_login(user_name, user_password, history) < 0)break;
int run = 1;
while (run) {
int opt_2 = page_play();
switch (opt_2) {
case 1: {
history[strlen(history)] = '\0';
char r = play_a_game();
if (r != 'x') {
history[strlen(history) + 1] = '\0';
history[strlen(history)] = r;
}
break;
}
case 2:
show_history(history);
break;
case 3:
save(user_name, user_password, history);
run = 0;
break;
case 4://清除历史记录
history[0] = '\0';
break;
default:
break;
}
}
break;
}
case 2:
page_regist();
break;
case 3:
return 0;
default:
break;
}
}
return 0;
}