Question: Hi there! I have to code the game checkers using c++ and SFML for my introductory CompSci class and it is not making much sense.
Hi there! I have to code the game checkers using c++ and SFML for my introductory CompSci class and it is not making much sense. I have
#include
#include
#include
#include
using namespace std;
int main(int argc, char const** argv)
{
const int MaxRow = 8;
const int MaxCol = 8;
int x = 0;
int y = 0;
// Create the variable for the window side
double windowside = 600; //initialize variable for the window size
sf::RenderWindow window(sf::VideoMode(windowside, windowside), "Sean's Game of Checkers");
vector
vector
for (int y=0; y < MaxRow; y++) //loop through all of the rows
{
for (int x = 0; x< MaxCol; x++) //loop through all of the columns
{
if ((x + y) % 2 ==0) //even locations on the board
{
sf::RectangleShape RedColorSquares(sf::Vector2f (windowside/8, windowside/8)); //make size of square 1/8 of the board
RedColorSquares.setFillColor(sf::Color::Red); //color square Red
RedColorSquares.setPosition(sf::Vector2f(((x*windowside)/8), (y*windowside)/8)); //Set position of square
if ((x+y) % 2 ==1) // odd locations on the board
{
sf::RectangleShape BlackColor(sf::Vector2f (windowside/8, windowside/8));
BlackColor.setFillColor(sf::Color::Black);
BlackColor.setPosition(sf::Vector2f(((x*windowside)/8),(y*windowside)/8));
}
}
}
}
//First Blue checker row
for(int x = 0; x< MaxRow; x++)
{
sf::CircleShape BlueCheckers; // loop through all of the circles
BlueCheckers.setRadius(windowside/18); //circle is slightly smaller than its outer square
BlueCheckers.setPosition(x *windowside/16, y * windowside / 16 ); // Centers the circles in the middle of the square
BlueCheckers.setFillColor(sf::Color::Blue); //colors the circles blue
vec1.push_back(BlueCheckers);
}
// Start the game loop
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();
}
}
// Clear screen
window.clear(sf::Color::Black);
// Draw the string
window.draw(text);
// Update the window
window.display();
}
return 0;
}.
This is how i tried to design the board but it isn't right and won't load. How do I build the checkerboard? And how do i animate the pieces so that you can make moves?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
