Hey guys! I found this site today and was wondering if you guys could help me out here. My teacher assigned us this homework assignment today. I was working on my code and was pretty deep into it, so I didn't here him explaining how to do it. He's kind of an a-hole, so he didn't repeat himself. But here's basically how it goes.

I have a box. Now in that box, i have an x in the middle. I need to make that x move, not jump, move to the bottom right, then move across to the bottom left, move diagonally to the top right, move across to the top left, and move diagonally back to the starting point. And I need to keep it moving forever in a loop, but I can use only one loop. And the user must be able to stop the x from moving by hitting the space bar and then let it go by hitting it again

Can someone tell me how this works?

Nobody? Please help! This must be an easy program. I've only been in Pascal for two months. If it helps, I figured out that I need a while do statement. Also, I can't use functions or procedures. He hasn't taught us those yet.

note this wont run - it is just pseudo code showing the method only

// define the start conditions

// size of box
xmin = 0
ymin = 0
xmax = 100
ymax = 100
//movement each loop
xmove = 1
ymove = 1
// initial position
x = xmax / 2
y = ymax /2

repeat
// move it
x = x + xmove
y = y + ymove
// show it
show_x
// see if we are past the bottom right corner
if ( x > xmax ) and ( y > ymax ) then
begin
// if so, then start moving left
x = -1
y = 0
end else
// see if we are past bottom left corner
if ( x < xmin ) and ( y > ymax ) then
begin
// ok, start moving up & to right
x = +1
y = -1
end else
// you get the idea
if ( x > xmax ) and ( y < ymin ) then
begin
x = -1
y = 0
end
else if ( x < xmin ) and ( y < ymin ) then
begin
x = 1
y = 1
end
// repeat till user presses a key
until keypressed = space

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.