added basic sourcefile

This commit is contained in:
asciibene 2021-06-15 01:12:02 -04:00
parent dd3017558e
commit 829f923ccb
1 changed files with 159 additions and 0 deletions

159
robotfindskitten.bas Normal file
View File

@ -0,0 +1,159 @@
REM SmallBASIC
REM ROBOT FINDS KITTEN
REM BY ASCIIBENEFACTOR
rem
REM GET DICT FILE WITH ITEM NAMES
' x:28,y14
linenb=10
colnb=20
win=false
score=0
robx=fix(rnd*colnb)
roby=fix(rnd*linenb)
kitx=fix(rnd*colnb)
kity=fix(rnd*linenb)
kitchar = charget
amount = 5
thrash = array("{0:{}}")
rem prg start
genThrash(amount)
rem grafx loop waiting for win
repeat
if robx = kitx AND roby = kity then
win=true
fi
printrob()
printobj()
printkit()
printui()
collscan()
if inkey = nil then
delay 10
else
kbctrl
endif
until win
REM ======FUNCTION SPACE =========-
sub remtrash(nb,x,y)
locate thrash[y].x,thrash[x].x
? " "
end
sub collscan()
for local i = 1 to amount
if robx=thrash[i].x and roby=thrash[i].y then
locate linenb+1,1
print thrash[i].text
fi
next
end
sub kbctrl()
kb = inkey
' delete old rob
locate roby,robx
? " "
select case kb
case "h"
if robx > 0 then
robx = robx-1
dir="x-"
fi
case "j"
if roby < linenb then
roby = roby+1
dir="x+"
fi
case "k"
if roby > 0 then
roby = roby-1
dir="y-"
fi
case "l"
if robx < colnb then
robx = robx+1
dir="y+"
fi
end select
printrob()
end
sub printui()
locate linenb+1,1
print "Robot finds kitten"
locate linenb+2,6
print "score:"+score
end
sub printrob()
locate roby,robx
print "@"
end
sub printkit()
locate kity,kitx
print kitchar
end
sub printobj()
rem print thrash
for it=1 to amount
local objx = thrash[it].x
local objy = thrash[it].y
locate objy,objx
print thrash[it].ch
next
end
func charget()
select case fix(rnd*4)
case 1
return "&"
case 2
return "%"
case 3
return "#"
case 4
return "?"
end select
end
sub genthrash(amount)
for index = 1 to amount
local tx = fix(rnd*colnb)
local ty = fix(rnd*linenb)
thrash[index].x = tx
thrash[index].y = ty
thrash[index].ch = charget
thrash[index].text = textget
next
end
func textget()
r = rnd()*len(dict)
return 'placeholder'
end
sub borderscr()
cls
for i = 0 to linenb+1
locate i,colnb+1
? "X"
for i2 = 0 to colnb+1
locate linenb+1,i2
print "X"
next
next
end