BlackJack Game

This is a discussion on BlackJack Game within the C Programming forums, part of the General Programming Boards category; Can anyone help me with this code...More details below: Code: #include <stdio.h> #include <time.h> #include <stdlib.h> int CardValue; int Players[2] ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    24

    BlackJack Game

    Can anyone help me with this code...More details below:

    Code:
    #include <stdio.h> 
    #include <time.h> 
    #include <stdlib.h> 
    
    
    
    int CardValue; 
    int Players[2] = {0}; 
    
    int main ( void ) 
    { 
    
      void showHand ( char *val1, char *val2, char *val3, char *val4 ); 
      int randomNumber(int max); 
      int HitStay(void); 
      char *DealCards(int n, int ToWhom); 
      char *assignCardValue(void);    
      
      char *card1; 
      char *card2; 
      char *card3; 
      char *card4; 
      srand((unsigned int)time(NULL)); 
    
      
      card1 = DealCards(1,0); 
      card2 = DealCards(1,0); 
      card3 = DealCards(1,1); 
      card4 = DealCards(1,1); 
      showHand(card1, card2, card3,""); 
    
      printf("You have a total of %d Points\t\t Dealers first card is %2s\n", Players[0], card3); 
      HitStay(); 
      
      getchar(); 
      return 0; 
    } 
    
    /* _______________showHand Function_______(uses stdio.h)______________________*/ 
    
    void showHand ( char *val1, char *val2, char *val3, char *val4 ) 
    { 
      printf ( "***********\t***********\t\t***********\t***********\n" ); 
      printf ( "*%2s       *\t*%2s       *\t\t*%2s       *\t*%2s       *\n", val1, val2,val3, val4); 
      printf ( "*         *\t*         *\t\t*         *\t*         *\n" ); 
      printf ( "*         *\t*         *\t\t*         *\t*         *\n" ); 
      printf ( "*         *\t*         *\t\t*         *\t*         *\n" ); 
      printf ( "*         *\t*         *\t\t*         *\t*         *\n" ); 
      printf ( "*         *\t*         *\t\t*         *\t*         *\n" ); 
      printf ( "*      %2s *\t*      %2s *\t\t*      %2s *\t*      %2s *\n", val1, val2, val3, val4); 
      printf ( "***********\t***********\t\t***********\t***********\n\n" ); 
    } 
    
    /* ______________randomNumber Function____(uses: stdlib.h and time.h)_________*/ 
      
    int randomNumber(int max) /* MAX is N + 1 */ 
    { 
    
    int Xrand; 
    Xrand =   rand() % max; 
    
    return Xrand; 
    } 
    
    /*______________assignCardValue Function__________*/ 
    
    char *assignCardValue(void) 
    { 
    
    char *CardName[] = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; 
    int  value[] = {  1,   2,   3,   4,   5,   6,   7,   8,   9,   10,  10,  10,  10 }; 
    
    int r = randomNumber ( 13 ); 
    CardValue = value[r]; 
    return CardName[r]; 
    
    } 
    
    /*____________________DealCards() Function ______________*/ 
    char *DealCards(int n, int ToWhom) 
    { 
    
    int i; 
    char *cards; 
    
    for (i = 0; i = n; i++) 
    { 
       cards = assignCardValue(); 
       Players[ToWhom] += CardValue; 
       break; 
    } 
    
    return cards; 
    } 
    
    /*___________HitStay() Function___________*/ 
    
    int HitStay(void) 
    { 
           
    	  
      
    return 0; 
    } 
    
    /*________HandleDealersHand() Function_______*/ 
    
    /*________ShowDealerHand() Function_____*/
    Cant seam to get my Loop to work for Hit or Stay Function...

    I have a function:
    Code:
    int HitStay(void) 
    { 
    
    return 0; 
    }
    Inside i need to get the players choice H for Hit and S for Stay...

    If the player chooses H thee function DealCards(1,1) is called and the new total of his cards should be printed.

    Code:
    printf("Your total is %d", Players[0]);
    From there the play should be asked again if they wish to Hit or Stay... If they choose stay then the loop should be exited....

    Iv tried several times but cant seam to figure out why my while loop doesnt work...

  2. #2
    Registered User Eigenvalue's Avatar
    Join Date
    Aug 2002
    Posts
    21
    Where is the while loop you are having problems with? I didn't see it in the code you posted.

    Eigenvalue

    [edit]I am obviously obsessed with while loops. Sorry about that! [/edit]
    Last edited by Eigenvalue; 11-12-2002 at 11:18 AM.
    "I'm not responsible for what other people think I am able to do." -- Richard Feynman

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    for (i = 0; i = n; i++)

    I think you mean:

    for (i = 0; i < n; i++)

  4. #4
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    actually what does your game do ???
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 10:46 AM
  3. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-21-2006, 11:23 PM
  4. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-25-2006, 11:14 PM
  5. Game Programmer's AIM Circle: Join Today
    By KingZoolerius66 in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-20-2003, 11:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21