以前常玩的猜字母遊戲@@
老師會話一個人上吊的圖~~~
然後26個字母 去猜一個單子~~~
不過要寫程一個遊戲 我覺得好難阿
誰可以幫幫我
1.The computer randomly selects an English word from a list of at least 10 English words.
2.The computer randomly exposes some characters of an English word of the lenght n. At least 1 character is exposed and at maximum n - 1 character.
3.The player guesses character by character until the word is solved or the 8 times of wrong guesses is exceeded.
4.Each time a correct character is guessed the character is exposed.
5.They player can decide to continue to play or not.
Hint:
1.To get the string length, use the strlen function.
2.To compare two strings, use the strcmp function.
3.To count the number of strings, refer to the following code:
main() {
char *words[] = {"computer", "information", "engineering", "programming"};
char guess[30];
int i, n = sizeof(words)/sizeof(char *);
printf("List of string: ");
for (i = 0; i < n; i++) printf("%s ", words[i]);
i = rand() % n;
printf("\nEnter your guess : ");
scanf("%s", guess);
printf("Your guess is \"%s\".\n", guess);
printf("Computer selects \"%s\".\n", words[i]);
if (strcmp(guess, words[i])) printf("Your guess is wrong.\n");
else printf("Your guess is correct.\n");
}
A possible session could look like as follows:
The word to guess: -a--c
Your guess => o
The word to guess: -a--c
Your guess => m
The word to guess: ma--c
Your guess => l
The word to guess: ma--c
Your guess => g
The word to guess: mag-c
Your guess => i
Correct! The word is magic.
====================================================
Continue (Y/N)? Y
The word to guess: wo--e-
...
...
You guessed wrong more than 8 times. The word is wonder.
====================================================
Continue (Y/N)? N
Bye!
拜託一下了
