void Server::stop(){ qDebug() << "Server::stop()"; waitForNewMessage(WAITING_FOR_MESSAGE::DONE); emit emitOutput(QString("\nMATCH FINISHED")); emit matchFinished(proverSM.getGoals(currentState)); QThread::currentThread()->msleep(500); int nbPlayers = addresses.size(); QString message = QString("(stop ") % matchId % " "; // Likely to be not necessary if(stepCounter == 0){ message += "nil)"; } else{ message += "( "; for(QString move : moves){ message += QString("(") % move % ") "; } message += QString(") )"); } for(int i = 0; i<nbPlayers; ++i){ networkConnections[i]->request(message, startclock); emit outputPlayerMessage(i, QString("Score %1").arg(getGoal(i))); } }
void Server::play(){ waitForNewMessage(WAITING_FOR_MESSAGE::PLAY); emit emitOutput(QString("\nPLAY step %1").arg(stepCounter)); QThread::currentThread()->msleep(500); QString message = QString("(play ") % matchId % " "; if(stepCounter == 0){ message += "nil)"; } else{ // bool singlePlayer = (moves.size() == 1); // if(!singlePlayer){ message += "( "; // } for(QString move : moves){ message += move % " "; } // if(!singlePlayer){ message += QString(") "); // } message += ")"; } int nbPlayers = addresses.size(); for(int i = 0; i<nbPlayers; ++i){ networkConnections[i]->request(message, startclock); } }
void Server::ping(){ qDebug() << "Server::ping()"; waitForNewMessage(WAITING_FOR_MESSAGE::INFO); int nbPlayers = addresses.size(); for(int i = 0; i<nbPlayers; ++i){ networkConnections[i]->request("(info)", 5); } }
void Server::start(){ waitForNewMessage(WAITING_FOR_MESSAGE::START); stepCounter = 0; // Incrementation is in handleTransition() currentState = proverSM.getInitialState(); // Update handled in handleTransition() emit emitOutput(QString("\nMETAGAME")); int nbPlayers = addresses.size(); QString messageStart = QString("(start ") % matchId % " "; QString messageEnd = gameString % ") " % QString::number(startclock) % " " % QString::number(playclock) % ")"; for(int i = 0; i<nbPlayers; ++i){ QString message = messageStart % roles[i] % " (" % messageEnd; networkConnections[i]->request(message, startclock); } }
// Function: waitForCommand // Inputs: NA // Outputs: False if user wants to quit, true otherwise // Description: This function displays the available commands and waits // for the user to input an integer [1,8]. If the value entered // is not an integer or is outside of the defined range, it // displays an error message. // bool Menu::waitForCommand() { // The value that the user input command is stored into. int whichCommand; // Display the command options available. std::cout << NEW_LINE << TAB << INPUT_NEW_USER << STRING_CREATE_USER; std::cout << TAB << INPUT_NEW_MESSAGE << STRING_POST_MESSAGE; std::cout << TAB << INPUT_NEW_TWEET << STRING_POST_TWEET; std::cout << TAB << INPUT_DISPLAY_WALL << STRING_DISPLAY_WALL; std::cout << TAB << INPUT_DISPLAY_HOME << STRING_DISPLAY_HOME; std::cout << TAB << INPUT_ADD_FRIEND << STRING_ADD_FRIEND; std::cout << TAB << INPUT_SWITCH_USER << STRING_SWITCH_USER; std::cout << TAB << INPUT_EXIT << STRING_QUIT; std::cout << TAB + TAB + STRING_CHOOSE_OPTION; // Read an input from the command line as a string. std::string inputString; std::getline(std::cin,inputString); // If string is not one char, throw an error. if ( inputString.length() > 1 ) { std::cout << NEW_LINE << TAB << TAB << STRING_INVALID_COMMAND; return waitForCommand(); } // Convert the string to an integer. whichCommand = std::atoi(inputString.c_str()); // Check to see if whichCommand is [1,8], if not display an error switch ( whichCommand ) { case INPUT_NEW_USER: waitForNewUser(); break; case INPUT_NEW_MESSAGE: waitForNewMessage(); break; case INPUT_NEW_TWEET: waitForNewTweet(); break; case INPUT_DISPLAY_HOME: displayPage(board.toHomeVector(users.getCurrentUser()), true); break; case INPUT_DISPLAY_WALL: displayPage(board.toWallVector(users.getCurrentUser()), false); break; case INPUT_ADD_FRIEND: waitForNewFriend(); break; case INPUT_SWITCH_USER: waitForAlternateUser(); break; case INPUT_EXIT: return false; default: std::cout << NEW_LINE + TAB + TAB + STRING_INVALID_COMMAND; return waitForCommand(); } return true; }