View.Set ("graphics:201;251,nobuttonbar,position:center;center")
%variables
var xmouse, ymouse, button : int
var num1, num2 : string := ""
var op : string := ""
var answer : int := 0
var font : int
%calculator look
drawfillbox (0, 200, 200, 250, yellow)
drawfillbox (0, 0, 200, 200, grey)
drawfillbox (0, 0, 50, 50, white)
drawbox (0,0,50,50,black)
drawbox (50, 0, 100, 50, black)
drawbox (100, 0, 150, 50, black)
drawbox (150, 0, 200, 50, black)
drawbox (0, 50, 50, 100, black)
drawbox (50, 50, 100, 100, black)
drawbox (100, 50, 150, 100, black)
drawbox (150, 50, 200, 100, black)
drawbox (0, 100, 50, 150, black)
drawbox (50, 100, 100, 150, black)
drawbox (100, 100, 150, 150, black)
drawbox (150, 100, 200, 150, black)
drawbox (0, 150, 50, 200, black)
drawbox (50, 150, 100, 200, black)
drawbox (100, 150, 150, 200, black)
drawbox (150, 150, 200, 200, black)
drawbox (0, 200, 200, 250, black)
%Calculator numbers
font := Font.New ("arial:18")
Font.Draw ("ESC", 0, 20, font, black)
Font.Draw ("0", 70, 20, font, black)
Font.Draw ("=", 120, 20, font, black)
Font.Draw ("/", 170, 20, font, black)
Font.Draw ("1", 20, 70, font, black)
Font.Draw ("2", 70, 70, font, black)
Font.Draw ("3", 120, 70, font, black)
Font.Draw ("*", 170, 70, font, black)
Font.Draw ("4", 20, 120, font, black)
Font.Draw ("5", 70, 120, font, black)
Font.Draw ("6", 120, 120, font, black)
Font.Draw ("-", 170, 120, font, black)
Font.Draw ("7", 20, 170, font, black)
Font.Draw ("8", 70, 170, font, black)
Font.Draw ("9", 120, 170, font, black)
Font.Draw ("+", 170, 170, font, black)
%Input
loop
loop
buttonwait ("down", xmouse, ymouse, button, button)
exit when xmouse > 0 and xmouse < 50 and ymouse > 0 and ymouse < 50
if xmouse > 50 and xmouse < 100 and ymouse > 0 and ymouse < 50 then
num1 := num1 + "0"
elsif xmouse > 0 and xmouse < 50 and ymouse > 50 and ymouse < 100 then
num1 := num1 + "1"
elsif xmouse > 50 and xmouse < 100 and ymouse > 50 and ymouse < 100 then
num1 := num1 + "2"
elsif xmouse > 100 and xmouse < 150 and ymouse > 50 and ymouse < 100 then
num1 := num1 + "3"
elsif xmouse > 0 and xmouse < 50 and ymouse > 100 and ymouse < 150 then
num1 := num1 + "4"
elsif xmouse > 50 and xmouse < 100 and ymouse > 100 and ymouse < 150 then
num1 := num1 + "5"
elsif xmouse > 100 and xmouse < 150 and ymouse > 100 and ymouse < 150 then
num1 := num1 + "6"
elsif xmouse > 0 and xmouse < 50 and ymouse > 150 and ymouse < 200 then
num1 := num1 + "7"
elsif xmouse > 50 and xmouse < 100 and ymouse > 150 and ymouse < 200 then
num1 := num1 + "8"
elsif xmouse > 100 and xmouse < 150 and ymouse > 150 and ymouse < 200 then
num1 := num1 + "9"
elsif xmouse > 150 and xmouse < 200 and ymouse > 0 and ymouse < 50 then
op := "/"
exit
elsif xmouse > 150 and xmouse < 200 and ymouse > 50 and ymouse < 100 then
op := "*"
exit
elsif xmouse > 150 and xmouse < 200 and ymouse > 100 and ymouse < 150 then
op := "-"
exit
elsif xmouse > 150 and xmouse < 200 and ymouse > 150 and ymouse < 200 then
op := "+"
exit
end if
drawfillbox (0, 200, 200, 250, yellow)
Font.Draw (num1, 10, 210, font, black)
end loop
exit when xmouse > 0 and xmouse < 50 and ymouse > 0 and ymouse < 50
loop
buttonwait ("down", xmouse, ymouse, button, button)
exit when xmouse > 0 and xmouse < 50 and ymouse > 0 and ymouse < 50
if xmouse > 50 and xmouse < 100 and ymouse > 0 and ymouse < 50 then
num2 := num2 + "0"
elsif xmouse > 0 and xmouse < 50 and ymouse > 50 and ymouse < 100 then
num2 := num2 + "1"
elsif xmouse > 50 and xmouse < 100 and ymouse > 50 and ymouse < 100 then
num2 := num2 + "2"
elsif xmouse > 100 and xmouse < 150 and ymouse > 50 and ymouse < 100 then
num2 := num2 + "3"
elsif xmouse > 0 and xmouse < 50 and ymouse > 100 and ymouse < 150 then
num2 := num2 + "4"
elsif xmouse > 50 and xmouse < 100 and ymouse > 100 and ymouse < 150 then
num2 := num2 + "5"
elsif xmouse > 100 and xmouse < 150 and ymouse > 100 and ymouse < 150 then
num2 := num2 + "6"
elsif xmouse > 0 and xmouse < 50 and ymouse > 150 and ymouse < 200 then
num2 := num2 + "7"
elsif xmouse > 50 and xmouse < 100 and ymouse > 150 and ymouse < 200 then
num2 := num2 + "8"
elsif xmouse > 100 and xmouse < 150 and ymouse > 150 and ymouse < 200 then
num2 := num2 + "9"
elsif xmouse > 150 and xmouse < 200 and ymouse > 0 and ymouse < 50 then
exit
elsif xmouse > 150 and xmouse < 200 and ymouse > 50 and ymouse < 100 then
exit
elsif xmouse > 150 and xmouse < 200 and ymouse > 100 and ymouse < 150 then
exit
elsif xmouse > 150 and xmouse < 200 and ymouse > 150 and ymouse < 200 then
exit
elsif xmouse > 100 and xmouse < 150 and ymouse > 0 and ymouse < 50 then
exit
end if
drawfillbox (0, 200, 200, 250, yellow)
Font.Draw (num2, 10, 210, font, black)
end loop
exit when xmouse > 0 and xmouse < 50 and ymouse > 0 and ymouse < 50
%Process
if op = "+" then
answer := strint (num1) + strint (num2)
elsif op = "-" then
answer := strint (num1) - strint (num2)
elsif op = "*" then
answer := strint (num1) * strint (num2)
elsif op = "/" then
answer := strint (num1) div strint (num2)
end if
drawfillbox (0, 200, 200, 250, yellow)
%Final Output
Font.Draw (intstr (answer), 10, 210, font, black)
num1 := ""
num2 := ""
op := ""
answer := 0
end loop
|