Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cstdlib>
- #include "SweeperBoard.h"
- using namespace std;
- void PrintHelp()
- {
- 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"
- "\t\t\'3\' = <number> of mines in the 8 squares around\n "
- "\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"
- "\t\t(f)lag - flags the specified point as a mine.\n"
- "\t\t(u)nflag - unflags the specified point as a mine.\n\t\t(e)xit - Exits the game\n";
- }
- int main()
- {
- // Title, asking for some parameters
- cout << " _____________" << endl;
- cout << " " << char(-81) << "> TEXT-SWEEPER" << char(-87) << " <" << char(-82) << endl;
- cout << " ^^^^^^^^^^^^^" << endl << endl;
- cout << " This waste of time brought to you by Seb.H" << endl << endl;
- cout << "Size (on x and y) must be 26 or lower - unless you want to enter the undefined!" << endl;
- cout << "What sized grid would you like (<width> <height>)? ";
- int widthGrid, heightGrid;
- cin >> widthGrid >> heightGrid;
- cout << "What percentage of the " << widthGrid*heightGrid << " squares will be mines? (0-100) ";
- int minesPercent;
- cin >> minesPercent;
- //Construct the board from the parameters
- SweeperBoard sb(widthGrid, heightGrid, minesPercent);
- sb.PrintBoard();
- string command;
- char x, y; //temporaries, for passing to functions
- while(1) {
- cout << "Type in your command (type a \'?\' for help): ";
- cin >> command;
- //Bunch of commands
- if( command == "?" ) PrintHelp();
- if( command[0] == 'p' || command[0] == 'P' ) {
- cout << "Pop where <x> <y>?";
- cin >> y >> x; // The coordinates are backwards - I don't really know why
- if(!sb.Pop(x-65, y-65)) //Subtract 65 - because they are characters
- cout << "Invalid or out of range / Did you use caps? / You can't pop flags!" << endl;
- else {
- system("cls");
- sb.PrintBoard();
- }
- }
- if( command[0] == 'f' || command[0] == 'F' ) {
- cout << "Flag where <x> <y>?";
- cin >> y >> x;
- if(!sb.Flag(x-65, y-65))
- cout << "Invalid or out of range" << endl;
- else {
- system("cls");
- sb.PrintBoard();
- }
- }
- if( command[0] == 'u' || command[0] == 'U' ) {
- cout << "Unflag where <x> <y>?";
- cin >> y >> x;
- if(!sb.Unflag(x-65, y-65))
- cout << "Invalid or out of range / There's no flag there to unflag!" << endl;
- else {
- system("cls");
- sb.PrintBoard();
- }
- }
- if( sb.gameLost ) break;
- if( sb.gameWon ) break;
- if( command[0] == 'e' || command[0] == 'E' ) return 0;
- cout << endl;
- }
- if(sb.gameLost) {
- system("cls");
- cout << "\tKASPLAT!" << endl;
- sb.PrintBoard();
- cout << "\tYou seem to have lost." << endl;
- } else {
- system("cls");
- cout << "\tIt seems..." << endl;
- sb.PrintBoard();
- cout << "\tThat you have won." << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement