/* Reacts to an action event in the window. */ static void processActionEvent(State& state, GActionEvent e) { string cmd = e.getActionCommand(); /* Need to make a new world? Deselect everything and return to the fresh * state. */ if (cmd == kNewWorldLabel) { /* This might fail, in which case we do nothing. */ if (regenerateWorld(state.world, state.worldType)) { drawWorld(state.world); state.uiState = FRESH; } } /* Want to load a new world? Try to do so and update the UI accordingly. */ else if (cmd == kLoadWorldLabel) { if (tryLoadWorld(state.world, state.worldType)) { drawWorld(state.world); state.uiState = FRESH; } } /* Rerunning the search is only possible if we already did a search. */ else if (cmd == kRerunLabel) { if (state.uiState == DRAWN) { uncolorSquares(); removeOverlays(); runSearch(state); } else { cout << "Cannot rerun a search; no search has been done." << endl; } } /* Clearing the display just sets us back to the fresh state. */ else if (cmd == kClearLabel) { restoreWorldDisplay(); state.uiState = FRESH; } /* Trying to quit exits the entire program. */ else if (cmd == kQuitLabel) { exitGraphics(); } }
/* * (public function) * Reacts to an action event in the window. */ void processActionEvent(GActionEvent e) { string cmd = e.getActionCommand(); if (cmd == "Load") { // Want to load a new world? Try to do so and update the UI accordingly. if (regenerateWorld(state.world, state.worldType)) { drawWorld(state.world); state.uiState = FRESH; } } else if (cmd == "Run") { // Rerunning the search is only possible if we already did a search. if (state.uiState == DRAWN) { uncolorSquares(); removeOverlays(); runSearch(state); } else { cout << "Cannot rerun a search; no search has been done." << endl; } } else if (cmd == "Clear") { // Clearing the display just sets us back to the fresh state. restoreWorldDisplay(); state.uiState = FRESH; } else if (cmd == "Exit") { } }