Computer Science Canada Tuing Making box not go out of the screen problem |
Author: | jasonhan416 [ Sun Dec 14, 2008 2:30 pm ] |
Post subject: | Tuing Making box not go out of the screen problem |
The program suppose to move when i use arrow keys and i understand that ACII 200 means up 208 means down 205 means -> 203 means <- My problem is this i need make a program that the box doesn't go outside the size of the screen or distort. I need to modify it. Please help me. here's the code %Declaration Section var startpointx, startpointy : int := 0 var endpointx, endpointy : int := 50 var key : string (1) %Set screren mode and size setscreen ("graphics :400;400") setscreen ("noecho") setscreen ("ncursor") setscreen ("offscreenonly") procedure display drawfillbox (startpointx, startpointy, endpointx, endpointy, 0) drawfillbox (startpointx + 1, startpointy + 1, endpointx - 1, endpointy - 1, blue) getch (key) if key = chr (200) then startpointy := startpointy + 1 endpointy := endpointy + 1 elsif key = chr (208) then startpointy := startpointy - 1 endpointy := endpointy - 1 elsif key = chr (205) then startpointx := startpointx + 1 endpointx := endpointx + 1 else if key = chr (203) then startpointx := startpointx - 1 endpointx := endpointx - 1 end if end if View.Update end display %Main program loop display exit when key = chr (27) end loop |
Author: | ecookman [ Sun Dec 14, 2008 2:41 pm ] |
Post subject: | RE:Tuing Making box not go out of the screen problem |
use maxx and maxy to find the max of the corners example: put maxx put maxy ^ | | will show you the max corr. of the x and y then an restricting it to the max corrs. i think this is done using an array of boolean pretymuch if {the box is in the points} = true if {the box is outside of the points} = false {get it to stop there} ... i think |
Author: | jasonhan416 [ Sun Dec 14, 2008 3:06 pm ] |
Post subject: | Re: RE:Tuing Making box not go out of the screen problem |
ecookman @ Sun Dec 14, 2008 2:41 pm wrote: use maxx and maxy to find the max of the corners
example: put maxx put maxy ^ | | will show you the max corr. of the x and y then an restricting it to the max corrs. i think this is done using an array of boolean pretymuch if {the box is in the points} = true if {the box is outside of the points} = false {get it to stop there} ... i think oh... okay.. where in the line do you use maxx and maxy. and cna you give me soem examples? |
Author: | DanielG [ Sun Dec 14, 2008 4:07 pm ] |
Post subject: | RE:Tuing Making box not go out of the screen problem |
jasonhan416, instead of using the key`s ascii value use turing`s KEY_UP_ARROW, KEY_DOWN_ARROW ..., they make the code easier to understand. |
Author: | copthesaint [ Sun Dec 14, 2008 4:17 pm ] | ||
Post subject: | Re: Tuing Making box not go out of the screen problem | ||
this is the easiest way and some extra keys
plus you can alsouse numbers ('#') or letters ('a") when using letters use lower case if you use upper case you will have to use shift while using the button |