Small Basic Forum
The Small Archives - Program 1 - Printable Version

+- Small Basic Forum (https://litdev.uk/mybb)
+-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1)
+--- Forum: Standard Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=2)
+--- Thread: The Small Archives - Program 1 (/showthread.php?tid=342)



The Small Archives - Program 1 - sm4llprogrammer2008 - 05-10-2025

Name: Smallsweeper
Created on Version: 1.3
Status: Experiment
Theme: Minesweeper
Link: https://smallbasic.com/program/?MBGB956.000
Code:
GraphicsWindow.Hide()
Program.Delay(6000)
GraphicsWindow.Title = "Loading"
GraphicsWindow.CanResize = "False"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.DrawText(0, 0, "Loading Smallsweeper...")
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
GraphicsWindow.Show()
Program.Delay(4000)
GraphicsWindow.Hide()
GraphicsWindow.Clear()
GraphicsWindow.Title = "Smallsweeper"
GraphicsWindow.Width = 1536
GraphicsWindow.Height = 864
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
GraphicsWindow.CanResize = "True"
GraphicsWindow.BrushColor = "White"
width = 10 ' Number of columns
height = 10 ' Number of rows
mines = 20 ' Total mines on the board
For i = 1 To mines
  x = Math.GetRandomNumber(width) - 1
  y = Math.GetRandomNumber(height) - 1
  While board[x][y] = -1 ' Ensure no duplicate mines
    x = Math.GetRandomNumber(width) - 1
    y = Math.GetRandomNumber(height) - 1
  EndWhile
  board[x][y] = -1
EndFor
For x = 0 To width - 1
  For y = 0 To height - 1
    If board[x][y] <> -1 Then
      count = 0
      For dx = -1 To 1
        For dy = -1 To 1
          If board[x + dx][y + dy] = -1 Then
            count = count + 1
          EndIf
        EndFor
      EndFor
      board[x][y] = count
    EndIf
  EndFor
EndFor
cellSize = 20
GraphicsWindow.BackgroundColor = "Gray"

For x = 0 To width - 1
  For y = 0 To height - 1
    GraphicsWindow.DrawRectangle(x * cellSize, y * cellSize, cellSize, cellSize)
  EndFor
EndFor
GraphicsWindow.MouseDown = OnMouseClick

Sub OnMouseClick
  mouseX = GraphicsWindow.MouseX
  mouseY = GraphicsWindow.MouseY
  cellX = Math.Floor(mouseX / cellSize)
  cellY = Math.Floor(mouseY / cellSize)
 
  ' Reveal cell logic
  If board[cellX][cellY] = -1 Then
    GraphicsWindow.ShowMessage("Game Over! You hit a mine.", "Smallsweeper")
   
    Program.End()
  Else
    GraphicsWindow.DrawText(cellX * cellSize + 5, cellY * cellSize + 5, board[cellX][cellY])
  EndIf
EndSub

GraphicsWindow.Show()