Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sf::RenderWindow window(sf::VideoMode(900, 900), "SFML works!");
- /*
- sf::CircleShape shape(100.f);
- shape.setFillColor(sf::Color::Green);
- */
- sf::RectangleShape rectangle(sf::Vector2f(10, 10)); // tworzymy prostokąt
- //rectangle.setPosition(0, 0);
- /*
- vec.push_back(sf::RectangleShape(sf::Vector2f(10, 10)));
- vec.push_back(sf::RectangleShape(sf::Vector2f(10, 10)));
- vec.push_back(sf::RectangleShape(sf::Vector2f(10, 10)));
- vec.push_back(sf::RectangleShape(sf::Vector2f(10, 10)));
- vec.push_back(sf::RectangleShape(sf::Vector2f(10, 10)));
- vec.push_back(sf::RectangleShape(sf::Vector2f(10, 10)));
- vec[0].setPosition(0, 0);
- vec[1].setPosition(10, 0);
- vec[2].setPosition(20, 0);
- vec[3].setPosition(0, 10);
- vec[4].setPosition(10, 10);
- vec[5].setPosition(20, 10);
- vec[1].setFillColor(sf::Color::Red);
- vec[2].setFillColor(sf::Color::Blue);
- vec[3].setFillColor(sf::Color::Blue);
- */
- int xVal = 0;
- int yVal = 0;
- int counter = 0;
- vector<vector<sf::RectangleShape>>vec1;
- vec1.resize(23);
- for (int i = 0; i < 23; ++i) {
- vec1[i] = (vector<sf::RectangleShape>(23));
- }
- for (size_t i = 0; i < 23; i++)
- {
- for (size_t j = 0; j < 23; j++)
- {
- vec1[i][j] = (sf::RectangleShape(sf::Vector2f(10, 10)));
- vec1[i][j].setPosition(xVal, yVal);
- xVal += 10;
- counter++;
- }
- yVal += 10;
- xVal = 0;
- }
- sf::Font font;
- if (!font.loadFromFile("arial.ttf")) {
- cout << "error";
- }
- sf::Text text[2];
- text[0].setFont(font);
- text[0].setString("play");
- text[0].setFillColor(sf::Color::Red);
- text[0].setCharacterSize(40);
- text[0].setPosition(400, 0);
- text[1].setFont(font);
- text[1].setString("back");
- text[1].setFillColor(sf::Color::White);
- text[1].setCharacterSize(40);
- text[1].setPosition(400, 410);
- auto map = GameField{};
- map.setMapValues();
- int change = -1;
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- switch (event.type) {
- case sf::Event::KeyReleased:
- switch (event.key.code) {
- val = index;
- case sf::Keyboard::Up:
- cout << index << endl;
- MoveUp(text);
- break;
- case sf::Keyboard::Down:
- cout << index << endl;
- MoveDown(text);
- break;
- case sf::Keyboard::Return:
- switch (index) {
- case 0:
- cout << "Play\n";
- for (size_t i = 0; i < 23; i++)
- {
- for (int j = 0; j < 23; j++) {
- if (map.vecOfCells[i][j]->getPreviousState()) {
- vec1[i][j].setFillColor(sf::Color::Red);
- }
- else { vec1[i][j].setFillColor(sf::Color::White); }
- map.setNumberOfCellsNeighbours(map.vecOfCells[i][j]);
- }
- }
- for (int i = 0; i < 23; ++i) {
- for (int j = 0; j < 23; ++j) {
- map.vecOfCells[i][j]->setPreviousState(map.vecOfCells[i][j]->getStatusOfCell());
- map.vecOfCells[i][j]->setNumberOfNeighbours(0);
- }
- }
- break;
- case 1:
- cout << "back\n";
- change--;
- break;
- }
- break;
- }
- break;
- case sf::Event::Closed:
- window.close();
- break;
- }
- }
- window.clear();
- for (int i = 0; i < 23; i++) {
- for (int j = 0; j < 23; j++)
- {
- window.draw(vec1[i][j]);
- }
- }
- window.draw(text[0]);
- window.draw(text[1]);
- window.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement