Hunt the Wumpus: Difference between revisions

Content added Content deleted
(Add link to APL version)
(add FreeBASIC)
Line 900: Line 900:
(StartGame)
(StartGame)
</lang>
</lang>

=={{header|FreeBASIC}}==
<lang freebasic>data 7,13,19,12,18,20,16,17,19,11,14,18,13,15,18,9,14,16,1,15,17,10,16,20,6,11,19,8,12,17
data 4,9,13,2,10,15,1,5,11,4,6,20,5,7,12,3,6,8,3,7,10,2,4,5,1,3,9,2,8,14
data 1,2,3,1,3,2,2,1,3,2,3,1,3,1,2,3,2,1

randomize timer

dim shared as ubyte i, j, tunnel(1 to 20, 1 to 3), lost(1 to 6, 1 to 3), targ
dim as ubyte player = int(rnd*20)+1, wump, bat1, bat2, pit1, pit2, d6, epi
dim as ubyte arrows = 5
dim as string choice

for i = 1 to 20 'set up rooms
for j = 1 to 3
read tunnel(i,j)
next j
next i

for i = 1 to 6 'set up list of permuatations of 1-2-3
for j = 1 to 3
read lost(i,j)
next j
next i

'place wumpus, bats, and pits
do
wump = int(rnd*20)+1
loop until wump <> player
do
pit1 = int(rnd*20)+1
loop until pit1 <> player
do
pit2 = int(rnd*20)+1
loop until pit2 <> player andalso pit2 <> pit1
do
bat1 = int(rnd*20)+1
loop until bat1 <> player andalso bat1 <> pit1 andalso bat1 <> pit2
do
bat2 = int(rnd*20)+1
loop until bat2 <> player andalso bat2 <> pit1 andalso bat1 <> pit2 andalso bat2 <> bat1

do
if player = wump then
print "You have been eaten by the Wumpus!"
goto defeat
end if
if player = pit1 or player = pit2 then
print "Aaaaaaaaaaa! You have fallen into a bottomless pit."
goto defeat
end if
if player = bat1 or player = bat2 then
print "A bat has carried you into another empty room."
do
player = (rnd*20)+1
loop until player <> wump andalso player <> pit1 andalso player <> pit2 andalso player <> bat1 andalso player <> bat2
end if
print using "You are in room ##. There are tunnels to rooms ## ## and ##."; player; tunnel(player,1); tunnel(player,2); tunnel(player,3)
print using "You have ## arrows left."; arrows
d6 = 1 + int(rnd*6)
for i = 1 to 3
epi = tunnel(player,lost(d6,i))
if epi = wump then
print "You smell something terrible nearby."
end if
if epi = bat1 or epi = bat2 then
print "You hear a rustling."
end if
if epi = pit1 or epi = pit2 then
print "You feel a cold wind blowing from a nearby cavern."
end if
next i
choices:
print
print "What would you like to do? Type A to shoot an arrow, or a number to move to another room."
input choice
select case left(choice,1)
case "a", "A"
input "Which room would you like to shoot into? ", targ
if targ = player then
print "You shot yourself. Why would you want to do such a thing?"
goto defeat
end if
if targ = wump then goto victory
if targ = tunnel(player,1) or targ = tunnel(player,2) or targ = tunnel(player,3) then
print "The Wumpus awakes!"
if rnd < 0.75 then
print "He moves to a nearby cavern."
wump = tunnel(wump, 1+int(rnd*3))
else
print "He goes back to sleep."
end if
else
print "You can't shoot that room from here."
goto choices
end if
arrows -= 1
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
targ = valint(choice)
if targ = player then print "You are already there."
if targ = tunnel(player,1) or targ = tunnel(player,2) or targ = tunnel(player,3) then
print using "You walk to room ##"; targ
player = targ
else
print "You can't get there from here."
end if
case else
print "You are making no sense."
end select
loop until arrows = 0
print "You have run out of arrows!"
defeat:
print "You lose! Better luck next time."
end
victory:
print "You have slain the Wumpus!"
print "You have won!"
end</lang>


=={{header|Go}}==
=={{header|Go}}==