Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5. int main()
  6. {
  7. sf::Event event;
  8.  
  9. sf::Clock czasZmiany;
  10. czasZmiany.getElapsedTime();
  11.  
  12. sf::RenderWindow window(sf::VideoMode(1200, 600), "SFML works!");
  13. vector<vector<sf::RectangleShape>>szachownica;
  14.  
  15. //WPISANIE LICZBY PRZEZ UZYTKOWNIKA
  16.  
  17. int n;
  18. cout << "PODAJ NIEPARZYSTA LICZBE ";
  19. cin >> n;
  20. int a = 0;
  21. for (int j = 0; j < n; j++)
  22. {
  23. vector<sf::RectangleShape>pomocniczy;
  24. for (int i = 0; i < n; i++)
  25. {
  26. sf::RectangleShape pole;
  27. pole.setPosition(sf::Vector2f(i * 52.0f, a));
  28. pole.setFillColor(sf::Color::White);
  29. pole.setSize(sf::Vector2f(50.0f, 50.0f));
  30. pomocniczy.push_back(pole);
  31. }
  32. szachownica.push_back(pomocniczy);
  33. a += 51;
  34.  
  35. }
  36. //POCZATEK PROGRAMU
  37.  
  38. int i = 0;
  39. int j = 0;
  40.  
  41. int k = n - 1;
  42. int l = 0;
  43. bool dol = false;
  44. bool gora = false;
  45. while (window.isOpen())
  46. {
  47. while (window.pollEvent(event))
  48. {
  49. if (event.type == sf::Event::Closed)
  50. window.close();
  51. }
  52.  
  53. window.clear();
  54.  
  55. //ZMIANA KOLOROW
  56.  
  57. if (czasZmiany.getElapsedTime().asMilliseconds() > 500.0f)
  58. {
  59.  
  60. if (gora == false)
  61. {
  62. if (i < n)
  63. {
  64. szachownica[i][j].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
  65. i++;
  66. j++;
  67. }
  68. else
  69. {
  70. i--;
  71. j--;
  72. gora = true;
  73. }
  74. }
  75.  
  76. if (gora == true)
  77. {
  78. if (i!=0)
  79. {
  80. i--;
  81. j--;
  82. szachownica[i][j].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
  83. }
  84. else
  85. {
  86. gora = false;
  87. i++;
  88. j++;
  89. }
  90. }
  91. if (dol == false)
  92. {
  93. if (l < n)
  94. {
  95. szachownica[k][l].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
  96. l++;
  97. k--;
  98. }
  99. else
  100. {
  101. l--;
  102. k++;
  103. dol = true;;
  104. }
  105. }
  106. if (dol == true)
  107. {
  108. if (l !=0)
  109. {
  110. l--;
  111. k++;
  112. szachownica[k][l].setFillColor(sf::Color(rand() % 255, rand() % 255, rand() % 255));
  113. }
  114. else
  115. {
  116. l++;
  117. k--;
  118. dol = false;;;
  119. }
  120. }
  121. czasZmiany.restart();
  122. }
  123. //RYSOWANIE SZACHOWNICY
  124. for (auto itr = szachownica.begin(); itr != szachownica.end(); itr++)
  125. {
  126. for (auto itr1 = (*itr).begin(); itr1 != (*itr).end(); itr1++)
  127. {
  128. window.draw((*itr1));
  129. }
  130.  
  131. }
  132. window.display();
  133. }
  134.  
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement