I am Not very familiär anymore with freebasic so I am asking Here for little help
Something is Missing Help is very Welcome thanks loewenherz
Code: Select all
' kind of MineSweeper
screenres 640, 480, 32
const rows = 10
const cols = 10
dim board(rows, cols) as string
dim revealed(rows, cols) as integer
dim shared as integer mineCount = 15
sub initializeBoard()
dim i As integer, j as integer
Dim board(rows, cols) as string
Dim revealed(rows, cols) as integer
' Clear the board
for i = 0 to rows - 1
for j = 0 to cols - 1
board(i, j) = " "
revealed(i, j) = 0
next j
next i
' Place mines
dim row As Integer, col as integer
dim placedMines as integer = 0
do
row = rnd * rows
col = rnd * cols
if board(row, col) <> "*" then
board(row, col) = "*"
placedMines += 1
end if
loop until placedMines = mineCount
end sub
sub printBoard()
dim board(rows, cols) as string
Dim revealed(rows, cols) as integer
cls
dim i As Integer, j as integer
for i = 0 to rows - 1
for j = 0 to cols - 1
if revealed(i, j) = 1 then
print board(i, j);
else
print ".";
end if
next j
print
next i
end sub
sub revealCell(row as integer, col as integer)
dim board(rows, cols) as string
Dim revealed(rows, cols) as integer
If row < 0 or row >= rows or col < 0 or col >= cols then return
if revealed(row, col) = 1 then return
revealed(row, col) = 1
if board(row, col) = "*" then
print "Game over! You hit a mine."
end
else
dim i As integer, j As integer
dim mineCount as integer = 0
for i = row - 1 to row + 1
for j = col - 1 to col + 1
if i >= 0 and i < rows and j >= 0 and j < cols then
if board(i, j) = "*" then
mineCount += 1
end if
end if
next j
next i
board(row, col) = str(mineCount)
if mineCount = 0 then
' recursively reveal adjacent cells if there are no adjacent mines
revealCell(row - 1, col - 1)
revealCell(row - 1, col)
revealCell(row - 1, col + 1)
revealCell(row, col - 1)
revealCell(row, col + 1)
revealCell(row + 1, col - 1)
revealCell(row + 1, col)
revealCell(row + 1, col + 1)
end if
end if
end sub
sub gamemain()
dim board(rows, cols) as string
Dim revealed(rows, cols) as integer
initializeBoard()
printBoard()
dim row As integer, col as integer
do
print "Enter row (0-9): "
input row
print "Enter col (0-9): "
input col
revealCell(row, col)
printBoard()
Loop
'PRINT "push a key to continue"
'Sleep
'Print "you have pressed "; INKEY ; " key: "
'Print "wait a second"
'Sleep 1000
end sub
gamemain()