void MenuSystem::displayMenu(){ if (_curMenu == 0){ if(_curSubMenu < _numMenuTitles){ printTopMenu(getMenuTitle(_curMenu), _screenWidth); printSubMenu(getMenuTitle(_curSubMenu), _screenWidth - 4); } }else{ printTopMenu(getMenuTitle(_curMenu), _screenWidth); if(getMenuOption(_curSubMenu, _curOption)){ printSubMenu(getActionTitle(getMenuOption(_curSubMenu,_curOption) - 1), _screenWidth - 4); } } }
void MenuSystem::selectSubMenu(){ _curMenu = _curSubMenu; _curOption = getMenuOption(_curMenu,1); Serial.print("Current Menu : "); Serial.println(_curMenu); Serial.print("Current option : "); Serial.println(_curOption); displayMenu(); }
void Menu::drawMenuOptionHilite(int hMenu, int vMenu) { AgiMenu *m = getMenu(hMenu); AgiMenuOption *d = getMenuOption(hMenu, vMenu); // Disabled menu items are "greyed out" with a checkerboard effect, // rather than having a different color. -- dsymonds _vm->printText(d->text, 0, m->wincol + 1, vMenu + 2, m->width + 2, MENU_BG, MENU_FG, !d->enabled); }
//------------------------------------------------------------------------------ // startMenu //------------------------------------------------------------------------------ // Uppgift: Visar upp startmenyn. // Indata : (void) // Utdata : (void) //------------------------------------------------------------------------------ void TestApp::startMenu() { int choice = 0; int maxSize = sizeof(startMenuitems) / sizeof(startMenuitems[0]); do { system("cls"); cout << " \n /**** HANOI GAME ****/\n\n 1. Start newgame\n 2. Replay\n 0. Exit " << endl; choice = getMenuOption(0, maxSize-1); doMenuChoice(startMenuitems[choice]); } while (startMenuitems[choice] != menu::EXIT); }
//------------------------------------------------------------------------------ // gamePlayMenu //------------------------------------------------------------------------------ // Uppgift: Visar upp gameplay menyn. // Indata : (void) // Utdata : (void) //------------------------------------------------------------------------------ void TestApp::gamePlayMenu() { int choice = 0; int maxSize = sizeof(gamePlayMenuItems) / sizeof(gamePlayMenuItems[0]); do { system("cls"); m_commandMgr->doCommand(new ShowCommand(m_hannoiEngine)); cout << endl << endl << " 1. Move\n 2. Undo\n 3. Redo\n 4. Reset\n 0. Exit " << endl; choice = getMenuOption(0, maxSize - 1); doMenuChoice(gamePlayMenuItems[choice]); } while (gamePlayMenuItems[choice] != menu::EXIT); }
int main() { int keepLooping = TRUE; char text[MAX_INPUT_CHARS + 1]; // +1 for \0 character text[0] = '\0'; // print menu printf("1. Input Text\n2. Text Stats\n3. Find Substring\n4. Reverse Text\n5. Quit\n\n\n\n"); // infinite loop to accept user input while (keepLooping) { // get user option printf("===============Input Option:"); int option; if (isValidOption(option = getMenuOption())) { switch (option) { case 1: { int keepPrompting = TRUE; while (keepPrompting) { char c; int i = 0; keepPrompting = FALSE; while ((c = getchar()) != '\n') { text[i++] = c; if (i > MAX_INPUT_CHARS) { printf("Text no more than 1000 characters. Please enter again.\n"); clearInputBuffer(); keepPrompting = TRUE; break; } } if (!keepPrompting) if (text[i-1] == '\n') text[i-1] = '\0'; else text[i] = '\0'; } printf("\n\n\n"); break; } case 2: { // Text Stats int i, inWord = FALSE, wordCount = 0, sentenceCount = 0; // index is ascii char; index value is frequency int freqChars[NUM_ASCII_CHARS]; // initialize freqChars to 0's for (i = 0; i < NUM_ASCII_CHARS; i++) freqChars[i] = 0; // loop over each character in input for (i = 0; i < strlen(text); i++) { // check if word if (isalpha(text[i]) && !inWord) { inWord = TRUE; wordCount++; } else if (!isalpha(text[i]) && inWord) { inWord = FALSE; } // check for sentence if (i < strlen(text) && (text[i] == '.' || text[i] == '!' || text[i] == '?') && (text[i+1] == ' ' || text[i+1] == '\0' || text[i+1] == '\'' || text[i+1] == '"')) sentenceCount++; // increment character's frequency freqChars[text[i]]++; } printf("Character Number: %d\nWord Number: %d\nSentence Number: %d\nMost Frequent Characters:\n", strlen(text), wordCount, sentenceCount); int counter = 0, largest = 0; do { largest = 0; // find largest for (i = 0; i < NUM_ASCII_CHARS; i++) { if (freqChars[i] > largest) largest = freqChars[i]; } if (largest != 0) { // find and print ties for (i = 0; i < NUM_ASCII_CHARS; i++) { if (freqChars[i] == largest) { // print value. e.g. 'c':4 printf("'%c':%d\n", i, freqChars[i]); // delete largest values for next iteration freqChars[i] = 0; } } } else break; } while (++counter < 3); printf("\n\n\n"); break; } case 3: { // Find Substring printf("Please Input Substring\n"); char substring[MAX_INPUT_CHARS+1], c; int i = 0; while ((c = getchar()) != '\n') { substring[i++] = c; if (i > MAX_INPUT_CHARS) { printf("Text no more than 1000 characters. Substring not found.\n"); clearInputBuffer(); break; } } if (substring[i-1] == '\n') substring[i-1] = '\0'; else substring[i] = '\0'; if (substring[0] != '\0') { char *pos = text; int counter = 0; // cut off the portion we have already visited by advancing the pos pointer while ((pos = strstr(pos, substring)) > 0) { counter++; pos++; } printf("found %d occurrence(s)\n", counter); } printf("\n\n\n"); break; } case 4: { // Reverse Text printf("Reversed Text:\n"); // reverse whole string character by character int i, textLength = strlen(text); for (i = 0; i < textLength-i-1; i++) { char temp = text[i]; text[i] = text[textLength-1-i]; text[textLength-1-i] = temp; } // reverse characters in each word int inWord = FALSE, j, k; for (i = 0; i < textLength; i++) { if (text[i] != '\t' && text[i] != ' ' && !inWord) { inWord = TRUE; int wordLength = 0; // find word length for (j = i; text[j] != '\t' && text[j] != ' ' && text[j] != '\0'; j++, wordLength++); // reverse word for (k = 0; k < wordLength-k-1; k++) { char temp = text[k+i]; text[k+i] = text[wordLength+i-k-1]; text[wordLength+i-k-1] = temp; } } else if (!(text[i] != '\t' && text[i] != ' ')) { inWord = FALSE; } else { continue; } } printf("%s\n", text); printf("\n\n\n"); break; } case 5: // Quit keepLooping = FALSE; break; } // end switch } else { printf("Invalid Input.\n"); } } return 0; }
void MenuSystem::displayPrevAction(){ if(getMenuOption(_curSubMenu, (_curOption - 1))){ _curOption--; displayMenu(); } }
void MenuSystem::displayNextAction(){ if(getMenuOption(_curSubMenu, (_curOption + 1))){ _curOption++; displayMenu(); } }
bool Menu::keyhandler(int key) { static int clockVal; static int menuActive = false; static int buttonUsed = 0; bool exitMenu = false; if (!_vm->getflag(fMenusWork) && !(_vm->getFeatures() & GF_MENUS)) return false; if (!menuActive) { clockVal = _vm->_game.clockEnabled; _vm->_game.clockEnabled = false; drawMenuBar(); } // Mouse handling if (_vm->_mouse.button) { int hmenu, vmenu; buttonUsed = 1; // Button has been used at least once if (_vm->_mouse.y <= CHAR_LINES) { // on the menubar hmenu = 0; MenuList::iterator iterh; for (iterh = _menubar.begin(); iterh != _menubar.end(); ++iterh) { AgiMenu *m = *iterh; if (mouseOverText(0, m->col, m->text)) { break; } else { hmenu++; } } if (hmenu <= _hMaxMenu) { if (_hCurMenu != hmenu) { _vCurMenu = -1; newMenuSelected(hmenu); } _hCurMenu = hmenu; } } else { // not in menubar vmenu = 0; AgiMenu *m = getMenu(_hCurMenu); MenuOptionList::iterator iterv; for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) { AgiMenuOption *do1 = *iterv; if (mouseOverText(2 + do1->index, m->wincol + 1, do1->text)) { break; } else { vmenu++; } } if (vmenu <= _vMaxMenu[_hCurMenu]) { if (_vCurMenu != vmenu) { drawMenuOption(_hCurMenu); drawMenuOptionHilite(_hCurMenu, vmenu); } _vCurMenu = vmenu; } } } else if (buttonUsed) { // Button released buttonUsed = 0; debugC(6, kDebugLevelMenu | kDebugLevelInput, "button released!"); if (_vCurMenu < 0) _vCurMenu = 0; drawMenuOptionHilite(_hCurMenu, _vCurMenu); if (_vm->_mouse.y <= CHAR_LINES) { // on the menubar } else { // see which option we selected AgiMenu *m = getMenu(_hCurMenu); MenuOptionList::iterator iterv; for (iterv = m->down.begin(); iterv != m->down.end(); ++iterv) { AgiMenuOption *d = *iterv; if (mouseOverText(2 + d->index, m->wincol + 1, d->text)) { // activate that option if (d->enabled) { debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); _vm->_game.controllerOccured[d->event] = true; _vm->_menuSelected = true; break; } } } exitMenu = true; } } if (!exitMenu) { if (!menuActive) { if (_hCurMenu >= 0) { drawMenuHilite(_hCurMenu); drawMenuOption(_hCurMenu); if (!buttonUsed && _vCurMenu >= 0) drawMenuOptionHilite(_hCurMenu, _vCurMenu); } menuActive = true; } switch (key) { case KEY_ESCAPE: debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ESCAPE"); exitMenu = true; break; case KEY_ENTER: { debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ENTER"); AgiMenuOption* d = getMenuOption(_hCurMenu, _vCurMenu); if (d->enabled) { debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); _vm->_game.controllerOccured[d->event] = true; _vm->_menuSelected = true; exitMenu = true; } break; } case KEY_DOWN: case KEY_UP: _vCurMenu += key == KEY_DOWN ? 1 : -1; if (_vCurMenu < 0) _vCurMenu = _vMaxMenu[_hCurMenu]; if (_vCurMenu > _vMaxMenu[_hCurMenu]) _vCurMenu = 0; drawMenuOption(_hCurMenu); drawMenuOptionHilite(_hCurMenu, _vCurMenu); break; case KEY_RIGHT: case KEY_LEFT: _hCurMenu += key == KEY_RIGHT ? 1 : -1; if (_hCurMenu < 0) _hCurMenu = _hMaxMenu; if (_hCurMenu > _hMaxMenu) _hCurMenu = 0; _vCurMenu = 0; newMenuSelected(_hCurMenu); drawMenuOptionHilite(_hCurMenu, _vCurMenu); break; } } if (exitMenu) { buttonUsed = 0; _picture->showPic(); _vm->writeStatus(); _vm->setvar(vKey, 0); _vm->_game.keypress = 0; _vm->_game.clockEnabled = clockVal; _vm->oldInputMode(); debugC(3, kDebugLevelMenu, "exit_menu: input mode reset to %d", _vm->_game.inputMode); menuActive = false; } return true; }