Microsoft Small Basic

Program Listing:
Embed this in your website
' Challenge of th month December 2013 Simon Game by NaochanON VJL218
GraphicsWindow.MouseDown=OnDown
Controls.ButtonClicked=Onclicked
GUI()
Timer.Tick = OnTick
Timer.Interval = 100
Timer.Pause()

While Play="True"
  If Missed="True" Then
    wait_btn()
  ElseIf Missed="False" Then
    While M_click="False"
      Random_Light_On()
    endwhile
  EndIf
endwhile

Sub Onclicked
  nm=Controls.GetButtonCaption(Controls.LastClickedButton)
  btnclick="True"
  If nm="No" Then
    Play="False"
    Program.End()
  ElseIf nm="Yes" then
    Controls.move(btn[1],-100,120)
    Controls.move(btn[2],-100,120)
    Sum_clear()
    Shapes.SetText(MSG," ")
  EndIf
EndSub

Sub OnDown
  MX= GraphicsWindow.MouseX
  MY= GraphicsWindow.MouseY
  DS2= (MX-XYC["X"])*(MX-XYC["X"])+(MY-XYC["Y"])*(MY-XYC["Y"])

  If 75*75<= DS2 and   DS2<=0.9*DR*0.9*DR Then    ' in the circle
    KK=KK+1
    If MX<X0+DR And MY<Y0+DR Then
      ans=1
    ElseIf X0+DR<MX And MY<Y0+DR Then
      ans=2
    ElseIf MX<X0+DR And Y0+DR<MY Then
      ans=3
    ElseIf X0+DR<MX And Y0+DR<MY Then
      ans=4
    endif
    Shapes.SetOpacity(rect[ans],100)
    Program.Delay(200)
    Shapes.SetOpacity(rect[ans],30)
    Program.Delay(200)
    SumAns=text.Append(SumAns,ans)
    If MM=KK Then
      Timer.Pause()
      Shapes.SetOpacity(rect[ans],30)
      Program.Delay(200)
      check_Answer()
      M_click="False"
      Program.Delay(1500)
    endif
  endif
EndSub

Sub wait_btn
  M_click="True"
  GraphicsWindow.Title="Here"
  Controls.Move(btn[1],150,120)
  Controls.Move(btn[2],220,120)
  btnclick="False"
  While btnclick="False"
  endwhile
endsub

Sub MissPlay
  Timer.Pause()
  Shapes.SetText(MSG," You missed at No. "+KK+CRLF+" Play again? Click Yes or No ")
  Sound.PlayClickAndWait()
  Sound.PlayClickAndWait()
  Missed="True"
EndSub

Sub Check_Answer
  If SumAns=Sum Then
    Sound.PlayBellRingAndWait()
    SumAns=""
    KK=0
    Missed="False"
  ElseIf SumAns<>Sum Then
    MissPlay()
  EndIf
EndSub

sub OnTick
  t1= Math.Floor((Clock.ElapsedMilliseconds-t0)/100)/10
  rate=Math.Max((10-t1)/10,0.1)
  Shapes.Zoom(bar,rate,1)
  Shapes.Move(bar,rate*300/2+20,12)
  If rate<=0.1 Then
    MissPlay()
  endif
endsub

Sub Random_Light_On
  MM=MM+1
  N= Math.GetRandomNumber(4)
  Sum=text.Append(Sum,N)
  if MM>1 Then
    message="Answers are correct !!"+CRLF+"Click lighted color(s) "
  Else
    message="Click lighted color "
  endif
  Shapes.SetText(MSG,message)
  Level=Level-55
  Level=math.Max(Level,285)    ' delay time >=285ms
  For L=1 To MM
    NMB= Text.GetSubText(Sum,L,1)
    Shapes.SetOpacity(rect[NMB],100)
    Program.Delay(Level)
    Shapes.SetOpacity(rect[NMB],30)
    Program.Delay(Level*0.8)
  EndFor
  M_click="True"
  Program.Delay(500)
  Timer.Resume()
  t0=clock.ElapsedMilliseconds
  Shapes.SetText(MSG," Count down start!")
