程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 劣質代碼評析——《寫給大家看的C語言書(第2版)》附錄B之21點程序(五)

劣質代碼評析——《寫給大家看的C語言書(第2版)》附錄B之21點程序(五)

編輯:關於C語言

View Code

 

.  dispCard( cardDrawn, points[.  dispCard( cardDrawn,  points[.    .       (): printf(,.                 points[ACELOW] += .                 points[ACEHIGH] += .                 .       (): printf(,.                 points[ACELOW] += .                 points[ACEHIGH] += .                 .       (): printf(,.                 points[ACELOW] += .                 points[ACEHIGH] += .                 .        : points[ACELOW] +=.                 (cardDrawn==.                    printf(,.                    points[ACEHIGH]+= .                 
.                   points[ACEHIGH]+=.                   printf(.    . }

    

void dispCard(int cardDrawn,int points[]);

void dispCard(int cardDrawn, int points[])
{
   switch(cardDrawn)
   {
      case 11: puts("Jack");
               points[ACELOW]  += 10;
               points[ACEHIGH] += 10;
               break;
      case 12: puts("Queen");
               points[ACELOW]  += 10;
               points[ACEHIGH] += 10;
               break;
      case 13: puts("King");
               points[ACELOW]  += 10;
               points[ACEHIGH] += 10;
               break;
      case 1  :puts("Ace");
               points[ACELOW]  += 1 ;
               points[ACEHIGH] += 11;
               break;                
      default :printf("%d\n",cardDrawn);
               points[ACELOW]  += cardDrawn;
               points[ACEHIGH] += cardDrawn;
               break;
   }
}


 

void dispCard(int cardDrawn);

void dispCard(int cardDrawn)
{
   switch(cardDrawn)
   {
      case 11: puts("Jack");
               break;
      case 12: puts("Queen");
               break;
      case 13: puts("King");
               break;
      case 1  :puts("Ace");
               break;                
      default :printf("%d\n",cardDrawn);
               break;
   }
}

void update(int cardDrawn,int points[]);

void update(int cardDrawn, int points[])
{
   switch(cardDrawn)
   {
      case 11: 
      case 12: 
      case 13: points[ACELOW]  += 10;
               points[ACEHIGH] += 10;
               break;
      case 1  :points[ACELOW]  += 1 ;
               points[ACEHIGH] += 11;
               break;                
      default :points[ACELOW]  += cardDrawn;
               points[ACEHIGH] += cardDrawn;
               break;
   }
}


 

.       playerGetsCard(&.       playerGetsCard(&numCards,cards,playerPoints);

    

.  playerGetsCard( *numCards, cards[.  playerPoints[.  playerGetsCard( *numCards, cards[], playerPoints[.    .    newCard =.    printf(. }

   

 

. printf();

  

.    printf();

  

int main(void)
{
    /*……*/
    do{
        /*……*/
        printf("The dealer draws:");
        dispCard ( dealCard( numCards , cards ) , dealerPoints ) ;
        
        printf("You draw:");
        dispCard ( dealCard( numCards , cards ) , playerPoints) ;
        /*……*/
    }
    while( getAns("\nPlay again(Y/N)?") == 'Y' );  /*詢問是否繼續*/
    return 0;
}

    

.       
.          ans = getAns(.           ( ans == .             playerGetsCard(&.       ( ans !=  );

 

      do
      {
         char ans;
         
         ans = getAns("Hit or stand (H/S)?");
         
         if ( ans == 'H' )
             playerGetsCard(&numCards,cards,playerPoints);
         
         if ( ans == ' S ' )
            break;
         
      }
      while( 1 );

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved