Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Looking for a solution or inner logic for javafx Black Jack game. (Totally unfam

ID: 3823853 • Letter: L

Question

Looking for a solution or inner logic for javafx Black Jack game. (Totally unfamiliar with card games):

Create a program in which a user plays a simple version of the card game 21 against the computer. The computer will run a network server process allowing client players to connect. Each player is initially dealt two cards from a standard deck of 52. Random numbers will represent the cards from 1 to 10. After seeing their hand the user then the house (computer) are given the opportunity to take additional cards (hit me). The hand that comes the closest to 21 without exceeding 21 wins the game. A draw results if both players have the same score.

This application should use GUI elements to show the player their cards. You may use the attached card setView in a new window or your own. Your application should have a way to:

    shuffle the deck
    a way to deal cards to the players
    Show the current score based on hands won / hands lost

Explanation / Answer

#include <iostream>

#include <ctime>

#include <string>

using namespace std;

void play21(void);

int dealCards(int, string);

void hit(int &);

void determineWinner(int, int);

int Random(int, int);

void main(){

char keepPlaying = 'n';

do {

play21();

cout << "Do you want to play another hand (y/n)?";

cin >> keepPlaying;

} while(keepPlaying == 'Y' || keepPlaying == 'y');

}

void play21(void){

srand((int) time(0));

int person = dealCards(2, "Your Cards:");

cout << " = " << person << endl;

int house = dealCards(2, "Computers Cards:");

cout << " = " << house << endl;

hit(person);

cout << endl;

while ((house < person) && (house <= 21) && (person <= 21))

{

house += dealCards(1, "The Computer takes a card ");

cout << endl;

}

determineWinner(person, house);

}

void determineWinner(int humanScore, int houseScore)

{

if (humanScore == 21)

cout << "You have 21. You win!" << endl;

else if ((humanScore < 21) && (humanScore > houseScore))

cout << "You have the closer hand to 21. You win!" << endl;

else

cout << "The computer wins, sorry try again." << endl;

}

int dealCards(int numberOfCards, string message)

{

int return_value = 0;

int value = 0;

for (int a = 0; a <= numberOfCards; a++)

{

int cards = a;

while(cards--)

{

value = Random(0,10);

cout << value << " ";

if(cards)

cout << " , ";

return_value += value;

}

}

return return_value;

}

void hit(int &playerScore)

{

int cardCount = 0;

char wantCard = "y" || "n";

int cardTotal = 0;

cardTotal = playerScore;

cout << "Would you like another card?";

while (wantCard == 'Y' || wantCard == 'y')

{

if ((cardTotal > 0 ) && (cardTotal < 21))

cardCount += 1;

cardTotal += Random(0,10);

cout << "Your total is: " << cardTotal;

cout << "Do you want another card?";

cin >> wantCard;

if (wantCard == 'Y' || wantCard == 'y')

cout << cardTotal + dealCards(1, "You take a card.");

else

cout << "You decide to stand";

if (cardTotal > 21)

cout << "You have gone over 21, You Lose";

}

}

int Random(int lowerLimit, int upperLimit)

{

return 1 + rand() % (upperLimit - lowerLimit + 1);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote