Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Game.h"
- bool Game::file_exists(string filename)
- {
- if (ifstream(filename))
- {
- return true;
- }
- return false;
- }
- //================================================================
- //===========================PUBLIC===============================
- //================================================================
- Game::Game(Dictionary dictionary, Board board) {
- this->dictionary = dictionary;
- this->board = board;
- }
- //Shows the initial options given to the user
- void Game::main_menu(string dictionary_file) {
- unsigned int option;
- cout << "CROSSWORDS PUZZLE CREATOR" << endl;
- cout << "==============================================\n" << endl;
- cout << "INSTRUCTIONS:" << endl;
- cout << "CTRL-Z = back" << endl;
- cout << "----------------------------------------------\n" << endl;
- cout << "OPTIONS:" << endl;
- cout << "1 - Create Puzzle" << endl;
- cout << "2 - Resume Puzzle" << endl;
- cout << "0 - Exit" << endl << endl;
- cout << "Option: ";
- cin >> option;
- while (option != 0)
- {
- while (
- cin.fail()
- || (option < 0)
- || (option > 2)
- )
- {
- cout << "Please insert a number from the options available" << endl;
- cout << "1 - Create Puzzle" << endl;
- cout << "2 - Resume Puzzle" << endl;
- cout << "0 - Exit" << endl << endl;
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Option: ";
- cin >> option;
- }
- switch (option)
- {
- case 1:
- {
- dictionary.loadDictionary(dictionary_file);
- if (board.board())
- {
- board.show_board();
- advanced_menu();
- board.storeBoard(dictionary_file, false, "irrelevant parameter");
- }
- }
- break;
- case 2:
- {
- string board_file_name = board.loadBoard();
- dictionary.loadDictionary(dictionary_file);
- board.show_board();
- advanced_menu();
- board.storeBoard(dictionary_file, true, board_file_name);
- }
- break;
- case 0:
- cout << "Shuting down..." << endl;
- }
- if (option != 0) {
- cin.clear();
- cout << endl << "OPTIONS:" << endl;
- cout << "1 - Create Puzzle" << endl;
- cout << "2 - Resume Puzzle" << endl;
- cout << "0 - Exit" << endl << endl;
- cout << "Option: ";
- cin >> option;
- }
- }
- }
- //================================================================
- //The menu with the options that affect the board directly(insert/remove word)
- void Game::advanced_menu() {
- char command;
- cout << "COMMANDS:" << endl;
- cout << "+ = place word in board" << endl;
- cout << "- = remove word from board" << endl;
- cout << "b = back to main menu" << endl << endl;
- cout << "Command: ";
- cin >> command;
- while (command != 'b')
- {
- while (cin.fail()
- || ((command != '+')
- && (command != '-')
- && (command != 'b'))
- )
- {
- cout << endl << "Invalid command input" << endl;
- cout << "PLease insert one of the available commands" << endl << endl;
- cout << "COMMANDS:" << endl;
- cout << "+ = place word in board" << endl;
- cout << "- = remove word from board" << endl;
- cout << "b = back to main menu" << endl << endl;
- cout << "Command: ";
- cin.clear();
- cin.ignore(1000, '\n');
- cin >> command;
- }
- switch (command)
- {
- case '+':
- board.insert_word(dictionary);
- break;
- case '-':
- board.remove_word();
- break;
- }
- cin.clear();
- cout << endl << "COMMANDS:" << endl;
- cout << "+ = place word in board" << endl;
- cout << "- = remove word from board" << endl;
- cout << "b = back to main menu" << endl << endl;
- cout << "Command: ";
- cin >> command;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement