Catch a Thief.bas

Here is a text adventure game (sort of) for Johnno.


' Catch a thief.bas for SmallBASIC 0.12.8 2017-01-23
' modified Kitty.bas for Tinycat BASIC 2017-01-22 and
' Wheres Kitty.bas for SmallBASIC 2015-02-25 and
' revKitty for SmallBASIC 0.12.8 2017-01-23
' (Took awhile to get to where I liked it.)

randomize
' ===================== title and instructions
?
? " Catch a Thief"
? " A known cat burglar, Kitty, is seen entering a hotel."
? " You are called in to catch her before she cleans out all 10"
? " rooms. Kitty moves +1 or -1 room between your room checks."
? " 20% of time, Kitty switches direction."
? " You have brought the K-9 unit, Wolf, to help you find"
? " Kitty. Wolf will Woof (up to 4 times) for how many changes"
? " ago Kitty was in the room, a sigh means no scent of Kitty."
? " Kitty will have been in 4 rooms before you start checks."

label restart ' game loop
?
? " +++++++++++++++++++++++++ New Game +++++++++++++++++++++++++"
direction = iff(rnd < .5, 1, -1) : room = int(rnd * 10) + 1 ' initialize
robbed = string(10,"0") : index = 0 : flagExit = 0
dim rooms(100), checks(100), robs(100), reports(100)
for
i = 1 to 4 : moveKitty : next

while 1 'guessing loop
? : input " Enter a room number, 1 to 10 (any other quits), to check "; guess
if guess < 1 or guess > 10 then
r = " You quit checking." : flagExit = 1 : guess = 11 '>.................only exit
elif guess = room
r = " Kitty, you are under arrest!" : flagExit = 1
elif guess = lastMove1
r = " Woof"
elif guess = lastMove2
r = string(2, " Woof")
elif guess = lastMove3
r = string(3, " Woof")
elif guess = lastMove4
r = string(4, " Woof")
else
r = " (dog sighs)"
fi
? r
rooms(index) = room : checks(index) = guess
robs(index) = robbed : reports(index) = r : index += 1
if flagExit then exit
moveKitty
wend
?:? " Here is a replay of the game:"
? " Room:", "Guess:", "Robbed:";space(3), " Report:"
for
i = 0 to index-1
? " ";rooms(i);space(3), checks(i);space(3), robs(i), reports(i)
next
? : input " Play Again? Enter y for yes, any other quits "; again
if
again = "y" then goto restart

sub
moveKitty()
'before changing rooms check and see if all rooms have been cleaned out
mids robbed, room, "X" 'another room cleaned out

'shift lastMoves variables
lastMove4 = lastMove3 : lastMove3 = lastMove2
lastMove2 = lastMove1 : lastMove1 = room

if robbed = string(10, "X") then
room = 0 ' Kitty has left the building!!!
else
if rnd < .2 then direction *= -1
room = room + direction
if room = 11 then room = 1
if room = 0 then room = 10
end if
end

sub
mids(byref source, position, replacement)
local b, i
b = ""
for i = 1 to len(source)
if i = position then
b = b + replacement
else
b = b + mid(source, i, 1)
end if
next
source = b
end

Still making better! (I hope)


' Catch a thief.bas for SmallBASIC 0.12.8 2017-01-23
' modified Kitty.bas for Tinycat BASIC 2017-01-22 and
' Wheres Kitty.bas for SmallBASIC 2015-02-25 and
' revKitty for SmallBASIC 0.12.8 2017-01-23
' (Took awhile to get to where I liked it.)
' 2017-01-24 edit scenario to explain why 1 is next to 10

randomize

' ===================== title and description
print
print " Catch a Thief"
print
print " A known cat burglar, Kitty, has been spotted in the"
print " Diamond Lake area, famous for it's 10 posh mansions that"
print " surround it. You are called in to catch her before she"
print " cleans out all 10 homes. Kitty moves +1 or -1 property"
print " between your checks. 20% of time, Kitty switches direction."
print " You have brought the K-9 unit, Wolf, to help you find"
print " Kitty. Wolf will Woof (up to 4 times) for how many moves"
print " ago Kitty was at the property, a sigh means no scent of"
print " Kitty, who will have been in 4 homes before you start your"
print " search with Wolf. The 10th home is next door to first home."

label restart ' game loop
?
? " +++++++++++++++++++++++++ New Game +++++++++++++++++++++++++"
direction = iff(rnd < .5, 1, -1) : house = int(rnd * 10) + 1 ' initialize
robbed = string(10,"0") : index = 0 : flagExit = 0
dim houses(100), checks(100), robs(100), reports(100), lastMove(4)
for
i = 1 to 4 : moveKitty : next

while 1 'guessing loop
r = ""
? : input " Enter a home number, 1 to 10 (any other quits), to check "; guess
if guess < 1 or guess > 10 then
r = " You quit checking." : flagExit = 1 : guess = 11
else
if guess = house then
r = " Kitty, you are under arrest!" : flagExit = 1
else
for i = 1 to 4
if guess = lastMove(i) then r = string(i, " Woof") : exit for
next
if r = "" then r = " (dog sighs)"
end if
end if
? r
houses(index) = house : checks(index) = guess
robs(index) = robbed : reports(index) = r : index += 1
if flagExit then exit
moveKitty
wend
?:? " Here is a replay of the game:"
? " Home:", "Guess:", "Robbed:";space(3), " Report:"
for
i = 0 to index-1
? " ";houses(i);space(3), checks(i);space(3), robs(i), reports(i)
next
? : input " Play Again? Enter y for yes, any other quits "; again
if
again = "y" then goto restart

sub
moveKitty()
local i
'before changing homes check and see if all homes have been cleaned out
mids robbed, house, "X" 'another house cleaned out

'shift lastMoves variables
for i = 3 to 1 step -1
lastMove(i+1) = lastMove(i)
next
lastMove(1) = house

if robbed = string(10, "X") then
house = 0 ' Kitty has left the area
else
if rnd < .2 then direction *= -1
house = house + direction
if house = 11 then house = 1
if house = 0 then house = 10
end if
end

sub
mids(byref source, position, replacement)
local b, i
b = ""
for i = 1 to len(source)
if i = position then
b = b + replacement
else
b = b + mid(source, i, 1)
end if
next
source = b
end