Microsoft Small Basic

Program Listing:
Embed this in your website
'The point of the game is to turn all of the squares black
'Move with arrow keys,
'Change select square with Enter


GraphicsWindow.Width = 400
GraphicsWindow.Height = 400
GraphicsWindow.BackgroundColor = "DarkGray"
GraphicsWindow.Title = "Turn em Off"

GraphicsWindow.KeyDown = OnKeyDown

GraphicsWindow.Clear()

curx = 10
cury = 10
newx = 10
newy = 10

'Randomize and draw squars
For i=0 To 5
  For j=0 To 5
    x = Math.GetRandomNumber(2)
    If (x = 2) Then
      curcolor = "Black"
    Else
      curcolor = "Yellow"
    EndIf
    GraphicsWindow.BrushColor = curcolor
    GraphicsWindow.FillRectangle(j*65+10,i*65+10,50,50)
  EndFor
EndFor

DrawCur()


'Draw currently selected square by drawing larger red square then a smaller square inside
Sub DrawCur
  curcolor = GraphicsWindow.GetPixel(curx+25,cury+25)
  GraphicsWindow.BrushColor = "Red"
  GraphicsWindow.FillRectangle(curx,cury,50,50)
  GraphicsWindow.BrushColor = curcolor
  GraphicsWindow.FillRectangle(curx+2,cury+2,46,46)
EndSub



Sub OnKeyDown
  lkey = GraphicsWindow.LastKey

  'Pre-set new cursor position
  If (lkey = "Right") And (curx < 300)  Then
    newx = curx + 65
    newy = cury
  EndIf
  If (lkey = "Left") And (curx > 10) Then
    newx = curx - 65
    newy = cury
  EndIf
  If (lkey = "Down") And (cury < 300) Then
    newx = curx
    newy = cury + 65
  EndIf
  If (lkey = "Up") And (cury > 10) Then
    newx = curx
    newy = cury - 65
  EndIf

  'Draw square in currunt square w/o red borders and move
  GraphicsWindow.BrushColor = curcolor
  GraphicsWindow.FillRectangle(curx,cury,50,50)
  curx = newx
  cury = newy

  If (lkey = "Return") Then
    'Change current color
    tempcolor = curcolor
    ChangeColor()
    GraphicsWindow.FillRectangle(curx,cury,50,50)

    'Change top color
    If (cury > 10) Then
      tempcolor = GraphicsWindow.GetPixel(curx+25,cury-40)
      ChangeColor()
      GraphicsWindow.FillRectangle(curx,cury-65,50,50)
    EndIf

    'Change left color
    If (curx > 10) Then
      tempcolor = GraphicsWindow.GetPixel(curx-40,cury+25)
      ChangeColor()
      GraphicsWindow.FillRectangle(curx-65,cury,50,50)
    EndIf

    'Change right color
    If (curx < 300) Then
      tempcolor = GraphicsWindow.GetPixel(curx+90,cury+25)
      ChangeColor()
      GraphicsWindow.FillRectangle(curx+65,cury,50,50)
    EndIf

    'Change bottom color
    If (cury < 300) Then
      tempcolor = GraphicsWindow.GetPixel(curx+25,cury+90)
      ChangeColor()
      GraphicsWindow.FillRectangle(curx,cury+65,50,50)
    EndIf
    CheckWin()
  EndIf

  'Redraw currently selected square
  DrawCur()

EndSub



'Change color from black to yellow and otherwise
Sub ChangeColor
  If (tempcolor = "#FFFF00") Then 'Yellow
    tempcolor = "Black"
  Else
    tempcolor = "Yellow"
  EndIf
  GraphicsWindow.BrushColor = tempcolor
EndSub


'Check all spaces for any yellow. If not, you win and quit
Sub CheckWin
  flagw = 0
  For i=0 To 5
    For j=0 To 5
      If (GraphicsWindow.GetPixel(j*65+35,i*65+35) = "#FFFF00") Then
        flagw = 1
      EndIf
    EndFor
  EndFor
  If (flagw = 0) Then
    GraphicsWindow.ShowMessage("YOU WIN!","WINNER")
    Program.End()
  EndIf
EndSub

Copyright (c) Microsoft Corporation. All rights reserved.