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?

9 Years
Discussion Span
Last Post by jackkenyon

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.


how about this sort of loop
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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.