HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack

HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack - welcome to our blog that presents the full content How Gadget, the discussion this time we're discussing that you find that HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack, we have provided complete information with images that are easy to understand, the explanation is simple but complete, therefore please read until the end :)

This is about : HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack
And this article : HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack

You can also see our article on:


    HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack


    (updated : 27/02/2015)

    Blackjack, also known as twenty-one, is the most widely played casino banking game in the world. Blackjack is a comparing card game between a player and dealer, meaning that players compete against the dealer but not against any other players. It is played with one or more decks of 52 cards. The object of the game is to beat the dealer, which can be done in a number of ways:


    • Get 21 points on the player's first two cards (called a blackjack), without a dealer blackjack;
    • Reach a final score higher than the dealer without exceeding 21; or
    • Let the dealer draw additional cards until his or her hand exceeds 21.

    (source : wikipedia)




    This post is about how to make a console version of this game using C++. Console version means, it is played in command prompt like window. It is not very hi-tech complex graphic based version, so dont have too much expectation. You can say that this is the programmers version of the game. Its not that console games are not fun to play. Some of the best games, a decade ago, were console based.

    In this version of the game, you cannot see the cards, the points and the betting are calculated virtually. Only the numbers will be displayed. Its completely text based. But nevertheless, the thrill of the game won't be left unfelt.

    Logic of the code :

    To generate a new card every turn, I have used the randomize function to randomly generate numbers from 1-10 (or 11, depending on the situation). These randomly generated numbers will add up each turn. If the user lands exactly on 21 points, the user wins. If he/she exceeds 21, they will loose. In any other case, the dealer get to play. The points of the dealer is also calculated in the same way. In between the game, the user can choose to hit/stay. 'Hit' will generate another number, 'stay' will stop the user's turn and the dealer begins to play. This way the game is played.

    The code for the game is given below. You can either understand the code and then rewrite it on your own (recommended for your own good). Or you can copy paste it into your compiler. Copying and pasting into any modern C++ compiler is not a big deal. But if you are using 'Turbo c++' and dont know how to copy text to the turbo C++ compiler, http://howtomonetizeeverything.blogspot.com /2013/05/how-to-copy-any-text-to-turbo-c_16.html">Click here.

    Here's the code :




    #include<iostream.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<time.h>
    #include<dos.h>
    #include<stdio.h>
    #include<string.h>
    void main()
    {
    srand(time(NULL));
    clrscr();
    int i,j,k;
    cout << " ";
    char str[] = {"WELCOME TO BLACK JACK!!"};
    int ben = strlen(str);
    for(i=0;i<ben;i++)
    {
    putchar(str[i]);
    delay(90);
    }
    delay(1000);
    clrscr();
    cout <<" " << endl;
    delay(90);
    cout <<" --------- --------- --------- --------- " << endl;
    delay(490);
    cout <<"|A | |K | |Q | |J | "<< endl;
    delay(490);
    cout <<"| | | | | | | | "<<endl;
    delay(490);
    cout <<"| | | | | | | | "<<endl;
    delay(490);
    cout <<"| | | | | | | | "<<endl;
    delay(490);
    cout <<"| A| | K| | Q| | J| "<<endl;
    delay(490);
    cout <<" --------- --------- --------- --------- "<<endl;
    delay(1000);
    clrscr();
    a:
    cout << " MENU : " << endl;
    cout << " <1> PLAY" << endl << " <2> EXIT" << endl ;
    cin >> i;
    switch(i)
    {
    case 1 :
    {
    clrscr();
    cout << endl << "press 1 and enter to start" ;
    cin >> j;
    {
    if(j==1)
    clrscr();
    int pt;
    pt= rand() %10;
    cout <<"your hand: "<< pt << endl;
    do
    {
    cout << "press 1 to hit or 2 to stand"<<endl;
    int ch;
    cin >> ch;
    if(ch==1)
    pt = pt + rand()%10;
    cout << "your hand: " << pt<<endl;
    if(ch==2)
    {cout << endl;
    cout << " now its the dealer's turn"<< endl;
    int deal;
    deal = random(12)+10;
    cout << "dealer : " << deal << " you : " << pt<< endl;
    {if(pt == 21)
    cout << "YOU WIN!!!!!";}
    if(pt> deal)
    cout << "you WIN!!"<<endl;
    if(pt < deal && deal <=21)
    cout << " sorry you loose!"<<endl;
    if(pt==deal)
    cout <<" its a push!!" << endl;
    if(deal > 21)
    cout << " YOU WIN!! "<<endl ;
    break;}
    if(pt>21)
    cout <<"busted!!!!"<<endl;
    }while(pt<21);
    cout << "Do you want to play again??<y-1/n-2>"<<endl ;
    int g;
    b:
    cin >> g;
    if(g == 2)
    exit(0);
    if(g == 1)
    goto a;
    else
    cout << " you can enter only 1 or 2";
    goto b; }
    }
    break;
    case 2 : exit(0);
    break;
    default :{
    cout << "you can enter only '1' or '2'"<< endl;
    goto a;}
    }
    getch();
    }
    view raw gistfile1.cpp hosted with ❤ by GitHub



    If you are using a compiler other than Turbo C++, you will have to remove all the "delay();" functions, and the header file. The http://howtomonetizeeverything.blogspot.com /2013/05/using-delay-function-in-c.html">delay function can be used only in Turbo C++. It is used to create a time delay in the out put of the program. To know more about the delay function, http://howtomonetizeeverything.blogspot.com /2013/05/using-delay-function-in-c.html"> http://howtomonetizeeverything.blogspot.com /2013/05/using-delay-function-in-c.html">Click here.

    If you face any problem in implementing the code, dont hesitate to ask in the comment section or in the 'contact us' tab. Although there shouldn't be any problem.

    Once you paste the code in your compiler, can straight away run it. If you want to download the already compiled, executable version of the game, Click here.



    Information HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack has been completed we present

    A few of our information about the HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack, we hope you benefit from this article

    You have just read the article HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack and many articles about gadget in our blog this, please read it. and url link of this article is https://howtomonetizeeverything.blogspot.com/2013/05/how-to-make-console-game-in-c-blackjack.html Hopefully discussion articles on provide more knowledge about the world of tech gadgets.

    Tag :

    Related Posts :

    0 Response to "HOW TO MAKE A CONSOLE GAME IN C++ : Blackjack"

    Post a Comment