[SFML] Checkers

How do I create a 2d array and move the checkerpieces? I only need to move the pieces forward and not backwards. I have this so far:

int main(int argc, char const** argv)
{
const int MAX_ROW = 8;
const int MAX_COLUMN = 8;
// Create the main window that is 400 pixels wide and 400 pixels tall
sf::RenderWindow window(sf::VideoMode(400, 400), "Checkers");

vector<sf::RectangleShape> vec;
vector<sf::CircleShape> vec1;

for (int i = 0; i < MAX_ROW; i++) { //loops through all the rows
for (int j = 0; j < MAX_COLUMN; j++) { //loops through all the columns
if (i % 2 == 0 && j % 2 == 0) { //Even locations of the board
int x = i * 50;
int y = j * 50;

sf::RectangleShape whitecolor(sf::Vector2f(50, 50)); //White rectangles for the board
whitecolor.setFillColor(sf::Color::White);
whitecolor.setPosition(sf::Vector2f(x, y));
vec.push_back(whitecolor);
}

//Odd locations of the board
if (i % 2 != 0 && j % 2 != 0) {
int x = i * 50;
int y = j * 50;

sf::RectangleShape whitecolor(sf::Vector2f(50, 50)); //White rectangles for the board
whitecolor.setFillColor(sf::Color::White);
whitecolor.setPosition(sf::Vector2f(x, y));
vec.push_back(whitecolor);
}
}
}

//First red checker row
for (int i = 0; i < MAX_ROW; i++) {
int x = (100 * i) - 50;

sf::CircleShape circle;
circle.setRadius(25);
circle.setPosition(x, 0);
circle.setFillColor(sf::Color::Red);
vec1.push_back(circle);
}

//First blue checker row
for (int i = 0; i < MAX_ROW; i++) {
int x = (100 * i) - 50;

sf::CircleShape circle;
circle.setRadius(25);
circle.setPosition(x, 300);
circle.setFillColor(sf::Color::Blue);
vec1.push_back(circle);
}

//Second red checker row
for (int i = 0; i < MAX_ROW; i++) {
int x = (100 * i);

sf::CircleShape circle;
circle.setRadius(25);
circle.setPosition(x, 50);
circle.setFillColor(sf::Color::Red);
vec1.push_back(circle);
}

//Second blue checker row
for (int i = 0; i < MAX_ROW; i++) {
int x = (100 * i);

sf::CircleShape circle;
circle.setRadius(25);
circle.setPosition(x, 350);
circle.setFillColor(sf::Color::Blue);
vec1.push_back(circle);
}

//Third red checker row
for (int i = 0; i < MAX_ROW; i++) {
int x = (100 * i) + 50;

sf::CircleShape circle;
circle.setRadius(25);
circle.setPosition(x, 100);
circle.setFillColor(sf::Color::Red);
vec1.push_back(circle);
}

//Third blue checker row
for (int i = 0; i < MAX_ROW; i++) {
int x = (100 * i);

sf::CircleShape circle;
circle.setRadius(25);
circle.setPosition(x, 250);
circle.setFillColor(sf::Color::Blue);
vec1.push_back(circle);
}

// Create a graphical text to display
////////////////// Leave This as is ////////////////////////////////////
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window: exit
if (event.type == sf::Event::Closed) {
window.close();
}

// Escape pressed: exit
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
window.close();
}
}


////////////////// End of Leave This ////////////////////////////////////
// Clear screen
window.clear();

/*
Draws every single entity in the bar graph
*/


for (auto& rect : vec)
{
window.draw(rect);

}

for (auto& rect1 : vec1)
{
window.draw(rect1);

}



// Update the window
window.display();


}

return EXIT_SUCCESS;
}
Topic archived. No new replies allowed.