Advertisement
Guest User

TextSweeper.cpp

a guest
Jul 2nd, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cstdlib>
  5. #include "SweeperBoard.h"
  6. using namespace std;
  7.  
  8. void PrintHelp()
  9. {
  10.     cout << "HELP:\nTry and rid of the mines!\n\tLEGEND:\n\t\t\'" << char(-80) << "\' = Unknown\n\t\t\'" << char(16) <<"\' = Flagged mine\n\t\t\'" << char(-6) << "\' = No mines in the 8 squares around\n"
  11.         "\t\t\'3\' = <number> of mines in the 8 squares around\n "
  12.         "\tCOMMANDS:\n\t\t(p)op - reveals the number of mines (or mine) around\n\t\t    that point, filling up the squares with zero.\n"
  13.         "\t\t(f)lag - flags the specified point as a mine.\n"
  14.         "\t\t(u)nflag - unflags the specified point as a mine.\n\t\t(e)xit - Exits the game\n";
  15. }
  16.  
  17. int main()
  18. {
  19.     // Title, asking for some parameters
  20.     cout << "                                _____________" << endl;
  21.     cout << "                             " << char(-81) << "> TEXT-SWEEPER" << char(-87) << " <" << char(-82) << endl;
  22.     cout << "                                ^^^^^^^^^^^^^" << endl << endl;
  23.     cout << "                  This waste of time brought to you by Seb.H" << endl << endl;
  24.     cout << "Size (on x and y) must be 26 or lower - unless you want to enter the undefined!" << endl;
  25.     cout << "What sized grid would you like (<width> <height>)?  ";
  26.     int widthGrid, heightGrid;
  27.     cin >> widthGrid >> heightGrid;
  28.  
  29.     cout << "What percentage of the " << widthGrid*heightGrid << " squares will be mines? (0-100) ";
  30.     int minesPercent;
  31.     cin >> minesPercent;
  32.  
  33.     //Construct the board from the parameters
  34.     SweeperBoard sb(widthGrid, heightGrid, minesPercent);
  35.     sb.PrintBoard();
  36.     string command;
  37.     char x, y; //temporaries, for passing to functions
  38.     while(1) {
  39.         cout << "Type in your command (type a \'?\' for help): ";
  40.         cin >> command;
  41.         //Bunch of commands
  42.         if( command == "?" ) PrintHelp();
  43.  
  44.         if( command[0] == 'p' || command[0] == 'P' ) {
  45.             cout << "Pop where <x> <y>?";
  46.             cin >> y >> x; // The coordinates are backwards - I don't really know why
  47.             if(!sb.Pop(x-65, y-65)) //Subtract 65 - because they are characters
  48.                 cout << "Invalid or out of range / Did you use caps? / You can't pop flags!" << endl;
  49.             else {
  50.                 system("cls");
  51.                 sb.PrintBoard();
  52.             }
  53.         }
  54.  
  55.         if( command[0] == 'f' || command[0] == 'F' ) {
  56.             cout << "Flag where <x> <y>?";
  57.             cin >> y >> x;
  58.             if(!sb.Flag(x-65, y-65))
  59.                 cout << "Invalid or out of range" << endl;
  60.             else {
  61.                 system("cls");
  62.                 sb.PrintBoard();
  63.             }
  64.         }
  65.  
  66.         if( command[0] == 'u' || command[0] == 'U' ) {
  67.             cout << "Unflag where <x> <y>?";
  68.             cin >> y >> x;
  69.             if(!sb.Unflag(x-65, y-65))
  70.                 cout << "Invalid or out of range / There's no flag there to unflag!" << endl;
  71.             else {
  72.                 system("cls");
  73.                 sb.PrintBoard();
  74.             }
  75.         }
  76.  
  77.         if( sb.gameLost ) break;
  78.         if( sb.gameWon ) break;
  79.  
  80.         if( command[0] == 'e' || command[0] == 'E' ) return 0;
  81.  
  82.         cout << endl;
  83.     }
  84.     if(sb.gameLost) {
  85.         system("cls");
  86.         cout << "\tKASPLAT!" << endl;
  87.         sb.PrintBoard();
  88.         cout << "\tYou seem to have lost." << endl;
  89.     } else {
  90.         system("cls");
  91.         cout << "\tIt seems..." << endl;
  92.         sb.PrintBoard();
  93.         cout << "\tThat you have won." << endl;
  94.     }
  95.     system("pause");
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement