Microsoft Small Basic

Program Listing:
Embed this in your website
'TerGen v.0.0.6 Apr. 15 - 2:50 pm

wid = 24
hgt = 24
GraphicsWindow.Width = 20*(wid+2)
GraphicsWindow.Height = 20*(hgt+3)

GraphicsWindow.BackgroundColor = "Black"
GraphicsWindow.BrushColor = "GhostWhite"
GraphicsWindow.FillRectangle (20,20,GraphicsWindow.Width-40,GraphicsWindow.Height-40)
GraphicsWindow.FontSize = 72
GraphicsWindow.BrushColor = "DarkSlateGray"
GraphicsWindow.DrawText(135,75,"Terrain")
GraphicsWindow.DrawText(145,175,"Digger")
GraphicsWindow.FontSize = 18
GraphicsWindow.DrawText(40,300,"Arrow Keys to move")
GraphicsWindow.DrawText(40,325,"Press against terrain to dig with pick or shovel.")
GraphicsWindow.DrawText(40,350,"Get to the black dot to exit level.")
GraphicsWindow.DrawText(40,375,"Filler: Use 20 to fill a water space.")
GraphicsWindow.DrawText(40,400,"Bomb: Mouse click to place.")
GraphicsWindow.DrawText(40,425,"Barrels (brown dots) refill tools.")
GraphicsWindow.DrawText(40,450,"Collect gold and gems to feel special.")
GraphicsWindow.DrawText(40,475,"Press Home for a new level.")
Program.Delay(10000)

shovel = 15
pick = 3
gold = 0
gems = 0
filler = 0
bombs = 1
bomb_timer = -1

GraphicsWindow.MouseDown = OnMouseDown
GraphicsWindow.KeyDown = Keypress
GraphicsWindow.KeyUp = Win

player["pcX"] = 1
player["pcY"] = 1

newmap()

sub newmap
  GraphicsWindow.BackgroundColor = "DimGray"
For x = 1 To wid
  For y = 1 To hgt
    z = Math.GetRandomNumber(20)
    If z <= 11 Then
      coords[x][y]["terrain"] = "floor"
      f = Math.GetRandomNumber(80)
      If f >= 80 then
        coords[x][y]["features"] = "barrel"
      EndIf
    elseIf z = 12 Then
      coords[x][y]["terrain"] = "water"
    Elseif z >= 13 and z <= 17  then
      coords[x][y]["terrain"] = "stone"
    elseif z >= 18 and z <= 20  then
      coords[x][y]["terrain"] = "dirt"
    EndIf
    GraphicsWindow.FillRectangle ((x*20),(y*20),20,20)
  EndFor
EndFor
coords[1][1]["terrain"] = "floor"
coords[20][20]["terrain"] = "floor"
exit[x] = wid/3 + Math.GetRandomNumber(wid/3)
exit[y] = math.Round((hgt*.70) + Math.GetRandomNumber(hgt*.20))
redrawthemapagain()
EndSub

sub  redrawthemapagain
  GraphicsWindow.BackgroundColor = "DimGray"
For x = 1 To wid
  For y = 1 To hgt
    If coords[x][y]["terrain"] = "floor" Then
      GraphicsWindow.BrushColor = "lightyellow"
    elseIf coords[x][y]["terrain"] = "water" Then
      GraphicsWindow.BrushColor = "powderblue"
    Elseif coords[x][y]["terrain"] = "stone" Then
      GraphicsWindow.BrushColor = "DarkGray"
    Elseif coords[x][y]["terrain"] = "dirt" Then
      GraphicsWindow.BrushColor="Sienna"
    EndIf
    GraphicsWindow.FillRectangle ((x*20),(y*20),20,20)
  EndFor
EndFor
For x = 1 To wid
  For y = 1 To hgt
    If coords[x][y]["features"] = "barrel" then
      GraphicsWindow.BrushColor="brown" 'barrel
      GraphicsWindow.FillEllipse ((x*20),(y*20),20,20)
    ElseIf coords[x][y]["features"] = "gold" then
      GraphicsWindow.BrushColor="yellow" 'gold
      GraphicsWindow.FillEllipse ((x*20),(y*20),20,20)
    elseIf coords[x][y]["features"] = "gem" then
      GraphicsWindow.BrushColor="cyan" 'gem
      GraphicsWindow.FillEllipse ((x*20),(y*20),20,20)
    elseIf coords[x][y]["features"] = "bomb" then
      GraphicsWindow.BrushColor="DarkSlateGray" 'bomb
      bomb_timer = bomb_timer - 1
      If bomb_timer = 0 then
        bomb()
      EndIf
      GraphicsWindow.FillEllipse ((x*20),(y*20),20,20)
  EndIf
  EndFor
