Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. void print(vector <int> playerhand){
  2.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  3.     SetConsoleTextAttribute(hConsole, 15);
  4.    
  5.     char suits[4] = {3, 4, 5, 6};           //all the possible suits in order(3 = heart, 4 = diamond, 5 = clover, 6 = spade)
  6.     string ranks[13] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};  //all possible ranks
  7.    
  8.     cout<<"\nPlayer's hand: \n";            //declares that the computer is printing the player's hand
  9.     for(int j = 0; j < 10; j++){            //repeats for a length of 10(length of card is 10 for this program)
  10.         for(int i = 0; i < playerhand.size(); i++){     //repeats for how many cards are in the hand
  11.             if(j == 0 || j == 9){       //if it is the first or last line of the card
  12.                 cout<<"----------";         //outputs a line
  13.             }
  14.            
  15.             else if(j == 1){                    //the second line has the rank on the left hand side
  16.                 cout<<"|"<< ranks[playerhand[i] % 13];
  17.                
  18.                 if(playerhand[i] % 13 == 9)     //if the number is 10(only one that takes 2 spaces)
  19.                     cout<<"      |";        //then it takes a space away to equilize it
  20.                 else
  21.                     cout<<"       |";       //else all others take only 1 space
  22.             }
  23.            
  24.             else if(j == 8){            //second to last line has the rank on the right hand side
  25.                 if(playerhand[i] % 13 == 9)
  26.                     cout<<"|      ";        //if the rank takes 2 spaces(10) then it puts 1 less space
  27.                 else
  28.                     cout<<"|       ";//else all others take 1 space
  29.                
  30.                 cout<<ranks[playerhand[i] % 13]<<"|";       //prints rank and ends card
  31.             }
  32.            
  33.             else if(j == 4){                        //if the line is in the middle, then there is a suit there
  34.                 cout<<"|   ";                   //prints the side bar and spaces
  35.                 if(suits[playerhand[i] / 13] == char(3) || suits[playerhand[i] / 13] == char(4)){   //if the icon is a heart or diamond,   
  36.                     SetConsoleTextAttribute(hConsole, 12);          //sets print color to red
  37.                     cout<<suits[playerhand[i] / 13];                //prints the suit
  38.                 }
  39.                 else{                                       //else the only ones left are spade and clover
  40.                     SetConsoleTextAttribute(hConsole, 8);           //sets print color to gray
  41.                     cout<<suits[playerhand[i] / 13];                //prints the suit
  42.                 }
  43.                
  44.                 SetConsoleTextAttribute(hConsole, 15);          //sets print color back to white
  45.                 cout<<"    |";                              //ends the card
  46.             }
  47.            
  48.             else
  49.                 cout<<"|        |";             //else there there is nothing special on that line and prints a blank
  50.  
  51.             cout<<"     ";              //prints the space in between cards
  52.         }
  53.         cout<<"\n";                 //goes to next line
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement