find-thrash/robotfindskitten.bas
ascii benefactor e80ae27e00 lol
2021-06-15 04:58:16 -04:00

166 lines
2.4 KiB
QBasic

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:{}}")
map={}
rem prg start
genThrash(amount)
borderscr()
rem grafx loop waiting for win
repeat
if robx = kitx AND roby = kity then
win=true
locate linenb,1
print " You found kitten!"
fi
printobj()
printui()
printrob()
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 i = 1 to amount
if robx=thrash[i].x and roby=thrash[i].y then
locate linenb+3,2
print thrash[i].text
thrash[i].active = false
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
case "q"
break
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 printobj()
rem print thrash
for it=1 to amount
if thrash[it].active then
local objx = thrash[it].x
local objy = thrash[it].y
locate objy,objx
print thrash[it].ch
fi
next
locate kity,kitx
print kitchar
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 = "lazy"
thrash[index].active = true
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