void MainWindow::on_SUBTRACT_clicked() { getdata(); ui->lineEdit_19->setText(QString::number(f1-s1)); ui->lineEdit_20->setText(QString::number(f2-s2)); ui->lineEdit_21->setText(QString::number(f3-s3)); ui->lineEdit_22->setText(QString::number(f4-s4)); ui->lineEdit_23->setText(QString::number(f5-s5)); ui->lineEdit_24->setText(QString::number(f6-s6)); ui->lineEdit_25->setText(QString::number(f7-s7)); ui->lineEdit_26->setText(QString::number(f8-s8)); ui->lineEdit_27->setText(QString::number(f9-s9)); clearfield(); }
void MainWindow::on_ADD_clicked() { getdata(); ui->lineEdit_19->setText(QString::number(f1+s1)); ui->lineEdit_20->setText(QString::number(f2+s2)); ui->lineEdit_21->setText(QString::number(f3+s3)); ui->lineEdit_22->setText(QString::number(f4+s4)); ui->lineEdit_23->setText(QString::number(f5+s5)); ui->lineEdit_24->setText(QString::number(f6+s6)); ui->lineEdit_25->setText(QString::number(f7+s7)); ui->lineEdit_26->setText(QString::number(f8+s8)); ui->lineEdit_27->setText(QString::number(f9+s9)); clearfield(); }
void MainWindow::on_MULTIPLY_clicked() { getdata(); ui->lineEdit_19->setText(QString::number(f1*s1+f2*s4+f3*s7)); ui->lineEdit_20->setText(QString::number(f1*s2+f2*s5+f3*s8)); ui->lineEdit_21->setText(QString::number(f1*s3+f2*s6+f3*s9)); ui->lineEdit_22->setText(QString::number(f4*s1+f5*s4+f6*s7)); ui->lineEdit_23->setText(QString::number(f4*s2+f5*s5+f6*s8)); ui->lineEdit_24->setText(QString::number(f4*s2+f5*s6+f6*s9)); ui->lineEdit_25->setText(QString::number(f7*s1+f8*s4+f9*s7)); ui->lineEdit_26->setText(QString::number(f7*s2+f8*s5+f9*s8)); ui->lineEdit_27->setText(QString::number(f7*s3+f8*s6+f9*s9)); clearfield(); }
//the massive main function int main(int argc, char* args[]) // Gets command line input { bool quit = false, playing = true, falling = true, held = false, paused = false, cheating = false; // All our miscellaneous bools to keep track of game states. int level = 0, lines = 0, score = 0, choice = 0, cheatseq = 0; Scores scores("gfx"); // Opens the uber camoflaged gfx file for getting highscores. Tricksy, eh? Uint32 start = 0; // A REALLY big int for keeping track of time srand(SDL_GetTicks()); // seeding the random... seed if( init() == false ) // Initialize SDL { cout << "Init fail" << endl; return 1; //ERR !!!! } block = load_image( "blocks.png" ); // load blocks if(block == NULL) { cout << "Error loading blocks.png" << endl; return 1; //ERR! } back = load_image( "back.png" ); // load background if(back == NULL) { cout << "Error loading back.png" << endl; return 1; //ERR! } smallblock = load_image( "smallblocks.png" ); // small blocks for next and hold if(smallblock == NULL) { cout << "Error loading smallblocks.png" << endl; return 1; //ERR! } title = load_image( "title.png" ); // title if(title == NULL) { cout << "Error loading title.png" << endl; return 1; //ERR! } cursor = load_image( "cursor.png" ); // cursor in menu if(cursor == NULL) { cout << "Error loading cursor.png" << endl; return 1; //ERR! } font = TTF_OpenFont("ProggyClean.ttf", FONTSIZE); // our font if(font == NULL) { cout << "Error loading ProggyClean.ttf" << endl; return 1; //Yup. Didn't load. } effect = Mix_LoadWAV( "pause.wav" ); // dee doo sound if(effect == NULL) { cout << "Mix_LoadWAV: " << Mix_GetError() << endl; } while(playing) // while the user hasn't quit { score = 0; quit = false; Mix_FadeOutMusic(100); // fades out the music (if playing) for menu. Mix_FreeMusic(music); // gets rid of any music we might have loaded if(XM == true) // load title music { music = Mix_LoadMUS("title.xm"); } else { music = Mix_LoadMUS("title.mp3"); } if(!music) { cout << "Mix_LoadMUS(\"title.mp3\"): %s\n" << Mix_GetError() << endl; // music didn't load... } Mix_PlayMusic(music, -1); // play it til the user can't stand it no mo'. for(int i = 600; i>=100; i--) // slowly bring up the title { while( SDL_PollEvent( &event ) ) // gets any recent events (mouse, keyboard, whatev) { if( event.type == SDL_QUIT ) // X button { i = 100; playing = false; quit = true; } else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) //escape { i = 100; // brings the title screen instantly } } SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) ); // fill screen black apply_surface( 200, i, title, screen ); // apply title if( SDL_Flip( screen ) == -1 ) // hand *screen to video card { return 1; //ERRRRRRR !! } SDL_Delay(2); // slows it down a wee bit. } apply_surface( 325, 402 + choice * 50, cursor, screen ); // display cursor numbers = TTF_RenderText_Blended(font, "START", fontColor); // start apply_surface( 350, 400, numbers, screen ); numbers = TTF_RenderText_Blended(font, "HIGH SCORES", fontColor); // high scores apply_surface( 350, 450, numbers, screen ); numbers = TTF_RenderText_Blended(font, "EXIT", fontColor); // exit apply_surface( 350, 500, numbers, screen ); if( SDL_Flip( screen ) == -1 ) { return 1; //ERRRRRRR !! } paused = true; //pause for menu while(paused && !quit) { while( SDL_PollEvent( &event ) ) // wait for events { if( event.type == SDL_QUIT ) { paused = false; playing = false; quit = true; } else if( event.type == SDL_KEYDOWN ) { switch(event.key.keysym.sym) { case SDLK_ESCAPE: paused = false; quit = true; playing = false; break; case SDLK_RETURN: switch(choice) { case 0: paused = false; break; case 1: scores.display(); break; case 2: paused = false; quit = true; playing = false; break; } break; case SDLK_DOWN: // down, move cursor down Mix_PlayChannel(-1, effect, 0); // dee doo sound if(choice < 2) { choice++; } else { choice = 0; } break; case SDLK_UP: // up, move cursor up Mix_PlayChannel(-1, effect, 0); // see above if(choice > 0) { choice--; } else { choice = 2; } break; } SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) ); apply_surface( 200, 100, title, screen ); apply_surface( 325, 402 + choice * 50, cursor, screen ); numbers = TTF_RenderText_Blended(font, "START", fontColor); apply_surface( 350, 400, numbers, screen ); numbers = TTF_RenderText_Blended(font, "HIGH SCORES", fontColor); apply_surface( 350, 450, numbers, screen ); numbers = TTF_RenderText_Blended(font, "EXIT", fontColor); apply_surface( 350, 500, numbers, screen ); if( SDL_Flip( screen ) == -1 ) { return 1; //ERRRRRRR !! } } } } if(!quit) // if the user didn't quit { Mix_FadeOutMusic(100); //fade out title music Mix_FreeMusic(music); //free it if(XM == true) // change to game music { music = Mix_LoadMUS("music.xm"); } else { music = Mix_LoadMUS("music.mp3"); } if(!music) { cout << "Mix_LoadMUS(\"music.mp3\"): %s\n" << Mix_GetError() << endl; // music didn't load... } Mix_PlayMusic(music, -1); SDL_Delay(1500); // wait for ba-ding! to finish } Tile *tile = NULL, *next = NULL, *next2 = NULL, *next3 = NULL, *hold = NULL, *blank = NULL; //current tile, next tiles 1 2 3, hold, and the tile used for switching hold setclips(); // set the clip boxes for tiles clearfield(); // initialize the field next = new Tile(); // inits new tiles next2 = new Tile(); next3 = new Tile(); while(!quit) { SDL_Delay(50); // wait a bit for the next block to drop tile = next; // next to current next = next2; // move nexts next2 = next3; next3 = new Tile(); // new next 3 if(!tile->check(0, 0)) // if the tile is colliding from the get go { tile->show(); if( SDL_Flip( screen ) == -1 ) { return 1; //ERRRRRRR !! } gameOver(); // THEN YOU LOSE! HA! scores.checkScore(score); // Did you get a high score? scores.save(); // save the high score file scores.display(); // display the current high scores quit = true; } falling = true; while(falling && !quit) // the there a lot of !quits from now on so it goes straight back to the menu { apply_surface( 0, 0, back, screen ); // background tile->show(); // show the current tile if(hold != NULL) { hold->disp(27,78); // display hold } next->disp(390, 78); // display nexts next2->disp(390, 158); next3->disp(390, 238); start = SDL_GetTicks(); // start the timer while( falling && SDL_GetTicks() - start < (1/((static_cast<double>(level)/25) + 1))*(SPEED - MINSPEED)+MINSPEED) // spiffy formula I took way to long to make for speeding up { while( SDL_PollEvent( &event ) ) // get events { if( event.type == SDL_QUIT ) // quit immediatly { clean(); exit(0); playing = false; } else if( event.type == SDL_KEYDOWN ) // was a key pressed? { switch( event.key.keysym.sym ) // what key was pressed? { case SDLK_LEFT: // move left tile->check(-1, 0); break; case SDLK_RIGHT: // move right tile->check(1, 0); break; case SDLK_z: // rotate CCW tile->rotate(CC); break; case SDLK_x: // rotate CW tile->rotate(CW); break; case SDLK_DOWN: // soft drop if(!tile->check(0,1)) // if it hits something as a result of dropping once { falling = false; // apply the tile } start = SDL_GetTicks(); // reset the timer break; case SDLK_UP: // hard drop while(tile->check(0,1)) // move it down til it cant any more { score += 2 * (level + 1); // you get points for being so daring! } start -= 1000; //Lock that sucka! break; case SDLK_n: // this is the cheat key. But you have to be cheating to use it ;D if(cheating) { delete tile; // basically just gives you new tiles tile = new Tile(); } break; case SDLK_ESCAPE: // back to main menu quit = true; break; case SDLK_k: //SUPER SECRET KYLE-MODE! block = load_image( "kyles.png" ); back = load_image( "kyleback.png" ); smallblock = load_image("smallkyles.png"); Mix_HaltMusic(); music = Mix_LoadMUS("rawk.mp3"); Mix_PlayMusic(music, -1); break; case SDLK_o: // back to original block = load_image( "blocks.png" ); back = load_image( "back.png" ); smallblock = load_image("smallblocks.png"); Mix_HaltMusic(); music = Mix_LoadMUS("music.mp3"); Mix_PlayMusic(music, -1); break; case SDLK_c: // hold if(hold && !held) // if there is something held and you haven't held yet this turn { blank = hold; // switch current and held hold = tile; tile = blank; } else if(!hold) // if you've never held { hold = tile; // hold current and make more tiles tile = next; next = next2; next2 = next3; next3 = new Tile(); } hold->reset(); // reset the x and y values of the tile held = true; break; case SDLK_p: // pause paused = true; Mix_PauseMusic(); // pause music Mix_PlayChannel(-1, effect, 0); // play the dee doo apply_surface( 0, 0, back, screen ); // cover the tiles numbers = TTF_RenderText_Solid(font, intToStr(score).c_str(), fontColor); // but keep the scores apply_surface( 550, 50, numbers, screen ); numbers = TTF_RenderText_Solid(font, intToStr(level).c_str(), fontColor); apply_surface( 550, 120, numbers, screen ); if( SDL_Flip( screen ) == -1 ) // display screen { return 1; //ERRRRRRR !! } while(paused) { while(SDL_PollEvent( &event )) // get events { if( event.type == SDL_QUIT ) // quit immediatly { quit = true; paused = false; playing = false; } else if( event.type == SDL_KEYDOWN ) // key down? { switch( event.key.keysym.sym ) // what key? { case SDLK_ESCAPE: // unpause case SDLK_p: // unpause paused = false; break; case SDLK_UP: // CHEATING!! WOO!!! UP UP DOWN DOWN LEFT RIGHT LEFT RIGHT A B. <3 CONTRA. if(cheatseq == 0 || cheatseq == 1) { cheatseq++; } else { cheatseq = 0; // if you screwed up } break; case SDLK_DOWN: if(cheatseq == 2 || cheatseq == 3) { cheatseq++; } else { cheatseq = 0; } break; case SDLK_LEFT: if(cheatseq == 4 || cheatseq == 6) { cheatseq++; } else { cheatseq = 0; } break; case SDLK_RIGHT: if(cheatseq == 5 || cheatseq == 7) { cheatseq++; } else { cheatseq = 0; } break; case SDLK_z: if(cheatseq == 8) { cheatseq++; } else { cheatseq = 0; } break; case SDLK_x: if(cheatseq == 9) { Mix_PlayChannel(-1, effect, 0); cheating = true; } else { cheatseq = 0; } break; default: cheatseq = 0; break; } } } } cheatseq = 0; // If you screwed up the cheat sequence Mix_ResumeMusic(); // play that funky music break; } apply_surface( 0, 0, back, screen ); // put the background up screen << *tile; //There. Overloading. Huzzah. if(hold != NULL) // display hold { hold->disp(27,78); } next->disp(390, 78); // display all the nexts next2->disp(390, 158); next3->disp(390, 238); numbers = TTF_RenderText_Solid(font, intToStr(score).c_str(), fontColor); //display scores apply_surface( 550, 50, numbers, screen ); numbers = TTF_RenderText_Solid(font, intToStr(level).c_str(), fontColor); //Pretty sweet you can use all the sweet string functions with a function that returns a string =D apply_surface( 550, 120, numbers, screen ); if( SDL_Flip( screen ) == -1 ) // show screen { return 1; //ERRRRRRR !! } } } numbers = TTF_RenderText_Solid(font, intToStr(score).c_str(), fontColor); // display scores apply_surface( 550, 50, numbers, screen ); numbers = TTF_RenderText_Solid(font, intToStr(level).c_str(), fontColor); apply_surface( 550, 120, numbers, screen ); if( SDL_Flip( screen ) == -1 ) { return 1; //ERRRRRRR !! } SDL_Delay(1); } if(tile->check(0, 1) == 0) // if it can't fall any more { falling = false; // stop falling } } tile->apply(); // apply it to the pile held = false; // you can hold again! score += (level+1)*checklines(lines); // check the lines and score accordingly level = lines/10; // level up? delete tile; // delete the current tile so we don't get yelled at } delete next; // delete all the other tiles if you lost delete next2; delete next3; delete hold; } clean(); // uninitialize SDL and everything return 0; // RETURN THAT ZERO, BABY. } // Fin