fork download
  1. int HexagonBoard::getHexDistance(const sf::Vector2i& Tile1, const sf::Vector2i& Tile2) const {
  2. int retVal;
  3. //Relativkoordinaten zum Punkt 0, 0
  4. sf::Vector2i relToZeroInHexa(Tile1.x-Tile2.x, Tile1.y-Tile2.y);
  5.  
  6. //Differnz bilden
  7. sf::Vector2i diffInHexa(relToZeroInHexa.x, relToZeroInHexa.y);
  8.  
  9. //Umrechnung auf Mittelpunktskoordinaten/Dreieckskoordinaten
  10. //Dabei gerade und ungerade Reihen beachten
  11. if(Tile1.y % 2) {
  12. diffInHexa.x=-2*diffInHexa.x;
  13. } else {
  14. diffInHexa.x=2*diffInHexa.x;
  15. }
  16.  
  17. //Zusätzliche Verschiebung berücksichtigen, weil y-Achse im Zick-Zack läuft
  18. if(abs(relToZeroInHexa.y) % 2) {
  19. diffInHexa.x -=1;
  20. }
  21.  
  22. //Relativkoordinaten zum Punkt 0, 0
  23. sf::Vector2i relToZeroInTriangles(diffInHexa.x, relToZeroInHexa.y);
  24.  
  25. int m=( (relToZeroInTriangles.x <= 0 ? -1 : 1)*relToZeroInTriangles.x) - abs(diffInHexa.y);
  26. return (m < 0 ? abs(diffInHexa.y) : m/2.f + abs(diffInHexa.y) );
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: ‘HexagonBoard’ has not been declared
prog.cpp:1: error: expected ‘,’ or ‘...’ before ‘::’ token
prog.cpp:1: error: ISO C++ forbids declaration of ‘sf’ with no type
prog.cpp:1: error: non-member function ‘int getHexDistance(int)’ cannot have cv-qualifier
prog.cpp: In function ‘int getHexDistance(int)’:
prog.cpp:4: error: ‘sf’ is not a class or namespace
prog.cpp:4: error: expected `;' before ‘relToZeroInHexa’
prog.cpp:7: error: ‘sf’ is not a class or namespace
prog.cpp:7: error: expected `;' before ‘diffInHexa’
prog.cpp:11: error: ‘Tile1’ was not declared in this scope
prog.cpp:12: error: ‘diffInHexa’ was not declared in this scope
prog.cpp:14: error: ‘diffInHexa’ was not declared in this scope
prog.cpp:18: error: ‘relToZeroInHexa’ was not declared in this scope
prog.cpp:18: error: ‘abs’ was not declared in this scope
prog.cpp:19: error: ‘diffInHexa’ was not declared in this scope
prog.cpp:23: error: ‘sf’ is not a class or namespace
prog.cpp:23: error: expected `;' before ‘relToZeroInTriangles’
prog.cpp:25: error: ‘relToZeroInTriangles’ was not declared in this scope
prog.cpp:25: error: ‘diffInHexa’ was not declared in this scope
prog.cpp:25: error: ‘abs’ was not declared in this scope
prog.cpp:2: warning: unused variable ‘retVal’
stdout
Standard output is empty