#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define MAX_WORDS 10 #define MAX_WORD_LENGTH 50 char words[MAX_WORDS][MAX_WORD_LENGTH] = { "apple", "banana", "orange", "watermelon", "strawberry", "pineapple", "grapefruit", "kiwi", "blueberry", "mango" }; int main() { int size; char input[MAX_WORD_LENGTH]; srand(time(0)); printf("欢迎来到疯狂打字游戏!\n"); printf("你将会看到一系列乱序的字母,你需要输入对应的正确单词。\n"); printf("输入"exit"可以退出游戏。\n");

int score = 0;
int round = 1;
while (1) {
    printf("\n第 %d 轮:\n", round);
    // 随机选择一个单词
    int randomIndex = rand() % MAX_WORDS;
    char word[MAX_WORD_LENGTH];
    strcpy(word, words[randomIndex]);
    // 乱序字母
    int wordLength = strlen(word);
    for (int i = 0; i < wordLength; i++) {
        int randomIndex = rand() % wordLength;
        char temp = word[i];
        word[i] = word[randomIndex];
        word[randomIndex] = temp;
    }
    // 显示乱序字母
    printf("乱序字母:%s\n", word);
    // 接受用户输入
    // input = (int*)malloc(size * sizeof(int));
    printf("请输入单词:");
    scanf("%49s", input);
    // 检查退出条件
    if (strcmp(input, "exit") == 0) {
        break;
    }
    // 检查答案
    if (strcmp(input, words[randomIndex]) == 0) {
        printf("回答正确!\n");
        score += 10;
    }
    else {
        printf("回答错误!正确答案是:%s\n", words[randomIndex]);
    }
    round++;
}
printf("\n游戏结束!你的得分是:%d\n", score);
return 0;

}


原文地址: https://www.cveoy.top/t/topic/pKMV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录