EndFor
GraphicsWindow.FontSize = 16
GraphicsWindow.BrushColor = "Silver"
'GraphicsWindow.FillRectangle(3,3,440,20)
GraphicsWindow.FillRectangle(20,((hgt+1)*20)+5,((wid+1)*20)-3,20)
GraphicsWindow.BrushColor = "Black"
'GraphicsWindow.DrawText(3,3,"Pick: "+pick+" Shovel: "+shovel+" Gold: "+gold+" Gems: "+gems+" Filler: "+filler+" ")
GraphicsWindow.DrawText(20,((hgt+1)*20)+5,"Pick: "+pick+" Shovel: "+shovel+" Gold: "+gold+" Gems: "+gems+" Filler: "+filler+" ")
GraphicsWindow.BrushColor = "Blue" 'Player
GraphicsWindow.FillEllipse((player["pcX"]*20),(player["pcY"]*20),20,20)
GraphicsWindow.BrushColor="black" 'exit
GraphicsWindow.FillEllipse((exit[x]*20),(exit[y]*20),20,20)
EndSub

' <<<

Sub OnMouseDown
  If bomb_timer = -1 and bombs > 0 Then
  mx = Math.Round((GraphicsWindow.MouseX-10)/20)
  my = Math.Round((GraphicsWindow.MouseY-10)/20)
  'GraphicsWindow.ShowMessage("The terrain is:"+coords[mx][my]["terrain"]+"","Terrain")
    'GraphicsWindow.ShowMessage("You set up us the bomb!","Bomb Set")
    coords[mx][my]["features"] = "bomb"
    bomb_timer = 4
    bombs = bombs - 1
    redrawthemapagain()
  EndIf
EndSub

Sub bomb
  coords[mx][my]["features"] = ""
  coords[mx+1][my]["terrain"] = "floor"
  coords[mx-1][my]["terrain"] = "floor"
  coords[mx][my+1]["terrain"] = "floor"
  coords[mx][my-1]["terrain"] = "floor"
  coords[mx+1][my+1]["terrain"] = "floor"
  coords[mx+1][my-1]["terrain"] = "floor"
  coords[mx-1][my+1]["terrain"] = "floor"
  coords[mx-1][my-1]["terrain"] = "floor"
  bomb_timer = -1
  GraphicsWindow.BrushColor="orangered"
  GraphicsWindow.FillEllipse(((mx-1)*20),((my-1)*20),60,60)
endsub

