Visual C++

Moderators: Lundin
Number of threads: 379
Number of posts: 695

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Blackjack Game Help Posted by Shoxzor on 28 Nov 2008 at 5:35 PM
My names Rich;
I'm new to these forums, needing some help on my Blackjack C++ Game..
Its a final project && I'm basically clueless
Appreciate the help in advance!




#include <iostream>
#include <ctime>
#include "blackjack.h" // should contain all function prototypes
// and global variables and constants
using namespace std;

int main()
{
// Initialize random number generator
srand(time(0));

// Display welcome message and game rules
welcome();

// Show the house's open card
bool houseHasBigAce = false;
int houseHand = drawOpenHouseCard(houseHasBigAce);

// Then, build the player's hand
int playerHand = buildPlayerHand();
announceResult(PLAYER_SIDE, playerHand);

// Unless the player has busted, build the house's hand
if( playerHand <= 21 ) {
houseHand = buildHouseHand(houseHand, houseHasBigAce);
announceResult(HOUSE_SIDE, houseHand);
}

// Inform the player of the final result
whoWins(playerHand, houseHand);
system("pause");

return 0;
}

The main program of it has been written for us;
& the only thing we have to do is write the remaining functions to complete it.


#include <iostream>
#include <ctime>
#include "test.h" // should contain all function prototypes
// and global variables and constants
using namespace std;
using std::cout;
using std::endl;

int main()
{
welcome();
return 0;
}

void welcome()
{
cout << "Welcome to the game of BLACKJACK " << endl;
cout << " 1. The deck contains an infinite supply of cards" << endl;
cout << " 2. The goal of the game is to assemble a hand whose numerical point value is as close to 21" << endl;
cout << " without going over. Whoever gets closes to 21 without going over wins. " << endl;
cout << " 3. Aces are worth either 1 point or 11 points at the players dicretion. Picture cards are worth" << endl;
cout << " 10 points. All other cards are worth a number of points equal to their numerical value. " << endl;
cout << " 4. The dealer must draw on 16 or less and hold on 17 or more. " << endl;

cout << "LET'S START THE GAME !" << endl;

}
void announceCard(int theCard)
{
switch (theCard)
{
case 1:
cout << "An Ace ";
break;
case 2:
cout << "A Deuce ";
break;
case 3:
cout << "A Three ";
break;
case 4:
cout << "A Four ";
break;
case 5:
cout << "A Five ";
break;
case 6:
cout << "A Six ";
break;
case 7:
cout << "A Seven ";
break;
case 8:
cout << "A Eight ";
break;
case 9:
cout << "A Nine ";
break;
case 10:
cout << "A Ten ";
break;
case 11:
cout << "A Jack ";
break;
case 12:
cout << "A Queen ";
break;
case 13:
cout << "A King ";
break;
}
}

void announceHand (int theHand)
{
cout << "The hand's value is now " << endl;
}

void announceResult (bool side, int theHand)
{
if (theHand > 21) {
if (side == PLAYER_SIDE)
cout << "Player Busted!" << endl;
else
cout << "House Busted!" << endl;
}
else {
if (side == PLAYER_SIDE)
cout << "Player Holds on "<< theHand << endl;
else
cout << "House Holds on " << theHand << endl;
}
}
void whoWins (int playerHand, int houseHand)
{
if (playerHand > houseHand) {
cout << "Player Wins! " << endl;
}
else
{
cout << "House Wins! " << endl;
}
}
bool isPlayerHolding (int theHand)
{
if (

cout << "Do you wish to hold on " << theHand << endl;

}


This is currently my list of functions that I have added to it..
I have a project sheet that walks me through and gives me the functions, but i don't really understand what they are to do etc?

Report
Re: Blackjack Game Help Posted by Shoxzor on 28 Nov 2008 at 5:43 PM
list of output functions / descriptions

void welcome() / displays a welcome message & instruct
void announceCard (int theCard) / display the card just drawn ; 1-10 repersent the cards 1-10 while 11,12 & 13 rep JACK QUEEN KING ( recieves the numeric value of the card.
void announceHand (int theHand) / display the total point value of a hand (receives the num point value of the hand )
void announceReseult (bool side, int theHand) / Display wheither a side holds or has busted
void whoWins (int playerHand, int houseHand) / Announce the winner ( num value of player hand & num value of house hand)

Player Functions / used to build player's hand

bool isPlayerHolding ( int theHand ) / Ask the player whether he wants to hold or draw another card (receives num val of current hand ) ( returns: either t / f

int drawOneCard() / Picks a card at random assuming an infinite supply of cards ( returns numv value of card )

These are the first 7 functions of the program to be added.. I have 8 - 12 left & I need desperate help!


email - shoxzor@gmail.com
aim: shoxzorl

Report
Re: Blackjack Game Help Posted by AsmGuru62 on 29 Nov 2008 at 4:44 AM
...hmmm... I do not need a compiler to see that this will not even compile!
: bool isPlayerHolding (int theHand)
: {
: 	if (
: 
: 	cout << "Do you wish to hold on " << theHand << endl;
: 
: }
: 

Also, where is 'theHand' used in below code?
void announceHand (int theHand)
{
  cout << "The hand's value is now " << endl;
}
Report
Re: Blackjack Game Help Posted by Shoxzor on 29 Nov 2008 at 6:17 PM
I understand that it will not compile, because i am not sure how to write that next function...
im lost?



&&


I really don't know?
Do i need to int it in the main program?





also; i have a header file, where all the functions are to be put?
const bool PLAYER_SIDE = true;
const bool HOUSE_SIDE = false;
void welcome();
void announceHand (int);
void announceResult (bool side, int theHand);
void whoWins (int playerHand, int houseHand);
bool isPlayerHolding (int theHand);
int drawOneCard();

Report
Re: Blackjack Game Help Posted by AsmGuru62 on 30 Nov 2008 at 6:03 AM
I am guessing that it is supposed to be just printed:
:
: 
: void announceHand (int theHand)
: {
:   cout << "The hand's value is now " << theHand << endl;
: }
: 

I am guessing (again) that this function should ask player if he/she wants to hold that hand:
bool isPlayerHolding (int theHand)
{
    cout << "Do you wish to hold on " << theHand << endl;

    // get here player input, probably as text and then check if player
    // said "yes" then return true and if player said "no" then
    // return false.
}

I am not sure of any other logic here - did not play this game much. How does building House hand works? I think initially there should be a pair of cards for each House and Player. After this I am not sure of any logic.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.