Advertisement
Danicron

Commands.cpp

May 20th, 2019
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. Commands::Commands()
  2. {
  3. }
  4.  
  5.  
  6. Commands::~Commands()
  7. {
  8. }
  9.  
  10. void Commands::addCommands(std::vector<std::regex>& regex)
  11. {
  12.     regex.emplace_back(std::regex("look", std::regex::icase));
  13.     regex.emplace_back(std::regex("north", std::regex::icase));
  14.     regex.emplace_back(std::regex("east", std::regex::icase));
  15.     regex.emplace_back(std::regex("south", std::regex::icase));
  16.     regex.emplace_back(std::regex("west", std::regex::icase));
  17.  
  18. }
  19.  
  20.  
  21. void Commands::processCommands(std::string& commStr, std::vector<std::regex>& regex, Player& player, Area area)
  22. {
  23.     std::smatch match;
  24.     for (int i = 0; i < regex.size(); i++)
  25.     {
  26.         std::regex_match (commStr, match, regex[i]);
  27.     }
  28.  
  29.     if (match.empty())
  30.     {
  31.         std::cout << "No matches found." << std::endl;
  32.     }
  33.     else
  34.     {
  35.         std::cout << "Found match(es)" << std::endl;
  36.     }
  37.  
  38.    
  39.    
  40.     if (match.str() == "look")
  41.     {
  42.         player.look(player.playerX, player.playerY, area.room);
  43.     }
  44.     else if (match.str() == "north")
  45.     {
  46.         player.playerY -= 1;
  47.         std::cout << player.playerY << std::endl;
  48.     }
  49.     else if (match.str() == "east")
  50.     {
  51.         player.playerX += 1;
  52.         std::cout << player.playerX << std::endl;
  53.     }
  54.     else if (match.str() == "south")
  55.     {
  56.         player.playerY += 1;
  57.         std::cout << player.playerY << std::endl;
  58.     }
  59.     else if (match.str() == "west")
  60.     {
  61.         player.playerX -= 1;
  62.         std::cout << player.playerX << std::endl;
  63.     }
  64.  
  65.  
  66.    
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement