Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool GameMenu(size_t &size, int &hunterQty,int &trapQty, bool &smartBear)
- {
- sf::RenderWindow window(sf::VideoMode(1280,720), "beast and hunter");
- bool isMenu = true;
- int mouseX = 0;
- int mouseY = 0;
- int stage = 0;
- enum stageMenu { first, fieldSize, hunter, trap, smart};
- 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);
- menuMessage.text_.setFillColor(sf::Color::Black);
- Message menuNext("fonts/myFonts.ttf", "Next->", 100, 30, 500);
- Message menuSizeText("fonts/myFonts.ttf", "please select playing field size!", 100, 30, 30);
- menuSizeText.text_.setFillColor(sf::Color::Black);
- Message menuHunters("fonts/myFonts.ttf", "please select hunters quantity!", 100, 30, 30);
- menuHunters.text_.setFillColor(sf::Color::Black);
- Message menuTraps("fonts/myFonts.ttf", "please select traps quantity!", 100, 30, 30);
- menuTraps.text_.setFillColor(sf::Color::Black);
- Message menubear("fonts/myFonts.ttf", "use smart bear?", 100, 30, 30);
- menubear.text_.setFillColor(sf::Color::Black);
- Message menuBearYes("fonts/myFonts.ttf", "NO", 160, 30, 500);
- Message menuBearNO("fonts/myFonts.ttf", "YES", 160, 130, 500);
- std::vector <Message> mapSize;
- mapSize.reserve(9);
- for (int i = 0; i < 9; i++)
- {
- int buff = 4 + i;
- std::string strBuff
- = std::to_string(buff);
- mapSize.emplace_back("fonts/myFonts.ttf", strBuff, 160, 30 + i * 130, 520);
- }
- std::vector <Message> hunters;
- hunters.reserve(5);
- for (int i = 0; i < 5; i++)
- {
- int buff = 2 + i;
- std::string strBuff = std::to_string(buff);
- hunters.emplace_back("fonts/myFonts.ttf", strBuff, 160, 30 + i * 130, 520);
- }
- std::vector <Message> traps;
- traps.reserve(4);
- for (int i = 0; i < 4; i++)
- {
- int buff = 1 + i;
- std::string strBuff = std::to_string(buff);
- traps.emplace_back("fonts/myFonts.ttf", strBuff, 160, 30 + i * 130, 520);
- }
- sf::Texture menuBackground;
- menuBackground.loadFromFile("images/menu.jpg");
- sf::Sprite menuBg(menuBackground);
- while (isMenu)
- {
- sf::Vector2i pixelPos = sf::Mouse::getPosition(window);
- mouseX = pixelPos.x;
- mouseY = pixelPos.y;
- //std::cout << "x = " << mouseX << " || y = " << mouseY << "\n";
- std::cout << stage<<"\n";
- window.clear();
- window.draw(menuBg);
- if (stage == first)
- {
- window.draw(menuMessage.getMessage());
- window.draw(menuNext.getMessage());
- window.display();
- }
- if (stage == fieldSize)
- {
- window.draw(menuSizeText.getMessage());
- for (int i = 0; i < 9; i++)
- {
- window.draw(mapSize[i].getMessage());
- }
- window.display();
- }
- if (stage == hunter)
- {
- if (size > 5)
- {
- int a = (size / 2)-1;
- window.draw(menuHunters.getMessage());
- for (int i = 0; i <a; i++)
- {
- window.draw(hunters[i].getMessage());
- }
- window.display();
- }
- }
- if (stage == trap)
- {
- int a = (size / 3);
- window.draw(menuTraps.getMessage());
- for (int i = 0; i < a; i++)
- {
- window.draw(traps[i].getMessage());
- }
- window.display();
- }
- if (stage == smart)
- {
- }
- sf::Event event;
- while (window.pollEvent(event))
- {
- if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
- {
- window.close();
- }
- }
- if (stage == first)
- {
- if (((mouseY > 520) && (mouseY < 585)) && ((mouseX > 30) && (mouseX < 320)))
- {
- menuNext.text_.setFillColor(sf::Color::Blue);
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- stage++;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- }
- }
- else
- {
- menuNext.text_.setFillColor(sf::Color::White);
- }
- }
- if (stage == fieldSize)
- {
- for (int i = 0; i < 9; i++)
- {
- if (((mouseY > 565) && (mouseY < 690)) && ((mouseX > 30 + i * 130) && (mouseX < 30 + (i + 1) * 130)))
- {
- mapSize[i].text_.setFillColor(sf::Color::Blue);
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- size = i + 4;
- stage++;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- }
- }
- else
- {
- mapSize[i].text_.setFillColor(sf::Color::White);
- }
- }
- }
- if(stage == hunter)
- {
- if (size < 6)
- {
- hunterQty = 2;
- stage++;
- }
- else
- {
- int a = ((size / 2)-1);
- for (int i = 0; i < a; i++)
- {
- if (((mouseY > 565) && (mouseY < 690)) && ((mouseX > 30 + i * 130) && (mouseX < 30 + (i + 1) * 130)))
- {
- hunters[i].text_.setFillColor(sf::Color::Blue);
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- hunterQty = i + 2;
- stage++;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- }
- }
- else
- {
- hunters[i].text_.setFillColor(sf::Color::White);
- }
- }
- }
- }
- if (stage == trap)
- {
- int a = (size / 3);
- if(a>1)
- {
- for (int i = 0; i < a; i++)
- {
- if (((mouseY > 565) && (mouseY < 690)) && ((mouseX > 30) && (mouseX < 160)))
- {
- traps[i].text_.setFillColor(sf::Color::Blue);
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
- {
- trapQty = i + 1;
- stage++;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- } }
- else
- {
- traps[i].text_.setFillColor(sf::Color::White);
- }
- }
- }
- else
- {
- stage++;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement