/** \brief The update method for the MainMenu. * This method prints the main menu image onto the screen and creates an output based on the users input. * * \param input std::string The input from the user. * \return void * */ void MainMenu::update(std::string input) { _drawer->printMainMenuImage(); if(_introView != NULL) { _introView->update(input); } bool executedInput = executeInput(input); if(!executedInput) _drawer->printMainMenuText(); if(executedInput && _introView == NULL) _gameManager->printText("\nType anything to go back ..."); //if(!executeInput(input) && _introView == NULL) _drawer->printMainMenuText(); //else if(_introView == NULL) _gameManager->printText("\nType anything to go back ..."); }
int main(int argc, char *argv[]) { int listenfd = 0, connfd = 0, n = 0, len = 0; char sendBuff[1025] = {0}; struct sockaddr_in client_addr; FILE *infile = 0; if((listenfd = serverInit()) == -1) { //error setting up server fprintf(stderr, "Error: unable to initialize server\n"); return 1; } if(!(infile = getConfigFile())) { //unable to open config file fprintf(stderr, "Cannot open config file \"%s\", make s", CONFIG_FILE); fprintf(stderr, "ure the file exists and you have read permissions.\n"); return 1; } while(1) { //loop continually to connect to client len = sizeof(client_addr); connfd = accept(listenfd, (struct sockaddr *)&client_addr, (socklen_t *)&len); printf("Client connected from IP=%s on PORT=%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); while(1) { //processing loop n = read(connfd, sendBuff, sizeof(sendBuff)); if(!n) { //client died printf("Client died, waiting for new connection\n"); close(connfd); break; } else if(n == -1) { //client hasn't sent anything yet continue; } executeInput(sendBuff, connfd, infile); }//end while sleep(1); //sleep for a tiny bit to we don't use all CPU power, hehehe }//end while fclose(infile); //close config file }//end main
void Gesture::executeAction(Action action, string params) { switch (action) { case AUTOHOTKEY: executeAutohotkey(params); break; case SEND_INPUT: vector<int> iKeys; size_t *e; vector<string> sKeys = explode(params, ','); for (size_t i = 0; i < sKeys.size(); i++) iKeys.push_back(std::stol(sKeys[i], e, 16)); executeInput(iKeys); break; } }
/** \brief Updates the MapViewer. * It gives an suitable output based on the users input, writes an title into the screen * and executed the map render method. * It also displays an description of the current map field, the player is standing on. * * \param input std::string The users input. * \return void * */ void MapViewer::update(std::string input) { if(_subMap != NULL) { _subMap->update(input); return; } executeInput(input); _gameManager->print("╓────────────────────────────────────╖\n"); _gameManager->print("║ THE HOLY KINGDOM \033[4m\033[1mMODGNI KYLOH EHT\033[0m: ║\n"); _gameManager->print("╙────────────────────────────────────╜\n"); renderImage(); _gameManager->printText("You are " + getFieldDescription(_selectedFieldChar)); std::cout << std::regex_match(_selectedFieldChar + "", std::regex("1|2|3")) << " - " << _selectedFieldChar << std::endl; if(_enterErrorMessage == "") { if(std::regex_match(std::string(1, _selectedFieldChar), std::regex("[1-3]"))) _gameManager->printText("You can E N T E R this area.\n"); else _gameManager->printText("You can NOT(!) E N T E R this area (yet).\n"); } else _gameManager->printText(_enterErrorMessage); }
int Shell::run() { char *cmdStr; /* Read commands. */ while (true) { /* Print the prompt. */ prompt(); /* Wait for a command string. */ cmdStr = getInput(); /* Enough input? */ if (strlen(cmdStr) == 0) { continue; } /* Execute the command. */ executeInput(cmdStr); } return EXIT_SUCCESS; }
void StoryView::update(string input) { executeInput(input); _story->print(); }