查看單個文章
舊 2007-11-19, 04:39 PM   #1
rang0419
註冊會員
榮譽勳章

勳章總數0
UID - 285008
在線等級: 級別:0 | 在線時長:4小時 | 升級還需:1小時
註冊日期: 2007-11-07
文章: 24
精華: 0
現金: 35 金幣
資產: 35 金幣
預設 一個小遊戲的程式 該怎麼寫???



--------------------
閱讀本主題的最佳解答
--------------------


可以請問一下 下面的小遊戲該怎麼寫呢.......


有高手可以借我參考一下嗎........


感激不進!!


Create a tic-tac-toe game.

(1) First display a welcome message to the game. A player enters her or his name, selects to play first or not, and then start to plays the game.
(2) Display a 3 by 3 tic-tac-toe board.
(3) The player selects the cell to mark. The computer randomly selects the cell to mark.
(4) The game is continuing until there is a winner or the game is tie.
(5) Display the winning points for the winner which are the total of 3 different numbers between 1 and 9 random generated by the computer.
(6) The player can choose to continue a new game.

Hint: Refer to the following code.
welcome (char name[]) {
printf("===========================================\n");
printf("Welcome to the tic-tac-toe game! \n");
printf("Your name: ");
scanf("%s", name);
printf("%s, welcome to the game!\n", name);
printf("===========================================\n");
}

draw_box() {
char box[3][3] = {{'+', '-', '+'}, {'|', ' ', '|'}, {'+', '-', '+'}};
int i, j;

for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) printf("%c", box[i][j]);
printf("\n");
}
}

main() {
char name[40];

welcome(name);
draw_box();
}


A possible run may look like as follows:
===========================================
Welcome to the tic-tac-toe game!
Your name: Rita
Rita, welcome to the game!
===========================================
a b c
1 | |
---+---+---
2 | |
---+---+---
3 | |

Rita, do you want to play first (Y/N)? Y
Rita's step => 2b /* input by the user */

a b c
1 | |
---+---+---
2 | o |
---+---+---
3 | |

Computer's step => 1a /* generated by the computer */

a b c
1 x | |
---+---+---
2 | o |
---+---+---
3 | |

Rita's step => 3c

a b c
1 x | |
---+---+---
2 | o |
---+---+---
3 | | o

Computer's step => 3a

a b c
1 x | |
---+---+---
2 | o |
---+---+---
3 x | | o

Rita's step => 2a

a b c
1 x | |
---+---+---
2 o | o |
---+---+---
3 x | | o

Computer's step => 1c

a b c
1 x | | x
---+---+---
2 o | o |
---+---+---
3 x | | o

Rita's step => 2c

a b c
1 x | | x
---+---+---
2 o | o | o
---+---+---
3 x | | o

===========================================
Congratulations! Rita is the winner.
Your lucky numbers are 7, 5, and 2.
Rita's points: 14
Computer's points: 0
Play more (Y/N)? Y
===========================================
rang0419 目前離線  
送花文章: 5, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