|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
|
主題工具 | 顯示模式 |
2007-11-19, 04:39 PM | #1 |
註冊會員
|
疑問 - 一個小遊戲的程式 該怎麼寫???
-------------------- 閱讀本主題的最佳解答 -------------------- 可以請問一下 下面的小遊戲該怎麼寫呢....... 有高手可以借我參考一下嗎........ 感激不進!! 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 =========================================== |
送花文章: 5,
|
2007-11-22, 03:36 PM | #3 (permalink) |
管理版主
|
這主要有兩部分 Computer的人工智慧 與 判斷輸贏結束 人工智慧方面 設計一個亂數選擇能用的空格去填 是最簡單的 算式: Int((upperbound - lowerbound + 1) * Rnd + lowerbound) ,請自行改成C 至於判斷輸贏結束 首先是 判斷是否連成一線 (是的話結束並推論由誰贏 ※最後下手的人贏) <土法煉鋼> 掃描第一行(1a、1b、1c)、第二行(類推)、第三行(類推) 接著掃描1a、2b、3c 最後掃描1c、2b、3a 再來是計數 第一手的玩家 是否下了5次 是的話結束(可能不分輸贏) |
送花文章: 2027,
|
向 mini 送花的會員:
|
rang0419 (2007-11-23)
感謝您發表一篇好文章 |
2007-11-23, 01:40 AM | #4 (permalink) | |
註冊會員
|
引用:
恩恩!!! 感謝提醒喔~~~ 我在研究看看~~~ |
|
送花文章: 5,
|