// --------------------------------------------------------- bool GoCommand::execute() { Direction dir; cin >> dir; if ( myAdventurer->getStrength() < myAdventurer->getInventory()->getWeight() ) cout << "I am too burdened to move.\n\n"; else { if ( !myMap->getDirections().isValid( dir ) ) cout << dir << " is not a direction!\n\n"; else { Feature *next = myAdventurer->getCurrentFeature()->getExit( dir ); if ( !next ) cout << "I can't go that way.\n"; else { if ( myAdventurer->getCurrentFeature()->isClosed() && myAdventurer->getPreviousDirection() == dir ) cout << "The door is closed.\n"; else { myAdventurer->setCurrentFeature( next ); myAdventurer->setPreviousDirection( dir ); cout << "I am now in "; next->printName( cout ); cout << ".\n"; } } myAdventurer->move(); } } return true; }
// --------------------------------------------------------- bool InCommand::execute() { if ( myAdventurer->getStrength() < myAdventurer->getInventory()->getWeight() ) cout << "I am too burdened to move.\n\n"; else { Direction dir = myAdventurer->getPreviousDirection(); Feature * next; next = myAdventurer->getCurrentFeature()->getExit( dir ); if ( !next ) { cout << "I can't go that way.\n"; } else { if ( myAdventurer->getCurrentFeature()->isClosed() ) { cout << "The door is closed.\n"; } else { myAdventurer->setCurrentFeature( next ); myAdventurer->setPreviousDirection( dir ); cout << "I am now in "; next->printName( cout ); cout << ".\n"; } } myAdventurer->move(); } return true; }