Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1.  
  2. bool GameMenu(size_t &size, int &hunterQty,int &trapQty, bool &smartBear)
  3. {
  4. sf::RenderWindow window(sf::VideoMode(1280,720), "beast and hunter");
  5. bool isMenu = true;
  6.  
  7. int mouseX = 0;
  8. int mouseY = 0;
  9. int stage = 0;
  10. enum stageMenu { first, fieldSize, hunter, trap, smart};
  11.  
  12. Message menuMessage("fonts/myFonts.ttf", "Hello, it's game hunters and beast \nUse [W][A][S][D] or arrows for move hunters.\n [TAB] for next hunter \n\n", 60, 30, 30);
  13. menuMessage.text_.setFillColor(sf::Color::Black);
  14.  
  15. Message menuNext("fonts/myFonts.ttf", "Next->", 100, 30, 500);
  16.  
  17. Message menuSizeText("fonts/myFonts.ttf", "please select playing field size!", 100, 30, 30);
  18. menuSizeText.text_.setFillColor(sf::Color::Black);
  19.  
  20. Message menuHunters("fonts/myFonts.ttf", "please select hunters quantity!", 100, 30, 30);
  21. menuHunters.text_.setFillColor(sf::Color::Black);
  22.  
  23. Message menuTraps("fonts/myFonts.ttf", "please select traps quantity!", 100, 30, 30);
  24. menuTraps.text_.setFillColor(sf::Color::Black);
  25.  
  26. Message menubear("fonts/myFonts.ttf", "use smart bear?", 100, 30, 30);
  27. menubear.text_.setFillColor(sf::Color::Black);
  28.  
  29. Message menuBearYes("fonts/myFonts.ttf", "NO", 160, 30, 500);
  30. Message menuBearNO("fonts/myFonts.ttf", "YES", 160, 130, 500);
  31.  
  32. std::vector <Message> mapSize;
  33. mapSize.reserve(9);
  34. for (int i = 0; i < 9; i++)
  35. {
  36. int buff = 4 + i;
  37. std::string strBuff
  38. = std::to_string(buff);
  39. mapSize.emplace_back("fonts/myFonts.ttf", strBuff, 160, 30 + i * 130, 520);
  40. }
  41.  
  42. std::vector <Message> hunters;
  43. hunters.reserve(5);
  44. for (int i = 0; i < 5; i++)
  45. {
  46. int buff = 2 + i;
  47. std::string strBuff = std::to_string(buff);
  48. hunters.emplace_back("fonts/myFonts.ttf", strBuff, 160, 30 + i * 130, 520);
  49. }
  50.  
  51. std::vector <Message> traps;
  52. traps.reserve(4);
  53. for (int i = 0; i < 4; i++)
  54. {
  55. int buff = 1 + i;
  56. std::string strBuff = std::to_string(buff);
  57. traps.emplace_back("fonts/myFonts.ttf", strBuff, 160, 30 + i * 130, 520);
  58.  
  59. }
  60.  
  61. sf::Texture menuBackground;
  62. menuBackground.loadFromFile("images/menu.jpg");
  63. sf::Sprite menuBg(menuBackground);
  64.  
  65. while (isMenu)
  66. {
  67.  
  68. sf::Vector2i pixelPos = sf::Mouse::getPosition(window);
  69. mouseX = pixelPos.x;
  70. mouseY = pixelPos.y;
  71. //std::cout << "x = " << mouseX << " || y = " << mouseY << "\n";
  72. std::cout << stage<<"\n";
  73. window.clear();
  74. window.draw(menuBg);
  75.  
  76. if (stage == first)
  77. {
  78. window.draw(menuMessage.getMessage());
  79. window.draw(menuNext.getMessage());
  80. window.display();
  81. }
  82.  
  83. if (stage == fieldSize)
  84. {
  85. window.draw(menuSizeText.getMessage());
  86. for (int i = 0; i < 9; i++)
  87. {
  88. window.draw(mapSize[i].getMessage());
  89. }
  90. window.display();
  91. }
  92.  
  93. if (stage == hunter)
  94. {
  95. if (size > 5)
  96. {
  97. int a = (size / 2)-1;
  98. window.draw(menuHunters.getMessage());
  99. for (int i = 0; i <a; i++)
  100. {
  101. window.draw(hunters[i].getMessage());
  102. }
  103. window.display();
  104. }
  105. }
  106.  
  107. if (stage == trap)
  108. {
  109. int a = (size / 3);
  110. window.draw(menuTraps.getMessage());
  111. for (int i = 0; i < a; i++)
  112. {
  113. window.draw(traps[i].getMessage());
  114. }
  115. window.display();
  116. }
  117.  
  118. if (stage == smart)
  119. {
  120.  
  121.  
  122. }
  123.  
  124. sf::Event event;
  125. while (window.pollEvent(event))
  126. {
  127. if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
  128. {
  129. window.close();
  130. }
  131. }
  132.  
  133.  
  134. if (stage == first)
  135. {
  136. if (((mouseY > 520) && (mouseY < 585)) && ((mouseX > 30) && (mouseX < 320)))
  137. {
  138. menuNext.text_.setFillColor(sf::Color::Blue);
  139. if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  140. {
  141. stage++;
  142. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  143. }
  144. }
  145. else
  146. {
  147. menuNext.text_.setFillColor(sf::Color::White);
  148. }
  149.  
  150. }
  151.  
  152. if (stage == fieldSize)
  153. {
  154. for (int i = 0; i < 9; i++)
  155. {
  156. if (((mouseY > 565) && (mouseY < 690)) && ((mouseX > 30 + i * 130) && (mouseX < 30 + (i + 1) * 130)))
  157. {
  158. mapSize[i].text_.setFillColor(sf::Color::Blue);
  159. if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  160. {
  161. size = i + 4;
  162. stage++;
  163. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  164. }
  165. }
  166. else
  167. {
  168. mapSize[i].text_.setFillColor(sf::Color::White);
  169. }
  170. }
  171. }
  172.  
  173. if(stage == hunter)
  174. {
  175. if (size < 6)
  176. {
  177. hunterQty = 2;
  178. stage++;
  179. }
  180. else
  181. {
  182. int a = ((size / 2)-1);
  183. for (int i = 0; i < a; i++)
  184. {
  185. if (((mouseY > 565) && (mouseY < 690)) && ((mouseX > 30 + i * 130) && (mouseX < 30 + (i + 1) * 130)))
  186. {
  187. hunters[i].text_.setFillColor(sf::Color::Blue);
  188. if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  189. {
  190. hunterQty = i + 2;
  191. stage++;
  192. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  193. }
  194. }
  195. else
  196. {
  197. hunters[i].text_.setFillColor(sf::Color::White);
  198. }
  199. }
  200. }
  201. }
  202.  
  203. if (stage == trap)
  204. {
  205. int a = (size / 3);
  206. if(a>1)
  207. {
  208. for (int i = 0; i < a; i++)
  209. {
  210. if (((mouseY > 565) && (mouseY < 690)) && ((mouseX > 30) && (mouseX < 160)))
  211. {
  212. traps[i].text_.setFillColor(sf::Color::Blue);
  213. if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
  214. {
  215. trapQty = i + 1;
  216. stage++;
  217. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  218. } }
  219. else
  220. {
  221. traps[i].text_.setFillColor(sf::Color::White);
  222. }
  223. }
  224. }
  225. else
  226. {
  227. stage++;
  228. }
  229. }
  230. }
  231.  
  232. return false;
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement