/** *@fn MainWindow::on_action_Otw_rz_triggered() *@brief Otwarcie pliku z testem. *Uruchamia okno z możliwością wyboru pliku .stf */ void MainWindow::on_action_Rozpocznij_od_nowa_triggered() { for (int i = 0; i < t.test.size(); ++i) t.test[i].marked = -1; iter = 0; loadQuestion(0); repaint(); }
/** *@fn MainWindow::on_testLoad_clicked()() *@brief Uruchamia okno wyboru pliku i zeruje nowy test */ void MainWindow::on_next_clicked() { if (iter < t.test.size() -1) { setMarked(iter); ++iter; loadQuestion(iter); } repaint(); }
void MainWindow::on_action_Otw_rz_triggered() { QString fileName = QFileDialog::getOpenFileName(this , QObject::tr("Open File"), "", QObject::tr("Simple Test Files (*.stf)")); if (fileName == NULL) return; t.load(fileName); ui->action_Otw_rz->setDisabled(true); ui->action_Rozpocznij_od_nowa->setDisabled(false); ui->action_Wyjd_bex_oceny->setDisabled(false); ui->reading->setVisible(false); ui->testing->setVisible(true); iter = 0; loadQuestion(0); }
/** *@fn MainWindow::setMarked(int) *@brief Ustawia odpowiedź użytkownika według ui *@param questNr numer pytania */ void MainWindow::on_prev_clicked() { if (iter >= 0) { setMarked(iter); --iter; loadQuestion(iter); } if (iter < t.test.size() - 1) { ui->next->setDisabled(false); } if (iter == 0) { ui->prev->setDisabled(true); } repaint(); }
void testApp::urlResponse(ofHttpResponse & response){ loadingResponseDone=true; theResponse=ofToString(response.data); ofStringReplace(theResponse, "[{", ""); ofStringReplace(theResponse, "}]", ""); allEntries=ofSplitString(theResponse, "},{"); if (URLsToLoad[currentURLNo]==recentPostcardsBerlin){ loadURL_recentPostcards(response); } else if (URLsToLoad[currentURLNo]==recentLettersBerlin){ loadURL_recentLetters(response); } else if(URLsToLoad[currentURLNo]==currentAlphabetBerlin && berlinAlphabetLoaded==false){ loadURL_alphabetGerman(response); } else if(URLsToLoad[currentURLNo]==currentAlphabetBerlin && berlinAlphabetLoaded==true){ loadURL_alphabetLatvian(response); } else if (URLsToLoad[currentURLNo]==currentQuestion){ loadQuestion(response); } }
void ofApp::urlResponse(ofHttpResponse & response){ printf(" received response\n"); loadingResponseDone=true; theResponse=ofToString(response.data); ofStringReplace(theResponse, "[{", ""); ofStringReplace(theResponse, "}]", ""); //printf("%s", theResponse.c_str()); allEntries=ofSplitString(theResponse, "},{"); if (URLsToLoad[currentURLNo]==recentPostcards){ loadURL_recentPostcards(response); } else if (URLsToLoad[currentURLNo]==recentLetters){ loadURL_recentLetters(response); } else if(URLsToLoad[currentURLNo]==currentAlphabet){ loadURL_alphabet(response); } else if (URLsToLoad[currentURLNo]==currentQuestion){ loadQuestion(response); } }
int main(int argc,char* argv[]){ fd_set main_fds,read_fds; struct sockaddr_in myaddr; struct sockaddr_in theiraddr; int fdmax; int listener; int newfd; int addrlen; char buf[MAX_BUF]; int nbytes; int yes=1;int q1,q2; int i,j,w; int store1=0; int store2=0; int port; char *endptr; FILE * userfile; FILE * onlfile; char filename[20]; char command[20]; char sub[20]; char user[20]; char passwd[20]; int state; int sock; int nowsock; int count;int onlcount; char invite[200][50]; int invitecount=0; char userlist[20][100]; char passlist[20][100]; char onluser[20][100]; char onlpass[20][100]; int onlsock[100]; int onlstate[100]; char challenger[20]; char question[2000][50]; char question2[2000][50]; char answer[2000][50]; char answer2[2000][50]; int x;int y;int exist;int z;int flag;int timeup=0; int gamestart=0;int u1,u2; int truesock; int rivalsock; int qcount=0; int questionid[100]; char message[20]; char rival[20]; char ans[200]; char me[200]; int seq1=0; int seq2=0; int haveChallenge[100][100]; for (i=0;i<100;i++) for (j=0;j<100;j++) { haveChallenge[i][j]=0; } for (i=0;i<100;i++){ onlstate[i]=0; } //reset information in onlinefile onlfile=fopen(ONLINEFILE,"w"); fclose(onlfile); //load list of users and their passwords loadUserList(USERFILE,userlist,passlist,&count); count--; loadOnlineList(ONLINEFILE,onluser,onlpass,onlsock,&onlcount); onlcount--; //load question library loadQuestion(LIBRARY,question,answer,&qcount); for (i=0;i<qcount-1;i++){ strcpy(question2[i],question[i]); strcpy(answer2[i],answer[i]); } FD_ZERO(&main_fds); FD_ZERO(&read_fds); if((listener=socket(AF_INET,SOCK_STREAM,0))==-1){ perror("socket"); exit(1); } if(setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int))==-1){ perror("setsockopt"); exit(1); } //bind myaddr.sin_family=AF_INET; myaddr.sin_addr.s_addr=INADDR_ANY; if (argc<1) myaddr.sin_port=htons(MYPORT); else { port = strtol(argv[1], &endptr, 0); if ( *endptr ) { printf("ECHOCLNT: Invalid port supplied.\n"); exit(EXIT_FAILURE); } myaddr.sin_port=htons(port); } memset(&(myaddr.sin_zero),'\0',8); if(bind(listener,(struct sockaddr *)&myaddr,sizeof(myaddr))==-1){ perror("bind"); exit(1); } //listen if(listen(listener,10)==-1){ perror("listen"); exit(1); } //select FD_SET(listener,&main_fds); fdmax=listener; printf("fdmax=%d\n",fdmax); while(1){ read_fds=main_fds; if(select(fdmax+1,&read_fds,NULL,NULL,NULL)==-1){ perror("select"); exit(1); } for(i=0;i<=fdmax;i++){ if(FD_ISSET(i,&read_fds)){ // create new connection if(i==listener){ addrlen=sizeof(theiraddr); if((newfd=accept(listener,(struct sockaddr *)&theiraddr,&addrlen))==-1){ perror("accept"); }else{ FD_SET(newfd,&main_fds); if(newfd>fdmax){ fdmax=newfd; } printf("New connection from %s - Socket %d\n",inet_ntoa(theiraddr.sin_addr),newfd); } //close socket }else{ nbytes=recv(i,buf,sizeof(buf),0); nowsock=i; buf[nbytes]='\0'; printf("buf=%s\n",buf); if(nbytes<=0){ //if socket closed if(nbytes==0){ printf("Socket %d Closed\n",i); }else{ perror("recv"); } close(i); // for (w=0;w<onlcount;w++) { if (onlsock[w]==i){ for (z=w;z<onlcount-1;z++){ strcpy(onluser[z],onluser[z+1]); strcpy(onlpass[z],onlpass[z+1]); onlsock[z]=onlsock[z+1]; } onlcount--; w--; } } onlfile=fopen(ONLINEFILE,"w"); for (w=0;w<onlcount;w++) { fprintf(onlfile,"%s %s %d\n",onluser[w],onlpass[w],onlsock[w]); } fclose(onlfile); FD_CLR(i,&main_fds); }else{ sub[0]=buf[0]; sub[1]=buf[1]; sub[2]='\0'; printf("sub=%s\n",sub); //if sign up if (strcmp(sub,"su")==0) { x=2; while(buf[x]!=' '){ user[x-2]=buf[x]; x++; } user[x-2]='\0'; //check user list to ensure 1user<->1username x++;y=0; while(x<=strlen(buf)){ passwd[y++]=buf[x++]; } exist=0; for (z=0;z<count;z++){ if (strcmp(user,userlist[z])==0){ exist=1; } } if (exist==0){ printf("Sign up success\n"); strcpy(buf,"Sign up success\n"); userfile=fopen(USERFILE,"a+"); strcpy(userlist[count],user); strcpy(passlist[count],passwd); count++; fprintf(userfile,"%s %s\n",user,passwd); fclose(userfile); }else{ printf("User existed\n"); strcpy(buf,"User existed\n"); } if (gamestart==0){ if (send(i,buf,strlen(buf),0)==-1){ perror("Can not send message"); } } } //if login if (strcmp(sub,"lg")==0){ x=2; while(buf[x]!=' '){ user[x-2]=buf[x]; x++; } user[x-2]='\0'; x++;y=0; while(x<=strlen(buf)){ passwd[y++]=buf[x++]; } //check password int truepass=0; for (z=0;z<count;z++){ if ((strcmp(user,userlist[z])==0)&&(strcmp(passwd,passlist[z])==0)){ truepass=1; } } if (truepass==0){ printf("login false\n"); strcpy(buf,"login false\n"); }else{ truesock=1; for (z=0;z<onlcount;z++) { if (onlsock[z]==nowsock){ truesock=0; } } if (truesock==1){ printf("login success\n"); strcpy(buf,"login success\n"); onlfile=fopen(ONLINEFILE,"a+"); fprintf(onlfile,"%s %s %d\n",user,passwd,nowsock); fclose(onlfile); strcpy(onluser[onlcount],user); strcpy(onlpass[onlcount],passwd); onlsock[onlcount]=nowsock; printf("nowsock=%d\n",nowsock); onlcount++; } } if (gamestart==0){ if (send(i,buf,strlen(buf),0)==-1){ perror("Can not send message"); } } } //display online player if (strcmp(sub,"ol")==0){ printf("online people=%d\n",onlcount); strcpy(buf,""); for (w=0;w<onlcount;w++){ strcat(buf,onluser[w]); printf("%s %d\n",onluser[w],onlsock[w]); strcat(buf,"\n"); } if (gamestart==0){ if (send(i,buf,strlen(buf),0)==-1){ perror("Can not send message"); } } } printf("buf=%s\n",buf); //challenge if (strcmp(sub,"rq")==0){ x=2; while((buf[x]!=' ')&&(buf[x]!='\0')){ rival[x-2]=buf[x]; x++; } rival[x-2]='\0'; //flag show whether the rival received a chanllenge message from another player or not //flag==0 <=> no, flag!=0 <=> yes flag=0; for (z=0;z<onlcount;z++){ if (strcmp(onluser[z],rival)==0) { rivalsock=onlsock[z]; if (onlstate[z]!=0) flag=1; else if (onlstate[z]==0) { onlstate[z]=1; } } if (onlsock[z]==nowsock) { strcpy(challenger,onluser[z]); } } if (flag==0){ strcpy(message,"cl"); haveChallenge[nowsock][rivalsock]=1; strcat(message,challenger); if (gamestart==0) if (send(rivalsock,message,strlen(message),0)==-1){ perror("can not send challenge\n"); } } //decline if rival received challenge from another else if (flag==1){ // ca cannot challenge strcpy(message,"cc"); strcat(message,rival); if (gamestart==0) if (send(nowsock,message,strlen(message),0)==-1){ perror("can not send challenge\n"); } } } // accept challenge message if ((strcmp(sub,"ac")==0)){ x=2; while((buf[x]!=' ')&&(buf[x]!='\0')){ rival[x-2]=buf[x]; x++; } rival[x-2]='\0'; printf("accept rival=%s\n",rival); printf("onlcount=%d\n",onlcount); //game start message strcpy(message,"gt"); gamestart=1; for (z=0;z<onlcount;z++){ if (strcmp(rival,onluser[z])==0){ rivalsock=onlsock[z]; } } if (haveChallenge[nowsock][rivalsock]==1){ if (gamestart==0) if (send(nowsock,message,strlen(message),0)==-1){ perror("can not start \n"); } if (gamestart==0) if (send(rivalsock,message,strlen(message),0)==-1){ perror("can not send challenge\n"); } strcpy(message,"qu"); strcat(message,question[0]); q1=0;q2=0; u1=rivalsock; u2=nowsock; if (gamestart==0){ send(u1,message,strlen(message),0); send(u2,message,strlen(message),0); } } } //decline challenge message if ((strcmp(sub,"dc")==0)){ x=2; while((buf[x]!=' ')&&(buf[x]!='\0')){ rival[x-2]=buf[x]; x++; } rival[x-2]='\0'; for (z=0;z<onlcount;z++){ if (strcmp(rival,onluser[z])==0){ rivalsock=onlsock[z]; } if (onlsock[z]==nowsock){ strcpy(me,onluser[z]); } } //cc can't access strcpy(message,"cc"); strcat(message,me); if (gamestart==0) if (send(rivalsock,message,strlen(message),0)==-1){ perror("can not send challenge\n"); } haveChallenge[rivalsock][nowsock]=0; } if ((strcmp(sub,"as")==0)&&(gamestart==1)){ x=2; while((buf[x]!=' ')&&(buf[x]!='\0')){ ans[x-2]=buf[x]; x++; } ans[x-2]='\0'; if (nowsock==u1){ if(strcmp(ans,answer[q1])==0){ seq1++; q1++; if (seq1==3) { srand(time(NULL)); int r=rand()%80+91; if (store2<q2+1) store2=q2+1; else store2++; strcpy(question2[store2],question2[r]); strcpy(answer2[store2],answer2[r]); } if (seq1==6) { srand(time(NULL)); int r=rand()%80+181; if (store2<q2+1) store2=q2+1; else store2++; strcpy(question2[store2],question2[r]); strcpy(answer2[store2],answer2[r]); seq1=0; } if (q1>=MAXQUESTION){ if (gamestart==1) { strcpy(message,"gowinner"); send(u1,message,strlen(message),0); strcpy(message,"goloser"); send(u2,message,strlen(message),0); } } else{ if (gamestart==1) { strcpy(message,"qu"); strcat(message,question[q1]); send(u1,message,strlen(message),0); } } } else{ seq1=0; } } if (nowsock==u2){ if (strcmp(ans,answer2[q2])==0){ q2++; seq2++; if (seq2==3) { srand(time(NULL)); int r=rand()%80+91; if (store1<q1+1) store1=q1+1; else store1++; strcpy(question[store1],question[r]); strcpy(answer[store1],answer[r]); } if (seq2==6) { srand(time(NULL)); int r=rand()%80+181; if (store1<q1+1) store1=q1+1; else store1++; strcpy(question[store1],question[r]); strcpy(answer[store1],answer[r]); seq2=0; } if (q2>=MAXQUESTION){ strcpy(message,"gowinner"); send(u2,message,strlen(message),0); strcpy(message,"goloser"); send(u1,message,strlen(message),0); } else{ strcpy(message,"qu"); strcat(message,question2[q2]); send(u2,message,strlen(message),0); } } else { seq2=0; } } } if ((strcmp(sub,"so")==0)&&(gamestart!=1)){ for (w=0;w<onlcount;w++) { if (onlsock[w]==i){ for (z=w;z<onlcount-1;z++){ strcpy(onluser[z],onluser[z+1]); strcpy(onlpass[z],onlpass[z+1]); onlsock[z]=onlsock[z+1]; } onlcount--; w--; } } onlfile=fopen(ONLINEFILE,"w"); for (w=0;w<onlcount;w++) { fprintf(onlfile,"%s %s %d\n",onluser[w],onlpass[w],onlsock[w]); } fclose(onlfile); } printf("============================================\n"); } } } } } return 0; }
void GraphWidget::launchDialogBoxes() { //movement int reponse = QMessageBox::question(this, "Movements", "Do you want to enable diagonal travel ?", QMessageBox ::Yes | QMessageBox::No); if (reponse == QMessageBox::No) { diagonals=false; } QStringList items; items << tr("None") << tr("Manhattan distance") << tr("Chebychev") << tr("Eucidian distance") << tr("Eucidian squared distance"); bool ok; QString item = QInputDialog::getItem(this, tr("Heuristic estimation"), tr("Choose an heuristic estimation or the distances to the destination points:"), items, 0, false, &ok); if (ok && !item.isEmpty()) { if(item=="None") { Cell::heuEstim=None; } else if(item=="Manhattan distance") { Cell::heuEstim=Manhattan; } else if(item=="Chebychev") { Cell::heuEstim=Chebychev; } else if(item=="Eucidian distance") { Cell::heuEstim=euclidian; } else if(item=="Eucidian squared distance") { Cell::heuEstim=euclidianSquared; } } //movement reponse = QMessageBox::question(this, "Movements", "Do you want to enable greedy search?", QMessageBox ::Yes | QMessageBox::No); if (reponse == QMessageBox::No) { Cell::useClosestFirst=false; } reponse = QMessageBox::question(this, "Optimisation", "Do you want to enable cthuluh optimisation?", QMessageBox ::Yes | QMessageBox::No); if (reponse == QMessageBox::No) { Cell::useCthulhu=false; } reponse = QMessageBox::question(this, "Portals", "Do you want to enable portal optimisation?", QMessageBox ::Yes | QMessageBox::No); if (reponse == QMessageBox::No) { Cell::usePortalsChains=false; } loadQuestion(); }
FlashCardEditor::FlashCardEditor(TemplateCore *core, QWidget *parent) : TemplateEditor(core, parent), m_ui(new Ui::FlashCardEditor) { m_ui->setupUi(this); // Set validators. QRegExpValidator *author_validator = new QRegExpValidator(this); QRegExpValidator *title_validator = new QRegExpValidator(this); author_validator->setRegExp(QRegExp(".{,50}")); title_validator->setRegExp(QRegExp(".{,100}")); m_ui->m_txtAuthor->lineEdit()->setValidator(author_validator); m_ui->m_txtName->lineEdit()->setValidator(title_validator); // Set validators. QRegExpValidator *question_validator = new QRegExpValidator(this); QRegExpValidator *hint_validator = new QRegExpValidator(this); question_validator->setRegExp(QRegExp(".{,100}")); hint_validator->setRegExp(QRegExp(".{,30}")); m_ui->m_txtQuestion->lineEdit()->setValidator(question_validator); m_ui->m_txtHint->lineEdit()->setValidator(hint_validator); // Set tab order. QList<QWidget*> tab_order_widgets; tab_order_widgets << m_ui->m_txtQuestion->lineEdit() << m_ui->m_btnPictureSelect << m_ui->m_txtAnswer->lineEdit() << m_ui->m_txtHint->lineEdit() << m_ui->m_txtAuthor->lineEdit() << m_ui->m_txtName->lineEdit() << m_ui->m_listQuestions << m_ui->m_btnQuestionAdd << m_ui->m_btnQuestionRemove << m_ui->m_btnQuestionUp << m_ui->m_btnQuestionDown; for (int i = 1; i < tab_order_widgets.size(); i++) { setTabOrder(tab_order_widgets.at(i - 1), tab_order_widgets.at(i)); } m_ui->m_txtNumberOfQuestions->lineEdit()->setEnabled(false); m_ui->m_lblPictureFile->label()->setWordWrap(true); m_ui->m_txtAnswer->lineEdit()->setPlaceholderText(tr("Answer for the answer")); m_ui->m_txtHint->lineEdit()->setPlaceholderText(tr("Hint for the answer")); m_ui->m_lblPictureFile->setStatus(WidgetWithStatus::Error, QString(), tr("No picture selected")); m_ui->m_txtAuthor->lineEdit()->setPlaceholderText(tr("Author of this quiz")); m_ui->m_txtName->lineEdit()->setPlaceholderText(tr("Name of this quiz")); IconFactory *factory = IconFactory::instance(); m_ui->m_btnQuestionAdd->setIcon(factory->fromTheme("item-add")); m_ui->m_btnQuestionRemove->setIcon(factory->fromTheme("item-remove")); m_ui->m_btnQuestionUp->setIcon(factory->fromTheme("move-up")); m_ui->m_btnQuestionDown->setIcon(factory->fromTheme("move-down")); connect(m_ui->m_btnPictureSelect, SIGNAL(clicked()), this, SLOT(selectPicture())); connect(m_ui->m_txtAuthor->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onAuthorChanged(QString))); connect(m_ui->m_txtQuestion->lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(saveQuestion())); connect(m_ui->m_txtName->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(onNameChanged(QString))); connect(m_ui->m_txtAnswer->lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(onAnswerChanged(QString))); connect(m_ui->m_txtHint->lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(onHintChanged(QString))); connect(m_ui->m_btnQuestionAdd, SIGNAL(clicked()), this, SLOT(addQuestion())); connect(m_ui->m_btnQuestionRemove, SIGNAL(clicked()), this, SLOT(removeQuestion())); connect(m_ui->m_listQuestions, SIGNAL(currentRowChanged(int)), this, SLOT(loadQuestion(int))); connect(m_ui->m_btnQuestionUp, SIGNAL(clicked()), this, SLOT(moveQuestionUp())); connect(m_ui->m_btnQuestionDown, SIGNAL(clicked()), this, SLOT(moveQuestionDown())); setEditorsEnabled(false); updateQuestionCount(); qRegisterMetaType<FlashCardQuestion>("FlashCardQuestion"); checkAuthor(); checkName(); loadQuestion(-1); }