C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-22-2009, 08:12 AM   #1
Registered User
 
Join Date: May 2009
Posts: 1
Black Jack Game

This seems to work except the random number thing.
I'm new to C so any help would be awesome.

Code:
#include <stdio.h>
#include <time.h>
#include <string.h>

//Define All Global Variables Here
int MinNumber,MaxNumber,Hand,Dealer,Turn;
char action[20];
char *HitIt = "h";
char *Stay = "s";
char *DealIt = "d";
char *Quit = "q";

//Define All Functions Here
int getrand(int min, int max);
int srand(unsigned);
int rand();
void Hit();
void Deal();
void PlayerHit();
void DealerHit();
void Determine();

int main(int argc, const char * argv[]) {
MaxNumber	= 11;
MinNumber	= 0;
Hand	 = 0;
Dealer	 = 0;
Turn	 = 1;

srand(time(NULL));

Deal();

Determine();

return 0;
}

// Gets two random numbers from 1 to 13 and adds them together and sets the Hand variable to it
// Gets two random numbers from 1 to 13 and adds them together and sets the Dealer variable to it
void Deal() {
Hand = getrand(MinNumber,MaxNumber)+getrand(MinNumber,Max Number);
Dealer = getrand(MinNumber,MaxNumber)+getrand(MinNumber,Max Number);
Turn = 1;

if(Dealer > 20 || Hand > 20) {
printf("\n\nSorry but there was an error :(\n");
printf("\t Player");
printf("\t Dealer \t\n");
printf("\t %i \t",Hand);
printf("\t %i \t\n\n",Dealer);
}
}

// Adds a random number from 1-13 to the players hand variable
void PlayerHit() {
if(Turn == 1) {
Hand += getrand(MinNumber, MaxNumber);
}

else {
printf("Sorry But there was an error");
}
}

// Adds a random number from 1-13 to the dealers Dealer variable
void DealerHit() {
if(Turn == 0) {
Dealer += getrand(MinNumber, MaxNumber);
}

else {
printf("Sorry But there was a dealer error");
}
}

void Determine() {
if(action != NULL) {
if(strcmp(action,HitIt) == 0) {
Turn = 1;
PlayerHit();
}

if(strcmp(action,Stay) == 0) {
if(Dealer < 17) {
Turn = 0;
DealerHit();
}
}

if(strcmp(action,DealIt) == 0) {
printf("\nNew Hand\n\n");
Deal();
}
}

if(Turn == 0) {
if(Dealer < 17) {
DealerHit();
Determine();
}

else if((Dealer < Hand) && (Hand <= 21)) {
DealerHit();
Determine();
}
}

// Start Determining who wins
if(Hand == 21 && Dealer != 21) {
printf("Player:\t %i Black Jack!! you Win\n",Hand);
printf("Dealer:\t %i",Dealer);
printf("\nDeal(d): ");
scanf("%s",action);
Determine();
}

else if(Dealer == 21) {
printf("Player:\t %i\n",Hand);
printf("Dealer:\t %i Black Jack!! Dealer Wins",Dealer);
printf("\nDeal(d): ");
scanf("%s",action);
Determine();
}

else if(Hand > 21 && Dealer < 21) {
printf("Player:\t %i you busted!! \n",Hand);
printf("Dealer:\t %i Dealer Wins",Dealer);
printf("\nDeal(d): ");
scanf("%s",action);
Determine();
}

else if(Hand < 21 && Dealer > 21) {
printf("Player:\t %i you Win\n",Hand);
printf("Dealer:\t %i Dealer busted!!",Dealer);
printf("\nDeal(d): ");
scanf("%s",action);
Determine();
}

else if(Hand > 21 && Dealer > 21) {
printf("Player:\t %i you Busted!!\n",Hand);
printf("Dealer:\t %i dealer busted!!",Dealer);
printf("\nDeal(d): ");
scanf("%s",action);
Determine();
}

else {
if(Turn == 1) {
if(Dealer > Hand) {
printf("Player:\t %i\n",Hand);
printf("Dealer:\t %i",Dealer);
printf("\nYou can Hit(h), or stay(s): ");
scanf("%s",action);
Determine();
}

else {
printf("Player:\t %i\n",Hand);
printf("Dealer:\t %i",Dealer);
printf("\nYou can Hit(h), or stay(s): ");
scanf("%s",action);
Determine();
}
}
}
}

// Generates a Random number between Min and Max
int getrand(int Min,int Max){
return(rand()%(Max-Min)+Min);
}

Last edited by AwesomeMMan; 05-22-2009 at 09:00 PM.
AwesomeMMan is offline   Reply With Quote
Old 05-22-2009, 08:28 AM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
So, are you expecting this game to model a "normal" deck of cards? I've never seen a deck with cards from 0 to 10. Also, getting 21 on more than two cards is not a blackjack. And not only are you dealing zeroes, but you can't even get a blackjack since you're not allowing for aces to count as 11.
tabstop is offline   Reply With Quote
Old 05-22-2009, 10:19 AM   #3
Banned
 
ಠ_ಠ's Avatar
 
Join Date: Mar 2009
Posts: 533
use the code tags please
__________________
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
ಠ_ಠ is offline   Reply With Quote
Reply

Tags
black jack, cards, game, games

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please comment on my c++ game MegaManZZ Game Programming 10 01-22-2008 11:03 AM
beach bar (sims type game) DrKillPatient Game Programming 1 03-06-2006 01:32 PM
HELP!wanting to make full screen game windowed rented Game Programming 3 06-11-2004 04:19 AM
Game Programmer's AIM Circle: Join Today KingZoolerius66 A Brief History of Cprogramming.com 28 12-20-2003 12:12 PM
how do the game engine and the api interact? Shadow12345 Game Programming 7 06-05-2002 10:06 PM


All times are GMT -6. The time now is 03:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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