Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "fiszki.h"
- #include <QPixmap>
- #include <QDir>
- #include <QDirIterator>
- Fiszki::Fiszki():
- myScore(0),
- jezyk(0),
- rodzaj(0),
- //soundFile(null),
- riddle(" "),
- goodRiddle(" "),
- quantity(0)
- {
- }
- void Fiszki::load()
- {
- }
- void Fiszki::show(QGraphicsView* view_,QPushButton* odpowiedz_1, QPushButton* odpowiedz_2, QPushButton* odpowiedz_3)
- {
- int temp = -1;
- delete view_->scene();
- view_->setScene(new QGraphicsScene());
- view_->scene()->addPixmap(QPixmap::fromImage(QImage(obrazy[goodRiddle])));
- temp = rand()%3;
- if(temp == 0)
- odpowiedz_1->setText(goodRiddle);
- odpowiedz_2->setText(haslaDoGry[1]);
- odpowiedz_3->setText(haslaDoGry[2]);
- if(temp == 1)
- odpowiedz_1->setText(haslaDoGry[1]);
- odpowiedz_2->setText(goodRiddle);
- odpowiedz_3->setText(haslaDoGry[2]);
- if(temp == 2)
- odpowiedz_1->setText(haslaDoGry[1]);
- odpowiedz_2->setText(haslaDoGry[2]);
- odpowiedz_3->setText(goodRiddle);
- }
- void Fiszki::start()
- {
- if(jezyk = 0 && rodzaj == 0){ //zwierzeta angielski
- if(quantity == 0)
- return;
- QDirIterator it(QDir::currentPath()+ "/fiszki/animals", QDirIterator::Subdirectories );
- QImage img;
- quint8 i = 0;
- obrazy.clear();
- while (it.hasNext() && i < quantity ) {
- it.next();
- if(it.fileName().endsWith(".png")){
- img = QImage(it.filePath());
- i++;
- obrazy.insert(it.fileName(),img);
- hasla.push_back(it.fileName());
- }
- }
- }
- if(jezyk = 1 && rodzaj == 0){ // zwierzeta polski
- if(quantity == 0)
- return;
- QDirIterator it(QDir::currentPath()+ "/fiszki/zwierzeta", QDirIterator::Subdirectories );
- QImage img;
- quint8 i = 0;
- obrazy.clear();
- while (it.hasNext() && i < quantity ) {
- it.next();
- if(it.fileName().endsWith(".png")){
- img = QImage(it.filePath());
- i++;
- obrazy.insert(it.fileName(),img);
- hasla.push_back(it.fileName());
- }
- }
- }
- if(jezyk = 0 && rodzaj == 1){ //rzeczy angielski
- if(quantity == 0)
- return;
- QDirIterator it(QDir::currentPath()+ "/fiszki/things", QDirIterator::Subdirectories );
- QImage img;
- quint8 i = 0;
- obrazy.clear();
- while (it.hasNext() && i < quantity ) {
- it.next();
- if(it.fileName().endsWith(".png")){
- img = QImage(it.filePath());
- i++;
- obrazy.insert(it.fileName(),img);
- hasla.push_back(it.fileName());
- }
- }
- }
- if(jezyk = 1 && rodzaj == 1){ //rzeczy polski
- if(quantity == 0)
- return;
- QDirIterator it(QDir::currentPath()+ "/fiszki/rzeczy", QDirIterator::Subdirectories );
- QImage img;
- quint8 i = 0;
- obrazy.clear();
- while (it.hasNext() && i < quantity ) {
- it.next();
- if(it.fileName().endsWith(".png")){
- img = QImage(it.filePath());
- i++;
- obrazy.insert(it.fileName(),img);
- hasla.push_back(it.fileName());
- }
- }
- }
- if(jezyk = 0 && rodzaj == 2){ //kolory angielski
- if(quantity == 0)
- return;
- QDirIterator it(QDir::currentPath()+ "/fiszki/colors", QDirIterator::Subdirectories );
- QImage img;
- quint8 i = 0;
- obrazy.clear();
- while (it.hasNext() && i < quantity ) {
- it.next();
- if(it.fileName().endsWith(".png")){
- img = QImage(it.filePath());
- i++;
- obrazy.insert(it.fileName(),img);
- hasla.push_back(it.fileName());
- }
- }
- }
- if(jezyk = 1 && rodzaj == 2){ // kolory polski
- if(quantity == 0)
- return;
- QDirIterator it(QDir::currentPath()+ "/fiszki/kolory", QDirIterator::Subdirectories );
- QImage img;
- quint8 i = 0;
- obrazy.clear();
- while (it.hasNext() && i < quantity ) {
- it.next();
- if(it.fileName().endsWith(".png")){
- img = QImage(it.filePath());
- i++;
- obrazy.insert(it.fileName(),img);
- hasla.push_back(it.fileName());
- }
- }
- }
- NextStep(true);
- }
- void Fiszki::checkIfRiddleSolved(const QString riddle)
- {
- if(riddle == goodRiddle) {
- myScore+=2;
- NextStep(true);
- } else{
- NextStep(false);
- myScore--;
- }
- }
- void Fiszki::shuffle()
- {
- int i = 0;
- qint8 temp = 0;
- temp = rand()%10;
- goodRiddle = hasla[temp];
- haslaDoGry[0] = hasla[temp];
- hasla.remove(temp);
- while(goodRiddle == hasla[temp]){
- temp = rand()%12;
- }
- haslaDoGry[1] = hasla[temp];
- while(goodRiddle == hasla[temp] || haslaDoGry[1] == hasla[temp]){
- temp = rand()%12;
- }
- haslaDoGry[2] = hasla[temp];
- }
- void Fiszki:: NextStep(bool answer)
- {
- if(answer == true && quantity > 0){
- shuffle();
- show(view, answer_1, answer_2, answer_3);
- quantity--;
- }
- }
- void Fiszki :: Temp(QGraphicsView* view_,QPushButton* odpowiedz_1, QPushButton* odpowiedz_2, QPushButton* odpowiedz_3)
- {
- view = view_;
- answer_1 = odpowiedz_1;
- answer_2 = odpowiedz_2;
- answer_3 = odpowiedz_3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement