ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

BLACJACK EN C++


Enviado por   •  28 de Noviembre de 2012  •  467 Palabras (2 Páginas)  •  201 Visitas

Página 1 de 2

#include <iostream>

#include <ctime>

#include <cstdlib>

#include <string>

using namespace std;

int getCardPoints(int value, int & aceValue)

{

if ((value >= 2) && (value <= 10))

{

return (value);

}

else if (value == 1)

{

aceValue = 10; // 11 -1

return 1; // Already contain 1 for the Ace value

}

else if (value == 11)

{

return 10;

}

else if (value == 12)

{

return 10;

}

else if (value == 13)

{

return 10;

}

else

{

cout << "Error! Invalid card value." << endl;

exit (0);

}

}

void displayCardFace(int face)

{

if ((face >= 2) && (face <= 10))

{

cout << face;

}

else if (face == 1)

{

cout << "Ace";

}

else if (face == 11)

{

cout << "Jack";

}

else if (face == 12)

{

cout << "Queen";

}

else if (face == 13)

{

cout << "King";

}

else

{

cout << "Error! Invalid card face." << endl;

exit(0);

}

}

void displayCardSuit(int suit)

{

if (suit == 1)

{

cout << " of spades";

}

else if (suit == 2)

{

cout << " of clubs";

}

else if (suit == 3)

{

cout << " of diamonds";

}

else if (suit == 4)

{

cout << " of hearts";

}

else

{

cout << "Error! Invalid card suit." << endl;

exit(0);

}

}

void displayCard (int face, int suit)

{

displayCardFace(face);

displayCardSuit(suit);

}

int playerLoop(int playerTotal, int & aceValue)

{

string answer;

do

{

cout << "Player's current hand point value is ";

cout << playerTotal;

if (aceValue >0)

cout << " or " << playerTotal + aceValue;

cout << endl;

cout << "Do you want another card? (\"hit\" or \"stay\"): ";

getline(cin, answer);

if (answer == "hit")

{

int nextValue = (rand()%13)+1;

int nextSuit = (rand()%4)+1;

...

Descargar como (para miembros actualizados)  txt (4.3 Kb)  
Leer 1 página más »
Disponible sólo en Clubensayos.com