Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SFML/Graphics.hpp>
- using namespace std;
- using namespace sf;
- void hmminesroundtiles(int gridLogic[12][12], int size)
- {
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 10; j++) {
- int n = 0;
- if (gridLogic[i][j] == 9) continue;
- if (gridLogic[i][j+1] == 9) n++;
- if (gridLogic[i+1][j] == 9) n++;
- if (gridLogic[i][j - 1] == 9) n++;
- if (gridLogic[i-1][j] == 9) n++;
- if (gridLogic[i+1][j + 1] == 9) n++;
- if (gridLogic[i + 1][j - 1] == 9) n++;
- if (gridLogic[i - 1][j + 1] == 9) n++;
- if (gridLogic[i - 1][j - 1] == 9) n++;
- gridLogic[i][j] = n;
- }
- }
- }
- int main()
- {
- srand(time(0));
- RenderWindow window(VideoMode(400, 400), "Mines");
- int fieldwidth = 32;
- int gridview[12][12];
- int gridLogic[12][12];
- Texture texture;
- texture.loadFromFile("C:\\Users\\limb547\\Documents\\tiles.jpg");
- Sprite sp(texture);
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 10; j++) {
- gridview[i][j] = 10;
- if (rand() % 5 == 0) {
- gridLogic[i][j] = 9;
- }
- else {
- gridLogic[i][j] = 0;
- }
- }
- }
- hmminesroundtiles(gridLogic, 10);
- while (window.isOpen())
- {
- Vector2i cursorPosition = Mouse::getPosition(window);
- int x = cursorPosition.x / fieldwidth;
- int y = cursorPosition.y / fieldwidth;
- Event event;
- while (window.pollEvent(event))
- {
- if (event.type == Event::Closed) {
- // тогда закрываем его
- window.close();
- }
- if (event.type == Event::MouseButtonPressed) {
- if (event.key.code == Mouse::Left) {
- gridview[x][y] = gridLogic[x][y];
- }
- else if (event.key.code == Mouse::Right) {
- gridview[x][y] = 11;
- }
- }
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 10; j++) {
- sp.setTextureRect(IntRect(gridview[i][j] * fieldwidth, 0, fieldwidth, fieldwidth));
- sp.setPosition(i * fieldwidth, j * fieldwidth);
- window.draw(sp);
- }
- }
- window.display();
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment