Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Commands::Commands()
- {
- }
- Commands::~Commands()
- {
- }
- void Commands::addCommands(std::vector<std::regex>& regex)
- {
- regex.emplace_back(std::regex("look", std::regex::icase));
- regex.emplace_back(std::regex("north", std::regex::icase));
- regex.emplace_back(std::regex("east", std::regex::icase));
- regex.emplace_back(std::regex("south", std::regex::icase));
- regex.emplace_back(std::regex("west", std::regex::icase));
- }
- void Commands::processCommands(std::string& commStr, std::vector<std::regex>& regex, Player& player, Area area)
- {
- std::smatch match;
- for (int i = 0; i < regex.size(); i++)
- {
- std::regex_match (commStr, match, regex[i]);
- }
- if (match.empty())
- {
- std::cout << "No matches found." << std::endl;
- }
- else
- {
- std::cout << "Found match(es)" << std::endl;
- }
- if (match.str() == "look")
- {
- player.look(player.playerX, player.playerY, area.room);
- }
- else if (match.str() == "north")
- {
- player.playerY -= 1;
- std::cout << player.playerY << std::endl;
- }
- else if (match.str() == "east")
- {
- player.playerX += 1;
- std::cout << player.playerX << std::endl;
- }
- else if (match.str() == "south")
- {
- player.playerY += 1;
- std::cout << player.playerY << std::endl;
- }
- else if (match.str() == "west")
- {
- player.playerX -= 1;
- std::cout << player.playerX << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement