Microsoft Small Basic

Program Listing:
Embed this in your website
' Set up the graphics windows
GraphicsWindow.BackgroundColor = "Gray"
GraphicsWindow.Height = 600
GraphicsWindow.Width = 600

start:
' Set up the default font style
GraphicsWindow.FontBold = "True"
GraphicsWindow.FontName = "Courier New"
GraphicsWindow.FontSize = 300
GraphicsWindow.BrushColor = "Black"

' Enable the graphics window to respond to mouse and keyboard events.
GraphicsWindow.MouseDown = OnMouseDown
GraphicsWindow.KeyDown = OnKeyDown

pause = 20
win = "False"
canclick = "True" 'flag to only allow clicks when a new pair appear
p1score = 0
p2score = 0
targetscore = 5
number1 = 0
number2 = 0
number3 = 0
number4 = 0
colours = "1=DeepPink;2=Yellow;3=YellowGreen;4=Blue;5=White;6=Black"
symbols = "1=#;2=$;3=!;4=?;5=@;6=%"

' Display the Game Start Screen
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(30,150,540,300)
GraphicsWindow.FontSize = 50
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(100,200,"Match colours")
GraphicsWindow.DrawText(100,250,"or symbols.")
GraphicsWindow.FontSize = 35
GraphicsWindow.DrawText(100,320, "First to " + targetscore + " wins.")
GraphicsWindow.FontSize = 20
GraphicsWindow.DrawText(100,400, "Press space to play")
p1clicked = "False"
While ("True")
  If p1clicked = "True" Then
    Goto beginround
  EndIf
EndWhile

beginround:
' Set up the default font size and colour (for the big numbers)
GraphicsWindow.FontSize = 300
GraphicsWindow.BrushColor = "Black"

While (win = "False")
  GraphicsWindow.Clear() ' Clear the screen to remove the old numbers
  GraphicsWindow.BackgroundColor = "Gray" ' Return the background to grey
  p1clicked = "False"
  p2clicked = "False"
  canclick = "True"
  number1 = Math.GetRandomNumber(6)
  number2 = Math.GetRandomNumber(6)
  GraphicsWindow.BrushColor = colours[number1]
  GraphicsWindow.DrawText(75,125, symbols[number2])
  number3 = Math.GetRandomNumber(6)
  number4 = Math.GetRandomNumber(6)
  GraphicsWindow.BrushColor = colours[number3]
  GraphicsWindow.DrawText(325,125, symbols[number4])
  Updatep1Score()
  Updatep2Score()
  For i = 1 To 50 ' 50 * 20ms = 1 second delay between number pairs
    Program.Delay(pause)
    If canclick = "True" And p1clicked = "True" And (number1 = number3 Or number2 = number4) Then
      GraphicsWindow.BackgroundColor = "Green"
      p1score = p1score + 1
      Updatep1Score()
      canclick = "False"
    ElseIf canclick = "True" And p2clicked = "True" And (number1 = number3 Or number2 = number4) Then
      GraphicsWindow.BackgroundColor = "Green"
      p2score = p2score + 1
      Updatep2Score()
      canclick = "False"
    ElseIf canclick = "True" And p1clicked = "True" Then
      GraphicsWindow.BackgroundColor = "Red"
      p1score = p1score - 1
      If p1score < 0 Then
        p1score = 0
      EndIf
      Updatep1Score()
      canclick = "False"
    ElseIf canclick = "True" And p2clicked = "True" Then
      GraphicsWindow.BackgroundColor = "Red"
      p2score = p2score - 1
      If p2score < 0 Then
        p2score = 0
      EndIf
      Updatep2Score()
      canclick = "False"
    EndIf
  EndFor
  If p1score = targetscore Or p2score = targetscore Then
    win = "True"
  EndIf
EndWHile

' Display the Game Over Screen
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(30,150,540,300)
GraphicsWindow.FontSize = 50
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(100,200,"Game Over")
GraphicsWindow.BrushColor = "Yellow"
if p1score > p2score Then
  GraphicsWindow.DrawText(100,250,"Player 1 Wins!")
Else
  GraphicsWindow.DrawText(100,250,"Player 2 Wins!")
Endif
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FontSize = 20
GraphicsWindow.DrawText(100,400, "Press space to play again")
p1clicked = "False"
While ("True")
  If p1clicked = "True" Then
    Goto start
  EndIf
EndWhile


Sub OnKeyDown
  if GraphicsWindow.LastKey = "Space" Then
    p1clicked = "True"
  EndIf
EndSub

Sub OnMouseDown
  p2clicked = "True"
EndSub

Sub Updatep1Score
  GraphicsWindow.BrushColor = "Black"
  GraphicsWindow.FillRectangle(10,10,80,50)
  GraphicsWindow.FontSize = 50
  GraphicsWindow.BrushColor = "White"
  GraphicsWindow.DrawText(20,10, p1score)
  GraphicsWindow.BrushColor = "Black"
  GraphicsWindow.FontSize = 18
  GraphicsWindow.DrawText(12, 62, "P1 Press Space")
  GraphicsWindow.FontSize = 300
EndSub

Sub Updatep2Score
  GraphicsWindow.BrushColor = "Black"
  GraphicsWindow.FillRectangle(510,10,80,50)
  GraphicsWindow.FontSize = 50
  GraphicsWindow.BrushColor = "White"
  GraphicsWindow.DrawText(520,10, p2score)
  GraphicsWindow.BrushColor = "Black"
  GraphicsWindow.FontSize = 18
  GraphicsWindow.DrawText(435, 62, "P2 Click Mouse")
  GraphicsWindow.FontSize = 300
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.