Microsoft Small Basic

Program Listing: CBP647
'So the program will always react to a button-click event:
Controls.ButtonClicked = ButtonClicked

'First Screen where instructions are shown
''Graphics Window basic setup (Size and positioning)
GraphicsWindow.Width = 500
GraphicsWindow.Height = 500
GraphicsWindow.Left = (Desktop.Width-500)/2
GraphicsWindow.Top = (Desktop.Height-500)/2

''Graphics Window colours and controls, text and text size, and also a box around instructions.

'''Colours
GraphicsWindow.BackgroundColor = "White"
GraphicsWindow.BrushColor = "Black"

'''Text size
GraphicsWindow.FontSize = 17

'''Text (AKA Instructions)
GraphicsWindow.DrawText(5, 40, "You will be shown one rectangle. This tool will measure")
GraphicsWindow.DrawText(5, 60, "your response-time to it showing on screen. Try")
GraphicsWindow.DrawText(5, 80, "to click the left mouse button as soon as the rectangle")
GraphicsWindow.DrawText(5, 100, "appears.")

'''Addition to End button
GraphicsWindow.DrawText(150, 470, "Or you can")

'''Box around instructions

''''Box Colour
GraphicsWindow.PenColor = "DarkGray"

''''Thickness of rectangle lines
GraphicsWindow.PenWidth = 2

''''Box itself
GraphicsWindow.DrawRectangle(2, 38, 496, 86)

'''Start Button
''''TextSize
GraphicsWindow.FontSize = 135

''''Button Caption Colour
GraphicsWindow.BrushColor = "DarkGreen"

''''Button
Start = Controls.AddButton("START!", 0, 210)
Controls.SetSize(Start, 500, 250)

'''End Button
''''Text Size
GraphicsWindow.FontSize = 20

''''Button Caption Colour
GraphicsWindow.BrushColor = "Red"

''''Button
End = Controls.AddButton("End Application", 250, 460)
Controls.SetSize(End, 250, 40)




'Game Subroutine
Sub Game
GraphicsWindow.Clear()
ElapsedTime = ""
Program.Delay(100)
GraphicsWindow.MouseDown = MouseDown
Timer.Interval = 10
Width = Math.GetRandomNumber(400)
Height = Math.GetRandomNumber(Width/3)
Program.Delay(Math.GetRandomNumber(3000))
GraphicsWindow.FillRectangle(Math.GetRandomNumber(Width-20), Math.GetRandomNumber(Height-20), Width, Height)
Timer.Tick = Tick
EndSub

'Button Click subroutine
Sub ButtonClicked
If Controls.LastClickedButton = Start Then
Game()
ElseIf Controls.LastClickedButton = End Then
Program.End()
ElseIf Controls.LastClickedButton = Again Then
Game()
EndIf
EndSub

'Tick Sub
Sub Tick
ElapsedTime = ElapsedTime+10
EndSub

'Mouse Click Event
Sub MouseDown
If Mouse.IsLeftButtonDown = "True" Then
Timer.Pause()
Program.Delay(500)
EndingScreen()
EndIf
EndSub

'Last screen of app
Sub EndingScreen
Response = ElapsedTime/100
GraphicsWindow.Clear()
GraphicsWindow.DrawText(10, 50, "Reponse Time: "+Response+" seconds.")

End = Controls.AddButton("End Application", 10, 200)
Controls.SetSize(End, 250, 40)

GraphicsWindow.BrushColor = "DarkGreen"
Again = Controls.AddButton("Try Again", 10, 150)
Controls.SetSize(Again, 250, 40)
EndSub