Mouse Commands
Author |
Message |
jakey140
|
Posted: Tue Dec 19, 2006 7:44 pm Post subject: Mouse Commands |
|
|
I Am trying to write a program using procedures (title, userInput, goodBye) that will display three different sized squares on the screen all in a row, each a different colour, so that when the user clicks on the squares, the program will display a message stating the size of the square (small, medium or large, and then exit when the user clicks on the word Exit, displayed in a rectangle at the lower centre of the screen... Any Ideas or starting points? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
uberwalla
|
Posted: Tue Dec 19, 2006 7:56 pm Post subject: (No subject) |
|
|
my idea of where to start would be the Turing Walkthrough. take a look at the mouse.where command. also theres always the turing reference. |
|
|
|
|
|
jakey140
|
Posted: Tue Dec 19, 2006 11:05 pm Post subject: (No subject) |
|
|
heres what I have so far.... I just need to make a few minor adjustments and I should Be set...
code: |
%Declatation Section
var finished : boolean := false
var rangex, rangey, button : int
%set screen mode and size
setscreen ("graphics")
%Program Title
procedure title
cls
locate (1, 14)
put "Block Size"
end title
%Program introduction
procedure introduction
title
locate (3, 1)
put "Click on any one of the boxes"
end introduction
procedure display
%draw three boxes on the screen
drawfillbox (20, 20, 40, 40, green)
drawfillbox (60, 20, 100, 60, yellow)
drawfillbox (120, 20, 180, 80, red)
drawbox (290, 0, 350, 30, 0)
locatexy (300, 15)
put "exit"
procedure display
mousewhere (rangex, rangey, button)
if button = 1 then
if rangex >= 20 and rangex <= 40 and rangey >= 20 and rangey <= 40 then
locate (16, 1)
put "You have clicked the small square"
elsif rangex >= 60 and rangex <= 100 and rangey >= 20 and rangey <= 60 then
locate (16, 1)
put "You have clicked the meduim square"
elsif rangex >= 120 and rangex <= 180 and rangey >= 20 and rangey <= 80 then
locate (16, 1)
put "You have cliked the large square"
elsif rangex >= 290 and rangex <= 350 and rangey >= 0 and rangey <= 30 then
finished := true
else
locate (10, 1)
put "You clicked at: ", rangex, "", rangey
end if
end if
end display
%Main Program
introduction
loop
display
exit when finished
end loop
|
|
|
|
|
|
|
uberwalla
|
Posted: Tue Dec 19, 2006 11:18 pm Post subject: (No subject) |
|
|
ok well i was going to run to see what you had to try to give ya some help but then i noticed this...
Quote:
procedure display
%draw three boxes on the screen
drawfillbox (20, 20, 40, 40, green)
drawfillbox (60, 20, 100, 60, yellow)
drawfillbox (120, 20, 180, 80, red)
drawbox (290, 0, 350, 30, 0)
locatexy (300, 15)
put "exit"
procedure display
mousewhere (rangex, rangey, button)
u declare display twice and dont even end the first one. which one is supposed to be used? |
|
|
|
|
|
jakey140
|
Posted: Tue Dec 19, 2006 11:20 pm Post subject: (No subject) |
|
|
the bottom one... ive tried including the drawfillbox's in the display procedure as well but for some reason it messes up... take a look |
|
|
|
|
|
uberwalla
|
Posted: Tue Dec 19, 2006 11:27 pm Post subject: (No subject) |
|
|
ok i cleaned up your code a bit so it dont make long boxes and repeating word 'exit' going up the screen...
code: |
%Declatation Section
var finished : boolean := false
var rangex, rangey, button : int
var font := Font.New ("Arial:10")
%set screen mode and size
setscreen ("graphics")
%Program Title
procedure title
cls
locate (1, 14)
put "Block Size"
end title
%Program introduction
procedure introduction
title
locate (3, 1)
put "Click on any one of the boxes"
end introduction
procedure display
%draw three boxes on the screen
drawfillbox (20, 20, 40, 40, green)
drawfillbox (60, 20, 100, 60, yellow)
drawfillbox (120, 20, 180, 80, red)
drawbox (290, 0, 350, 30, 0)
Font.Draw ("Exit", 300, 15, font, 7)
mousewhere (rangex, rangey, button)
if button = 1 then
if rangex >= 20 and rangex <= 40 and rangey >= 20 and rangey <= 40 then
locate (16, 1)
put "You have clicked the small square"
elsif rangex >= 60 and rangex <= 100 and rangey >= 20 and rangey <= 60 then
locate (16, 1)
put "You have clicked the meduim square"
elsif rangex >= 120 and rangex <= 180 and rangey >= 20 and rangey <= 80 then
locate (16, 1)
put "You have cliked the large square"
elsif rangex >= 290 and rangex <= 350 and rangey >= 0 and rangey <= 30 then
finished := true
else
locate (10, 1)
put "You clicked at: ", rangex, "", rangey
end if
end if
end display
%Main Program
introduction
loop
display
exit when finished
View.Update
end loop
|
what was happening is for some reason the locatexy was screwing with the prog. also i added font.draw instead so it dont put a white strip over the boxes. |
|
|
|
|
|
jakey140
|
Posted: Tue Dec 19, 2006 11:36 pm Post subject: (No subject) |
|
|
awsome... thanks alot ... but how would I make it so that the font was just normal, not arial 10?? |
|
|
|
|
|
ZeroPaladn
|
Posted: Wed Dec 20, 2006 8:47 am Post subject: (No subject) |
|
|
you have to declare a font for Font.Draw. If you are looking for the font that the run window uses for the put statement, then just click on file, then preferences, then go to Run Window, and see the font there. Insert it into your font variable, and there you have it.
Here, I'll be nice...
Turing: | var font : int := Font.New ("Courier New:10") |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|