Microsoft Small Basic

Program Listing: XLB916-0
' XLB916-0
GraphicsWindow.Title = "Challenge of the Month - May 2013 | Community Suggestion 3 (2)"
gw = GraphicsWindow.Width
gh = GraphicsWindow.Height
GraphicsWindow.BackgroundColor = "Black"
DrawStars()
GraphicsWindow.BrushColor = "DimGray"
GraphicsWindow.FillRectangle(0, 350, gw, gh - 350) ' land
GraphicsWindow.BrushColor = "#999999"
GraphicsWindow.FillTriangle(100, 200, 300, 200, 200, 50) ' wall (door)
GraphicsWindow.FillRectangle(100, 200, 200, 200)
GraphicsWindow.BrushColor = "#660000"
GraphicsWindow.FillTriangle(200, 50, 300, 50, 300, 200) ' roof
GraphicsWindow.FillRectangle(300, 50, 100, 150)
GraphicsWindow.FillTriangle(400, 50, 400, 200, 500, 200)
GraphicsWindow.BrushColor = "#cccccc"
GraphicsWindow.FillRectangle(300, 200, 200, 200) ' wall (window)
GraphicsWindow.BrushColor = "#ffffee"
GraphicsWindow.FillRectangle(350, 200, 100, 150) ' window
GraphicsWindow.FillRectangle(150, 200, 100, 200) ' door
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "#000000"
window = Shapes.AddRectangle(100, 150)
Shapes.Move(window, 350, 200)
room = Shapes.AddRectangle(100, 200)
Shapes.Move(room, 150, 200)
GraphicsWindow.BrushColor = "#442200"
door = Shapes.AddRectangle(100, 200)
Shapes.Move(door, 150, 200)
LightOff()
'DrawGrid()
on = "False"
open = "False"
GraphicsWindow.MouseDown = OnMouseDown
Sub OnMouseDown
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
If 150 <= mx And mx <= 250 And 200 <= my And my <= 400 Then
If open Then
CloseDoor()
open = "False"
Else
OpenDoor()
open = "True"
EndIf
ElseIf 350 <= mx And mx <= 450 And 200 <= my And my <= 350 Then
If on Then
LightOff()
on = "False"
Else
LightOn()
on = "True"
EndIf
EndIf
EndSub
Sub OpenDoor
Shapes.Move(door, 50, 200)
EndSub
Sub CloseDoor
Shapes.Move(door, 150, 200)
EndSub
Sub LightOn
Shapes.SetOpacity(window, 10)
Shapes.SetOpacity(room, 10)
EndSub
Sub LightOff
Shapes.SetOpacity(window, 80)
Shapes.SetOpacity(room, 80)
EndSub
Sub DrawStars
For i = 1 To 100
x = Math.GetRandomNumber(GraphicsWindow.Width)
y = Math.GetRandomNumber(GraphicsWindow.Height)
GraphicsWindow.SetPixel(x, y, "#ffffff")
EndFor
EndSub
Sub DrawGrid
GraphicsWindow.PenWidth = 1
GraphicsWindow.PenColor = "Gray"
For x = 0 To gw Step 50
GraphicsWindow.DrawLine(x, 0, x, gh)
EndFor
For y = 0 To gh Step 50
GraphicsWindow.DrawLine(0, y, gw, y)
EndFor
EndSub