一個小遊戲的程式 該怎麼寫???
可以請問一下 下面的小遊戲該怎麼寫呢.......
有高手可以借我參考一下嗎........ 感激不進!! :on_22: 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 =========================================== |
忘了說 要用C來寫 囧
|
這主要有兩部分
Computer的人工智慧 與 判斷輸贏結束 人工智慧方面 設計一個亂數選擇能用的空格去填 是最簡單的 算式: Int((upperbound - lowerbound + 1) * Rnd + lowerbound) ,請自行改成C 至於判斷輸贏結束 首先是 判斷是否連成一線 (是的話結束並推論由誰贏 ※最後下手的人贏) <土法煉鋼> 掃描第一行(1a、1b、1c)、第二行(類推)、第三行(類推) 接著掃描1a、2b、3c 最後掃描1c、2b、3a 再來是計數 第一手的玩家 是否下了5次 是的話結束(可能不分輸贏) |
引用:
恩恩!!! 感謝提醒喔~~~ 我在研究看看~~~:on_79: |
所有時間均為台北時間。現在的時間是 07:40 PM。 |
Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.
『服務條款』
* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *