Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- sf::Event event;
- sf::Clock czasZmiany;
- czasZmiany.getElapsedTime();
- sf::RenderWindow window(sf::VideoMode(1200, 600), "SFML works!");
- vector<vector<sf::RectangleShape>>szachownica;
- //WPISANIE LICZBY PRZEZ UZYTKOWNIKA
- int n;
- cout << "PODAJ NIEPARZYSTA LICZBE ";
- cin >> n;
- int a = 0;
- for (int j = 0; j < n; j++)
- {
- vector<sf::RectangleShape>pomocniczy;
- for (int i = 0; i < n; i++)
- {
- sf::RectangleShape pole;
- pole.setPosition(sf::Vector2f(i * 52.0f, a));
- pole.setFillColor(sf::Color::White);
- pole.setSize(sf::Vector2f(50.0f, 50.0f));
- pomocniczy.push_back(pole);
- }
- szachownica.push_back(pomocniczy);
- a += 51;
- }
- //POCZATEK PROGRAMU
- int i = 0;
- int j = 0;
- int k = n - 1;
- int l = 0;
- bool dol = false;
- bool gora = false;
- while (window.isOpen())
- {
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- window.clear();
- //ZMIANA KOLOROW
- if (czasZmiany.getElapsedTime().asMilliseconds() > 500.0f)
- {
- if (gora == false)
- {
- if (i < n)
- {
- szachownica[i][j].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
- i++;
- j++;
- }
- else
- {
- i--;
- j--;
- gora = true;
- }
- }
- if (gora == true)
- {
- if (i!=0)
- {
- i--;
- j--;
- szachownica[i][j].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
- }
- else
- {
- gora = false;
- i++;
- j++;
- }
- }
- if (dol == false)
- {
- if (l < n)
- {
- szachownica[k][l].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
- l++;
- k--;
- }
- else
- {
- l--;
- k++;
- dol = true;;
- }
- }
- if (dol == true)
- {
- if (l !=0)
- {
- l--;
- k++;
- szachownica[k][l].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
- }
- else
- {
- l++;
- k--;
- dol = false;;;
- }
- }
- czasZmiany.restart();
- }
- //RYSOWANIE SZACHOWNICY
- for (auto itr = szachownica.begin(); itr != szachownica.end(); itr++)
- {
- for (auto itr1 = (*itr).begin(); itr1 != (*itr).end(); itr1++)
- {
- window.draw((*itr1));
- }
- }
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement