-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase.cpp
34 lines (32 loc) · 1.38 KB
/
case.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "case.h"
#include <cmath>
Case::Case() : sf::Text() {}
void Case::exchange(Case &c, sf::RenderWindow& window, Cadre cadre)
{
float pos_tampon;
std::string str;
// Les nombres sont-ils dans la même ligne ?
if (abs(c.getPosition().y - getPosition().y) < 50) // 50 est une valeur choisie arbitrairement
{
// Les nombres sont-ils dans des cases adjacentes ?
if (abs(c.getPosition().x - getPosition().x) < (window.getDefaultView().getSize().x - cadre.getLargeur()) / 2 + 2 * cadre.getLargeur() / 8)
{
// On prend soin de prendre en compte le fait que la largeur du nombre en pixel peut changer (getGlobalBounds().width)
pos_tampon = c.getPosition().x + c.getGlobalBounds().width / 2;
c.setPosition(getPosition().x + getGlobalBounds().width / 2 - c.getGlobalBounds().width / 2, c.getPosition().y);
setPosition(pos_tampon - getGlobalBounds().width / 2, getPosition().y);
}
}
// Les nombres sont-ils dans la même colonne ?
if (abs(c.getPosition().x - getPosition().x) < 50)
{
// Les nombres sont-ils dans des cases adjacentes ?
if (abs(c.getPosition().y - getPosition().y) < (window.getDefaultView().getSize().y - cadre.getLargeur()) / 2 + 2 * cadre.getLargeur() / 8)
{
// Ici, la hauteur ne change pas d'un nombre à un autre <
pos_tampon = c.getPosition().y;
c.setPosition(c.getPosition().x, getPosition().y);
setPosition(getPosition().x, pos_tampon);
}
}
}