Проблемы для перекрытия в 2-D массив символов
I am having trouble with a part of a program that takes a dynamically allocated object called userRect and checks for it overlapping on an array of chars arranged in the shape of a rectangle. The other rectangles rect[0] and rect[1] are randomly placed on a imaginary grid in a console window. rect[0] prints out with '0' rect[1] prints out with '1' userRect prints out with '#' if no overlap is present. userRect prints out with '+' at each char in the array that is overlapping another object. The object userRect is movable with the w,a,s,d keys. What is supposed to happen is when the user moves the userRect object and it overlaps another rect object. Each character that overlaps is replaced with a '+'. The program is not printing a '+' when the userRect is overlapping another rectangle. Can anyone point out what is causing this? I believe it to be a problem in the function bool isOverlapping always return false. This causes the if statement if (userRect->isOverlapping(rect[i])) to always return false causing the default print out of the '#'. Am I on track with my theory? Here is a sample of my code with most parts cut out for ease of reading. bool isOverlapping(Rect const & r) const { return !(min.x >= r.max.x || max.x <= r.min.x || min.y >= r.max.y || max.y <= r.min.y); } int main() { Rect * userRect; const int rectSize =2; Rect rect[rectSize]; const int ARRAY_SIZE = 13; // size of userRect userRect = new Rect(); // set userRect->setMin(7, 5); userRect->setMax(10, 9); do { // draw rect[0].draw('0'); rect[1].draw('1'); for (int i = 0; i < ARRAY_SIZE; i++) { if (userRect->isOverlapping(rect[i])) { userRect->draw('+'); } else userRect->draw('#'); } return 0; }
Что я уже пробовал:
Я уже пробовал удалить ! символ перед оператором return для isOverlapping.
Я также попытался перевернуть знаки с <= на >= внутри оператора if в функции isOverlapping.