Каким образом можно сделать так чтобы метод не повторялся второй и более раз?

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
 
class Class {
private:
    RenderWindow window;
    Texture texture;
    String File;
    int  b = 1;
    int mass[3][3] = { 2 };
    Sprite fon, kr[9], nol[9];
public:
    Class(String F):window(VideoMode(350,350), "X&O"){
        File = F;
        texture.loadFromFile("https://www.cyberforum.ru/images/" + File);
        fon.setTexture(texture);  fon.setTextureRect(IntRect(0,0,350,350));  fon.setPosition(0, 0);
        kr[0].setTexture(texture);  kr[0].setTextureRect(IntRect(350, 0, 100, 100));
        nol[0].setTexture(texture); nol[0].setTextureRect(IntRect(355, 100, 100, 100));
        for (int i = 0; i < 9; i++) {
            kr[i] = kr[0]; nol[i] = nol[0];
        }
    }
    void bol() {
        if (b == 1)
            b = 0;
        else
            b = 1;
    }
    void mouse(int x, int y, int ox, int oy, int i, int j, int xp, int yp, int f) {     // функция mouse
        Vector2i localPosition = Mouse::getPosition(window);
        if (Mouse::isButtonPressed(Mouse::Left)) {
            std::cout << "click ";
            if (localPosition.x <= x && localPosition.y <= y && localPosition.x >= ox && localPosition.y >= oy) {
                if (b == 1) 
                    mass[i][j] = 1; kr[f].setPosition(xp, yp);
                if (b == 0)
                    mass[i][j] = 0; nol[f].setPosition(xp, yp);
            }
        }
        if (mass[i][j] == 1)
            window.draw(kr[f]);
        if (mass[i][j] == 0)
            window.draw(nol[f]);
        bol();
    }
    void IsOpen() {
        while (window.isOpen()) {
            Event event;
            while (window.pollEvent(event)) {
                if (event.type == Event::Closed)
                    window.close();
            }
            window.setFramerateLimit(30);
            window.clear();
            window.draw(fon);
            mouse( 116, 112,  0,   0,  0, 0,  5,   5,  0);// она может вызваться до 9 раз но одна и та же не должна 
            mouse( 235, 112, 120,  0,  0, 1, 125,  5,  1);// вызываться дважды
            mouse( 350, 112, 240,  0,  0, 2, 240,  5,  2);
            mouse( 116, 237,  0,  117, 1, 0,  5,  125, 3);
            mouse( 235, 237, 120, 117, 1, 1, 125, 125, 4);
            mouse( 350, 237, 240, 117, 1, 2, 240, 125, 5);
            mouse( 116, 350,  0,  240, 2, 0,  5,  245, 6);
            mouse( 235, 350, 120, 240, 2, 1, 125, 245, 7);
            mouse( 350, 350, 240, 240, 2, 2, 240, 245, 8);
            window.display();
        }
    }
};
 
void main() {
    Class c("kn.png");
    c.IsOpen();
}

Мне нужно чтобы выполнение каждого метода mouse(); не повторялась более чем один раз.


Ответы (0 шт):