Help with Bjarne Stroustrup Chapter 13 Graphics Drill.

/*I don't know if I came to the right place for this. I am using Bjarne Stroustrup Programming, Principles and Practice using C++ and this is from a Drill in Chapter 13 - Graphics. I understand what is going on but I can't seem to get it to work. The last piece of the code is to move a 100*100 pixel image around 8*8 board of squares with each square measuring 100*100 pixels. The goal is to move the picture from one square to another when you click the Next button but my image jumps "weirdly". I hope somebody in here used the book and found a way to solve it.*/

#include "Graph.h"
#include "Simple_window.h"

int main()
{
using namespace Graph_lib;

Simple_window win(Point(0, 0), 800, 1000, "My Window");

Vector_ref<Graph_lib::Rectangle> board; //vector to hold the squares that make up the board

int s_counter = 0; //square counter

for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
board.push_back(new Graph_lib::Rectangle(Point(j * 100, i * 100), 100, 100));

win.attach(board[board.size() - 1]);
}
board[s_counter].set_fill_color(Color::red);
s_counter += 9;
} //loop to create and color diagonal squares


Image cover(Point(0, 0), "cover.jpg"); //new single image to move around the board

win.attach(cover);

for (int i = 0; i < 8; ++i)
{
for (int j = 0; j < 8; ++j)
{
cover.move(j * 100, i * 100);

win.wait_for_button();
}
}

}
Last edited on
Topic archived. No new replies allowed.