Sub Keypress
'Move Player
If keydelay <> 1 Then
  keydelay = 1
  key = GraphicsWindow.LastKey
  Program.Delay(500)

  If key = "Home" Then
    player["pcX"] = exit[x]
    player["pcY"] = exit[y]
    win()
    'newmap()
  EndIf

  If key = "Up" Then 'move
    If coords[player["pcX"]][player["pcY"]-1]["terrain"] = "floor" then
      player["pcY"] = player["pcY"] - 1
        Goto moveskip
    EndIf
    If coords[player["pcX"]][player["pcY"]-1]["terrain"] = "dirt" then
      'dig the dirt if you have a shovel
      If shovel > 0 Then
        shovel = shovel - 1
        filler = filler + 1
        coords[player["pcX"]][player["pcY"]-1]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]][player["pcY"]-1]["terrain"] = "stone" then
      'dig the stone
      If pick > 0 Then
        pick = pick - 1
        filler = filler + 5
        t = Math.GetRandomNumber(20)
        If t = 20 Then
          coords[player["pcX"]][player["pcY"]-1]["features"] = "gem"
        ElseIf t >= 17 and t < 20 then
          coords[player["pcX"]][player["pcY"]-1]["features"] = "gold"
        EndIf
        coords[player["pcX"]][player["pcY"]-1]["terrain"] = "floor"
        Program.Delay(500)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]][player["pcY"]-1]["terrain"] = "water" then
      If filler >= 20 then
        filler = filler - 20
        coords[player["pcX"]][player["pcY"]-1]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
  EndIf

  If key = "Left" Then
    If coords[player["pcX"]-1][player["pcY"]]["terrain"] = "floor" then
      player["pcX"] = player["pcX"] - 1
      Goto moveskip
    EndIf
    If coords[player["pcX"]-1][player["pcY"]]["terrain"] = "dirt" then
      'dig the dirt if you have a shovel
      If shovel > 0 Then
        shovel = shovel - 1
        filler = filler + 1
        coords[player["pcX"]-1][player["pcY"]]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]-1][player["pcY"]]["terrain"] = "stone" then
      'dig the stone
      If pick > 0 Then
        pick = pick - 1
        filler = filler + 5
        t = Math.GetRandomNumber(20)
        If t = 20 Then
          coords[player["pcX"]-1][player["pcY"]]["features"] = "gem"
        ElseIf t >= 17 and t < 20 then
          coords[player["pcX"]-1][player["pcY"]]["features"] = "gold"
        EndIf
        coords[player["pcX"]-1][player["pcY"]]["terrain"] = "floor"
        Program.Delay(500)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]-1][player["pcY"]]["terrain"] = "water" then
      If filler >= 20 then
        filler = filler - 20
         coords[player["pcX"]-1][player["pcY"]]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
  EndIf

  If key = "Right" Then
    If coords[player["pcX"]+1][player["pcY"]]["terrain"] = "floor" then
      player["pcX"] = player["pcX"] + 1
      Goto moveskip
    EndIf
    If coords[player["pcX"]+1][player["pcY"]]["terrain"] = "dirt" then
      'dig the dirt if you have a shovel
      If shovel > 0 Then
        shovel = shovel - 1
        filler = filler + 1
        coords[player["pcX"]+1][player["pcY"]]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]+1][player["pcY"]]["terrain"] = "stone" then
      'dig the stone
      If pick > 0 Then
        pick = pick - 1
        filler = filler + 5
        t = Math.GetRandomNumber(20)
        If t = 20 Then
          coords[player["pcX"]+1][player["pcY"]]["features"] = "gem"
        ElseIf t >= 17 and t < 20 then
          coords[player["pcX"]+1][player["pcY"]]["features"] = "gold"
        EndIf
        coords[player["pcX"]+1][player["pcY"]]["terrain"] = "floor"
        Program.Delay(500)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]+1][player["pcY"]]["terrain"] = "water" then
      If filler >= 20 then
        filler = filler - 20
        coords[player["pcX"]+1][player["pcY"]]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
  EndIf

  If key = "Down" Then
    If coords[player["pcX"]][player["pcY"]+1]["terrain"] = "floor" then
      player["pcY"] = player["pcY"] + 1
      Goto moveskip
    EndIf
    If coords[player["pcX"]][player["pcY"]+1]["terrain"] = "dirt" then
      'dig the dirt if you have a shovel
      If shovel > 0 Then
        shovel = shovel - 1
        filler = filler + 1
        coords[player["pcX"]][player["pcY"]+1]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]][player["pcY"]+1]["terrain"] = "stone" then
      'dig the stone if you have pickiness
      If pick > 0 Then
        pick = pick - 1
        filler = filler + 5
        t = Math.GetRandomNumber(20)
        If t = 20 Then
          coords[player["pcX"]][player["pcY"]+1]["features"] = "gem"
        ElseIf t >= 17 and t < 20 then
          coords[player["pcX"]][player["pcY"]+1]["features"] = "gold"
        EndIf
        coords[player["pcX"]][player["pcY"]+1]["terrain"] = "floor"
        Program.Delay(500)
        Goto moveskip
      EndIf
    EndIf
    If coords[player["pcX"]][player["pcY"]+1]["terrain"] = "water" then
      If filler >= 20 then
        filler = filler - 20
        coords[player["pcX"]][player["pcY"]+1]["terrain"] = "floor"
        Program.Delay(200)
        Goto moveskip
      EndIf
    EndIf
  Endif


moveskip:
If coords[player["pcX"]][player["pcY"]]["features"] = "barrel" then
t = Math.GetRandomNumber(2)
If t = 1 Then
  pick = pick + 5
ElseIf t = 2 then
  shovel = shovel + 10
EndIf
coords[player["pcX"]][player["pcY"]]["features"] = ""
EndIf

If coords[player["pcX"]][player["pcY"]]["features"] = "gold" then
gold = gold + Math.GetRandomNumber(10) + 3
coords[player["pcX"]][player["pcY"]]["features"] = ""
EndIf

If coords[player["pcX"]][player["pcY"]]["features"] = "gem" then
gems = gems + 1
coords[player["pcX"]][player["pcY"]]["features"] = ""
EndIf

If player["pcX"] = exit[x] And player["pcY"] = exit[y] Then
  win()
EndIf

  Program.Delay(20)
  redrawthemapagain()
  keydelay=0

EndIf
EndSub


Sub win
  If player["pcX"] = exit[x] And player["pcY"] = exit[y] Then
    GraphicsWindow.ShowMessage("You have reached the exit.","Win")
    player["pcX"] = 1
    player["pcY"] = 1
    For x = 1 To wid
      For y = 1 To wid
          coords[x][y]["features"] = ""
      EndFor
    EndFor
    newmap()
  EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.