EndSub

Sub GUI
  GraphicsWindow.Hide()
  color="1=Red;2=Green;3=Yellow;4=Blue;5=Lightcyan;6=Black"
  CLR="1=R;2=G;3=Y;4=B"
  GraphicsWindow.BackgroundColor=color[5]
  GraphicsWindow.Width=700
  GraphicsWindow.Height=600
  '------------------------------------------------------------------------------
  DR=200
  X0=150
  Y0=150
  XYC="X="+(X0+DR)+";Y="+(Y0+DR)
  RX="1="+X0+";2="+(X0+DR)+";3="+X0+";4="+(X0+DR)
  RY="1="+Y0+";2="+Y0+";3="+(Y0+DR)+";4="+(Y0+DR)
  For i=1 To 4
    GraphicsWindow.BrushColor=color[i]
    GraphicsWindow.PenColor=color[i]
    rect[i]= Shapes.AddRectangle(DR,DR)   ' RGYB block
    Shapes.Move(rect[i],RX[i],RY[i])
    Shapes.SetOpacity(rect[i],50)
  EndFor
  '------------------------------------------------------------------------------
  GraphicsWindow.BrushColor=color[6]
  GraphicsWindow.PenColor=color[6]
  cross_H=Shapes.AddRectangle(DR*2,10)
  Shapes.Move(cross_H,X0,Y0+DR-5)
  cross_V=shapes.AddRectangle(10,DR*2)
  Shapes.Move(cross_V,X0+DR-5,Y0)
  mask= Shapes.AddEllipse(150,150)
  Shapes.Move(mask,X0+DR-75,Y0+DR-75)
  GraphicsWindow.BrushColor=color[5]
  GraphicsWindow.FontSize=30
  simon=Shapes.AddText("Simon")
  Shapes.Move(simon,X0+DR-40,Y0+DR-20)
  '------------------------------------------------------------------------------
  For j=0 To 179
    GraphicsWindow.BrushColor=color[5]
    GraphicsWindow.PenColor=color[5]
    elp[j]= Shapes.AddRectangle(DR,15)          ' Mask
    DX=DR*1.4*math.Sin(math.GetRadians(J*2))
    DY=DR*1.4*math.cos(math.GetRadians(J*2))
    Shapes.Move(elp[j],X0+0.5*DR+DX,Y0+DR-DY)
    Shapes.Rotate(elp[j],90+j*2)
  endfor
  '------------------------------------------------------------------------------
  GraphicsWindow.BrushColor=color[1]
  MSG= Shapes.AddText("Start Simon game !!!! ")
  Shapes.Move(MSG,170,2000)
  GraphicsWindow.Show()
  '------------------------------------------------------------------------------
  For k=1 To 20
    KI= Math.Remainder((K-1),4)+1
    Shapes.SetOpacity(rect[ki],100)
    Program.Delay(100)
    Shapes.SetOpacity(rect[ki],30)
  EndFor
  Shapes.Animate(MSG,170,20,2000)
  Program.Delay(2000)
  Sound.PlayChimeAndWait()
  '------------------------------------------------------------------------------
  box= Controls.AddTextBox(170,10)           ' progressing bar box
  Controls.SetSize(box,302,15)
  bar= Shapes.AddRectangle(300,10)           ' progressing bar
  Shapes.SetOpacity(bar,50)
  Shapes.Move(bar,170,12)
  '------------------------------------------------------------------------------
  Sum_clear()
  YN="1=Yes;2=No"
  For i=1 To 2
    btn[i]=Controls.AddButton(YN[i],-100,120)
  EndFor
  CRLF= Text.GetCharacter(13)+Text.GetCharacter(10)
endsub

Sub Sum_clear
  Level=1000
  Play="True"
  M_click="False"
  Missed="False"
  SumAns=""
  Sum=""
  KK=0
  MM=0
endsub


Copyright (c) Microsoft Corporation. All rights reserved.