hello i am new to the forum as well as sfml and mostly new to programming. just wondering if someone can help me figure out what i did wrong in making a grid, i can only get to be 2x2.
#include <SFML/Graphics.hpp>
int main()
{
int columns = 3;
int rows = 3;
sf::RenderWindow window(sf::VideoMode(800, 600), "TicTacToe");
sf::RectangleShape grid[columns][rows];
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
for(int i=0;i<columns;i++){
for(int j=0;j<rows;j++){
sf::Vector2f cellSize(200.0f, 200.0f);
sf::Vector2f cellPos(5.0f,5.0f);
sf::Vector2f cellPos2(5.0f,5.0f);
grid[i][j].setSize(cellSize);
grid[i][j].setOutlineColor(sf::Color::Blue);
grid[i][j].setOutlineThickness(5.0f);
if(i%2==1 && j%2==1){
grid[i][j].setPosition(cellPos.x + cellSize.x, cellPos.y + cellSize.y);
}else if(i%2==1 && j%2==0){
grid[i][j].setPosition(cellPos.x + cellSize.x, cellPos.y);
}else if(i%2==0 && j%2==1){
grid[i][j].setPosition(cellPos.x, cellPos.y + cellSize.y);
}else{
grid[i][j].setPosition(cellPos);
}
window.draw(grid[i][j]);
}
}
window.display();
}
return 0;
}