void Game::doUse() { if (object != verb) { if ((object.compare("terminal") || object.compare("keyboard")) && current_room == 6) { enterCode(); return; } Item toUse = player->getItem(object); if (toUse.first != "NOITEM") { if (checkAction(toUse, USE)) { cout << "What to do you want to use the " << object << " with?" << endl; cout << ">"; getline(cin, object); Item result = room_list[current_room]->getItem(object); if (checkAction(result, USE)) { room_list[current_room]->changeState(toUse.first); } else cout << "You can't use the " << toUse.first << " with the " << object << endl; } else cout << "You can't use that. " << endl; } else cout << "You don't have a " << object << endl; } else { cout << "What do you want to use?" << endl; cout << ">"; getline(cin, object); doUse(); } }
/* Main program (obviously) */ int main(void) { while (1) { initialize(); clearScreen(); printf("%s", introText); while (!gameOver) { prompt(); if (buffer[0] == '\0') { } else if (tolower(buffer[0]) == 'h') { doHelp(); } else if (tolower(buffer[0]) == 'i') { doInventory(); } else if ((tolower(buffer[0]) == 'g') || !strcasecmp(buffer, "n") || !strcasecmp(buffer, "s") || !strcasecmp(buffer, "e") || !strcasecmp(buffer, "w") || !strcasecmp(buffer, "u") || !strcasecmp(buffer, "d") || !strcasecmp(buffer, "north") || !strcasecmp(buffer, "south") || !strcasecmp(buffer, "east") || !strcasecmp(buffer, "west") || !strcasecmp(buffer, "up") || !strcasecmp(buffer, "down")) { doGo(); } else if (tolower(buffer[0]) == 'l') { doLook(); } else if (tolower(buffer[0]) == 't') { doTake(); } else if (tolower(buffer[0]) == 'e') { doExamine(); } else if (tolower(buffer[0]) == 'u') { doUse(); } else if (tolower(buffer[0]) == 'd') { doDrop(); } else if (tolower(buffer[0]) == 'q') { doQuit(); } else if (!strcasecmp(buffer, "xyzzy")) { printf("Nice try, but that won't work here.\n"); } else { printf("I don't understand. Try 'help'.\n"); } /* Handle special actions. */ doActions(); } printf("Game over after %d turns.\n", turnsPlayed); printf("%s", "Do you want to play again (y/n)? "); fgets(buffer, sizeof(buffer)-1, stdin); if (tolower(buffer[0]) == 'n') { break; } } return 0; }
void Game::doAction(const Actions action) { switch (action) { case GO: doGo(); break; case QUIT: doQuit(); break; case PICK: doPick(); break; case DROP: doDrop(); break; case READ: doRead(); break; case BREAK: doBreak(); break; case SEE: doSee(); break; case OPEN: doOpen(); break; case FILL: doFill(); break; case USE: doUse(); break; case PUT: doPut(); break; case NOACTION: doNothing(); break; default: doNothing(); } }