Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. void main_menu()
  2. {
  3.  
  4.  
  5.     int option = 0;
  6.  
  7.     while((option !=1)&&(option !=2))
  8.     {
  9.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
  10.         centerText("Welcome to OLD MAID!");
  11.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
  12.         centerText("--------------------");
  13.         cout << endl;
  14.         centerText("Please choose an option: ");
  15.         centerText("1) Start game");
  16.         centerText("2) Read rules");
  17.  
  18.         gotoxy(40,10);
  19.         cin >> option;
  20.  
  21.         if((option !=1)&&(option !=2))
  22.         {
  23.             system("cls");
  24.             centerText("Invalid choice. Please pick again.");
  25.             cout << endl;
  26.            
  27.         }
  28.  
  29.         if(option == 2)
  30.         {
  31.             system("cls");
  32.             display_rules();
  33.  
  34.         }
  35.  
  36.         if(option == 1)
  37.         {
  38.             system("cls");
  39.         }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.     }
  46.  
  47.  
  48.  
  49.  
  50. }
  51. void centerText(char* s)
  52. {
  53.      int l=strlen(s);
  54.      int pos=(int)((120-l)/2);
  55.      for(int i=0;i<pos;i++)
  56.         cout <<" ";
  57.      cout<<s<<endl;
  58.      
  59. }
  60. void display_rules()
  61. {       SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  62.         cout << setiosflags(ios::left) << setw(15) << "THE OBJECTIVE: ";
  63.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
  64.         cout << "\t" << "To form and discard pairs, avoiding being the player holding" << endl;
  65.         cout << "\t\t" << "the Old Maid"
  66.         << " at the end of the game." << endl << endl;
  67.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  68.         cout << "THE SET-UP: ";
  69.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
  70.         cout << "\t" << "Three queens are removed from the deck." << endl;
  71.         cout << "\t\t" << "The remaining queen is the old maid." << endl;
  72.         cout << endl << endl;
  73.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  74.         cout << "THE PLAY: ";
  75.         SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
  76.         cout << "\t" << "Players remove pairs of cards from their hands.";
  77.         cout << " The dealer then " << endl;
  78.         cout << "\t\t" << "offers his hand,"
  79.         << "face down, to the player on his left." << endl;
  80.         cout << "\t\t" << "That player randomly takes one card from the dealer." << endl;
  81.         cout << "\t\t" << "If the card matches one he already has in his hand, he puts " << endl;
  82.         cout << "\t\t" <<   "the pair down. If not, he keeps it.  Play proceeds clockwise, " << endl;
  83.         cout << "\t\t" << "so the player to the left of the dealer then offers his hand," << endl;
  84.         cout << "\t\t" << "face down, to the player on his left. This cycle repeats until" << endl;
  85.         cout << "\t\t" << "there are no more pairs " << "and the only remaining card " << endl;
  86.         cout << "\t\t" << "is the Old Maid." << endl;
  87.         cout << endl;
  88.         system("pause");
  89.         cout << endl;
  90.         system("cls");
  91.         main_menu();
  92. }
  93.  
  94. void Deck::sort(vector<Card> hand)
  95. {
  96.     for(int i(0); i < hand.size(); i++)
  97.     {
  98.         for(int j(i); j < hand.size(); j++)
  99.         {
  100.             if(hand[i].get_suit() > hand[j].get_suit())
  101.             {
  102.                 swap(hand[i],hand[j]);
  103.             }
  104.         }
  105.     }
  106. }
  107. void Deck::card_nums(Deck deck)
  108. {
  109.  
  110.     vector<int> possible_choices;
  111.     //adding the numbers at the bottom and then making them a choice
  112.     gotoxy(0,12);
  113.     for(int i=0;i<deck.comp_hand.size();i++)
  114.     {
  115.         if(i<9)
  116.         {
  117.             cout << "  " << i+1 << " ";
  118.         }
  119.         else
  120.         {
  121.             cout << " " << i+1 << " ";
  122.         }
  123.         possible_choices.push_back(i+1);
  124.  
  125.     }
  126.  
  127.     gotoxy(50,25);
  128.     cout << "Please pick a number." << endl;
  129.     int pick;
  130.     gotoxy(50,35);
  131.     cin >> pick;
  132.    
  133.     while((pick>possible_choices.size()) || (pick<=0))
  134.     {
  135.         gotoxy(50,20);
  136.         cout << "Invalid choice. " << endl;
  137.         gotoxy(50,25);
  138.         cout << "Your turn! Please pick a number." << endl;
  139.         gotoxy(45,35);
  140.         cout << "       ";
  141.         gotoxy(50,35);
  142.         cin >> pick;
  143.     }
  144.  
  145.     gotoxy(50,20);
  146.     cout << "                " << endl;
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement