Advertisement
Guest User

Untitled

a guest
May 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. #include "fiszki.h"
  2. #include <QPixmap>
  3. #include <QDir>
  4. #include <QDirIterator>
  5.  
  6. Fiszki::Fiszki():
  7. myScore(0),
  8. jezyk(0),
  9. rodzaj(0),
  10. //soundFile(null),
  11. riddle(" "),
  12. goodRiddle(" "),
  13. quantity(0)
  14. {
  15. }
  16.  
  17. void Fiszki::load()
  18. {
  19.  
  20. }
  21.  
  22. void Fiszki::show(QGraphicsView* view_,QPushButton* odpowiedz_1, QPushButton* odpowiedz_2, QPushButton* odpowiedz_3)
  23. {
  24. int temp = -1;
  25. delete view_->scene();
  26. view_->setScene(new QGraphicsScene());
  27. view_->scene()->addPixmap(QPixmap::fromImage(QImage(obrazy[goodRiddle])));
  28.  
  29. temp = rand()%3;
  30.  
  31. if(temp == 0)
  32. odpowiedz_1->setText(goodRiddle);
  33. odpowiedz_2->setText(haslaDoGry[1]);
  34. odpowiedz_3->setText(haslaDoGry[2]);
  35. if(temp == 1)
  36. odpowiedz_1->setText(haslaDoGry[1]);
  37. odpowiedz_2->setText(goodRiddle);
  38. odpowiedz_3->setText(haslaDoGry[2]);
  39. if(temp == 2)
  40. odpowiedz_1->setText(haslaDoGry[1]);
  41. odpowiedz_2->setText(haslaDoGry[2]);
  42. odpowiedz_3->setText(goodRiddle);
  43.  
  44. }
  45.  
  46. void Fiszki::start()
  47. {
  48.  
  49. if(jezyk = 0 && rodzaj == 0){ //zwierzeta angielski
  50.  
  51. if(quantity == 0)
  52. return;
  53.  
  54. QDirIterator it(QDir::currentPath()+ "/fiszki/animals", QDirIterator::Subdirectories );
  55. QImage img;
  56. quint8 i = 0;
  57. obrazy.clear();
  58. while (it.hasNext() && i < quantity ) {
  59. it.next();
  60. if(it.fileName().endsWith(".png")){
  61. img = QImage(it.filePath());
  62. i++;
  63. obrazy.insert(it.fileName(),img);
  64. hasla.push_back(it.fileName());
  65. }
  66. }
  67. }
  68.  
  69. if(jezyk = 1 && rodzaj == 0){ // zwierzeta polski
  70. if(quantity == 0)
  71. return;
  72.  
  73. QDirIterator it(QDir::currentPath()+ "/fiszki/zwierzeta", QDirIterator::Subdirectories );
  74. QImage img;
  75. quint8 i = 0;
  76. obrazy.clear();
  77. while (it.hasNext() && i < quantity ) {
  78. it.next();
  79. if(it.fileName().endsWith(".png")){
  80. img = QImage(it.filePath());
  81. i++;
  82. obrazy.insert(it.fileName(),img);
  83. hasla.push_back(it.fileName());
  84. }
  85. }
  86. }
  87.  
  88. if(jezyk = 0 && rodzaj == 1){ //rzeczy angielski
  89. if(quantity == 0)
  90. return;
  91.  
  92. QDirIterator it(QDir::currentPath()+ "/fiszki/things", QDirIterator::Subdirectories );
  93. QImage img;
  94. quint8 i = 0;
  95. obrazy.clear();
  96. while (it.hasNext() && i < quantity ) {
  97. it.next();
  98. if(it.fileName().endsWith(".png")){
  99. img = QImage(it.filePath());
  100. i++;
  101. obrazy.insert(it.fileName(),img);
  102. hasla.push_back(it.fileName());
  103. }
  104. }
  105. }
  106.  
  107. if(jezyk = 1 && rodzaj == 1){ //rzeczy polski
  108.  
  109. if(quantity == 0)
  110. return;
  111.  
  112. QDirIterator it(QDir::currentPath()+ "/fiszki/rzeczy", QDirIterator::Subdirectories );
  113. QImage img;
  114. quint8 i = 0;
  115. obrazy.clear();
  116. while (it.hasNext() && i < quantity ) {
  117. it.next();
  118. if(it.fileName().endsWith(".png")){
  119. img = QImage(it.filePath());
  120. i++;
  121. obrazy.insert(it.fileName(),img);
  122. hasla.push_back(it.fileName());
  123. }
  124. }
  125. }
  126.  
  127. if(jezyk = 0 && rodzaj == 2){ //kolory angielski
  128. if(quantity == 0)
  129. return;
  130.  
  131. QDirIterator it(QDir::currentPath()+ "/fiszki/colors", QDirIterator::Subdirectories );
  132. QImage img;
  133. quint8 i = 0;
  134. obrazy.clear();
  135. while (it.hasNext() && i < quantity ) {
  136. it.next();
  137. if(it.fileName().endsWith(".png")){
  138. img = QImage(it.filePath());
  139. i++;
  140. obrazy.insert(it.fileName(),img);
  141. hasla.push_back(it.fileName());
  142. }
  143. }
  144. }
  145.  
  146. if(jezyk = 1 && rodzaj == 2){ // kolory polski
  147.  
  148. if(quantity == 0)
  149. return;
  150.  
  151. QDirIterator it(QDir::currentPath()+ "/fiszki/kolory", QDirIterator::Subdirectories );
  152. QImage img;
  153. quint8 i = 0;
  154. obrazy.clear();
  155. while (it.hasNext() && i < quantity ) {
  156. it.next();
  157. if(it.fileName().endsWith(".png")){
  158. img = QImage(it.filePath());
  159. i++;
  160. obrazy.insert(it.fileName(),img);
  161. hasla.push_back(it.fileName());
  162. }
  163. }
  164. }
  165.  
  166. NextStep(true);
  167. }
  168.  
  169.  
  170. void Fiszki::checkIfRiddleSolved(const QString riddle)
  171. {
  172. if(riddle == goodRiddle) {
  173. myScore+=2;
  174. NextStep(true);
  175. } else{
  176. NextStep(false);
  177. myScore--;
  178. }
  179.  
  180. }
  181.  
  182. void Fiszki::shuffle()
  183. {
  184. int i = 0;
  185. qint8 temp = 0;
  186.  
  187. temp = rand()%10;
  188. goodRiddle = hasla[temp];
  189.  
  190. haslaDoGry[0] = hasla[temp];
  191. hasla.remove(temp);
  192. while(goodRiddle == hasla[temp]){
  193. temp = rand()%12;
  194. }
  195. haslaDoGry[1] = hasla[temp];
  196.  
  197. while(goodRiddle == hasla[temp] || haslaDoGry[1] == hasla[temp]){
  198. temp = rand()%12;
  199. }
  200. haslaDoGry[2] = hasla[temp];
  201. }
  202.  
  203. void Fiszki:: NextStep(bool answer)
  204. {
  205. if(answer == true && quantity > 0){
  206. shuffle();
  207. show(view, answer_1, answer_2, answer_3);
  208. quantity--;
  209. }
  210. }
  211.  
  212. void Fiszki :: Temp(QGraphicsView* view_,QPushButton* odpowiedz_1, QPushButton* odpowiedz_2, QPushButton* odpowiedz_3)
  213. {
  214. view = view_;
  215. answer_1 = odpowiedz_1;
  216. answer_2 = odpowiedz_2;
  217. answer_3 = odpowiedz_3;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement