07-17-2024, 05:24 PM
Someone showed me some code not working and I updated it to QB64 and had fun doing this
Simple Game Update
Code: (Select All)
_Title "Simple Game Update" ' bplus 2024-07-17
' remember Locate works backwards from all graphics commands
' Y vertical is listed first then x horizontal.
' I call it Row, Col to distinguish from graphics (x, y)
DefInt A-Z ' using default screen 0, simplest of all screen commands is none!
Randomize Timer ' so we start in differnt places on board
Dim maze(1 To 14, 1 To 12) 'this is our game board
For x = 1 To 14 ' marks board borders and draws them
y = 1
maze(x, y) = 1
Locate y, x: Print "#";
y = 12
maze(x, y) = 1
Locate y, x: Print "#";
Next
For y = 2 To 11
x = 1
maze(x, y) = 1
Locate y, x: Print "#";
x = 14
maze(x, y) = 1
Locate y, x: Print "#";
Next
x = Int(Rnd * 7) + 3 ' set a random place to start
y = Int(Rnd * 5) + 3
Do
Locate 15, 2: Print "score:"; S ' udate score and player
Locate y, x
Print Chr$(1); ' this draw a cute little face
If maze(x, y) = 1 Then
Locate y, x: Print "*";
Locate 18, 1: Print "Wall! Game Over!"
End
End If
If maze(x + 1, y) = 1 Then ' is there a place to move
If maze(x - 1, y) = 1 Then
If maze(x, y + 1) = 1 Then
If maze(x, y - 1) = 1 Then
Locate 18, 1: Print "Trapped! Game Over!": End
End If
End If
End If
End If
kh& = _KeyHit
Select Case kh&
Case 18432: dry = -1
Case 20480: dry = 1
Case 19200: drx = -1
Case 19712: drx = 1
Case 27: End
End Select
If drx <> 0 Or dry <> 0 Then GoSub mover
_Limit 30
Loop
mover:
Locate y, x: Print " ";
x = x + drx
y = y + dry
drx = 0
dry = 0
tryAgain:
newx = x + Int(Rnd * 3) - 1
newy = y + Int(Rnd * 3) - 1
If newy = y And newx = x Then GoTo tryAgain
If maze(newx, newy) = 1 Then GoTo tryAgain
maze(newx, newy) = 1
Locate newy, newx: Print "#"; ' mark new block
S = S + 1 ' increase score
Return
b = b + ...