We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The Small Archives - Program 1
#1
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()
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)