1. Rhys !
  2. zorkish

Source

zorkish / commands / GoCommand.hpp

/*
 * GoCommand.hpp
 *
 *  Created on: 10/09/2012
 *      Author: rhys
 */

#ifndef GOCOMMAND_HPP_
#define GOCOMMAND_HPP_

#include "../Command.hpp"

class GoCommand : public Command {
public:
    virtual ~GoCommand() = default;

    virtual std::string run(std::string params, World& world, Player& player) {
        if (params.empty()) {
            return "You must specify a direction.";
        }

        auto it = player.current_location()->exits.find(params);
        if (it != player.current_location()->exits.end()) {
            auto* new_loc = world.get_location((*it).second);
            player.move(new_loc);
            return new_loc->long_desc();
        } else {
            return "You can't go " + params + " from here.";
        }
    }
};


#endif /* GOCOMMAND_HPP_ */