Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Tuing Making box not go out of the screen problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jasonhan416




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
ecookman




PostPosted: 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
jasonhan416




PostPosted: 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?
DanielG




PostPosted: 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.
copthesaint




PostPosted: 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

code:
var chars : array char of boolean

loop
Input.KeyDown(chars)
if chars (KEY_DOWN_ARROW) then
put "down"
elsif chars (KEY_UP_ARROW) then
put "up"
elsif chars (KEY_RIGHT_ARROW) then
put "right"
elsif chars (KEY_LEFT_ARROW) then
put "left"
end if
if chars (KEY_LEFT_ARROW) = true and chars (KEY_UP_ARROW) = true then
put "up-left"
elsif chars (KEY_LEFT_ARROW) = true and chars (KEY_DOWN_ARROW) = true then
put "down-left"
elsif chars (KEY_RIGHT_ARROW) = true and chars (KEY_UP_ARROW) = true then
put "up-right"
elsif chars (KEY_RIGHT_ARROW) = true and chars (KEY_DOWN_ARROW) = true then
put "down-right"
end if
View.Update
delay (100)
end loop

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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: