void drawGrid(sf::RenderWindow &window, bool change) { sf::View view = window.getView(); static std::vector<sf::Vertex> Line; if(change) { xSep = getSep(view.getSize().x, window.getSize().x); ySep = getSep(view.getSize().y, window.getSize().y); // change = false; // val(xSep); // val(ySep); Line.clear(); gridLine(view, xSep * 0.25, ySep * 0.25, sf::Color(0, 0, 0, 63), Line); gridLine(view, xSep, ySep, sf::Color(0, 0, 0, 100), Line); } window.draw(&Line[0], Line.size(), sf::Lines); //gridLable(window, xSep, ySep, sf::Color::Black); xyAxis(window); }
void TicTacToe::draw(sf::RenderTarget& renderTarget) { sf::RectangleShape gridLine(sf::Vector2f(3*CASE_SIZE, 4)); gridLine.setTexture(&Texture().GetRessource("Data/Image/border.png")); Texture().GetRessource("Data/Image/border.png").setRepeated(true); gridLine.setTextureRect(sf::IntRect(0,0,0,4)); gridLine.setRotation(90); //draw verticales lines for(unsigned int i =0; i< GRID_SIZE+1; i++) { gridLine.setPosition(i*CASE_SIZE + OFFSET_X, OFFSET_Y); renderTarget.draw(gridLine); } gridLine.setRotation(0); //draw horizontal lines for(unsigned int i =0; i< GRID_SIZE+1; i++) { gridLine.setPosition(OFFSET_X, i*CASE_SIZE + OFFSET_Y); renderTarget.draw(gridLine); } sf::Sprite spriteX, spriteO; spriteX.setTexture(Texture().GetRessource("Data/Image/x.png")); spriteO.setTexture(Texture().GetRessource("Data/Image/o.png")); for(unsigned int i = 0; i< GRID_SIZE; i++) { for(unsigned int j =0; j< GRID_SIZE; j++) { //x_and_o.setPosition(OFFSET_X*2 + j*CASE_SIZE, OFFSET_Y*2 + i*CASE_SIZE); switch(m_grid[i][j]) { case TicTacToe::PLAYERX : spriteX.setPosition(OFFSET_X*2 + j*CASE_SIZE, OFFSET_Y*2 + i*CASE_SIZE); renderTarget.draw(spriteX); break; case TicTacToe::PLAYERO : spriteO.setPosition(OFFSET_X*2 + j*CASE_SIZE, OFFSET_Y*2 + i*CASE_SIZE); renderTarget.draw(spriteO); break; default: break; } } } if(m_turn == TicTacToe::PLAYERX) { spriteX.setPosition(m_lastPointerLoc); spriteX.setScale(0.3, 0.3); renderTarget.draw(spriteX); } else { spriteO.setPosition(m_lastPointerLoc); spriteO.setScale(0.3, 0.3); renderTarget.draw(spriteO); } }