查看單個文章
舊 2008-01-04, 05:50 PM   #1
rang0419
註冊會員
榮譽勳章

勳章總數0
UID - 285008
在線等級: 級別:0 | 在線時長:4小時 | 升級還需:1小時
註冊日期: 2007-11-07
文章: 24
精華: 0
現金: 35 金幣
資產: 35 金幣
預設 如何使用C寫一個猜英文單字的遊戲?

以前常玩的猜字母遊戲@@

老師會話一個人上吊的圖~~~

然後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!






拜託一下了
rang0419 目前離線  
送花文章: 5, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