- 最後登錄
- 2024-11-16
- 在線時間
- 1052 小時
- 註冊時間
- 2006-9-27
- 閱讀權限
- 30
- 精華
- 0
- UID
- 281895
- 帖子
- 2096
- 積分
- 1823 點
- 潛水值
- 53651 米
| 關於類似洗牌指定牌的概念問題 ???
我的問題是我今天把牌 發出去 ( 不重複的問題解決了 )
不過 假如我要指定輸入的位置 它的位置竟然會顯示和在螢幕上位置不一樣
想了好久 目前沒有想法 想問問這問題的概念 解題技巧- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void shuffle( int deck[][ 13 ] );
- void deal( int deck[][ 13 ], char *face[],
- char *suit[] );
- int main()
- {
- int i,j;
- char c[10];
- char *suit[ 4 ] = { "c", "d", "h", "s" };
- char *face[ 13 ] =
- { "a", "2", "3", "4",
- "5", "6", "7", "8",
- "9", "t", "j", "q", "k" };
- int deck[ 4 ][ 13 ] = { 0 };
-
- srand(time(0));
- p rintf("=================================================\n"
- "Welcome to the Happy Card Game!\nYour name:");
- scanf("%s",&c);
- p rintf("%s, welcome to the game!\n"
- "=================================================\n"
- "The card table is shown as follows:\n"
- "-------------------------------------------------\n",c);
-
- shuffle( deck );
- deal( deck, face, suit );
- p rintf("\n-------------------------------------------------\n"
- "Who plays first: Player (P) or Computer (C)?\n");
-
-
-
-
- p rintf("\n");
- system("pause");
- return 0;
- }
- void shuffle( int deck[][ 13 ] )
- {
- int row;
- int column;
- int card;
- for ( card = 1; card <= 52; card++ ) {
-
- do {
- row = rand() % 4;
- column = rand() % 13;
- } while( deck[ row ][ column ] != 0 );
-
- deck[ row ][ column ] = card;
- }
- }
- void deal( int deck[][ 13 ], char *face[],
- char *suit[] )
- {
- int card;
- int row;
- int column;
-
- for ( card = 1; card <= 36; card++ ) {
- if (card % 6 == 1) p rintf("\n");
- for ( row = 0; row <= 3; row++ ) {
- for ( column = 0; column <= 12; column++ ) {
- if ( deck[ row ][ column ] == card ) {
- p rintf( "%s%s ", face[ column ], suit[ row ]);
- }
- }
- }
- }
- }
複製代碼 ... |
|