Hunt the Wumpus: Difference between revisions

added MiniScript example
(Add SenseTalk implementation)
(added MiniScript example)
Line 2,245:
 
</lang>
 
=={{header|MiniScript}}==
<lang MiniScript>exits = [[1,4,7], [0,2,9], [1,3,11], [2,4,13], [0,3,5],
[4,6,14], [5,7,16], [0,6,8], [7,9,17], [1,8,10],
[9,11,18], [2,10,12], [11,13,19], [3,12,14], [5,13,15],
[14,16,19], [6,15,17], [8,16,18], [10,17,19], [12,15,18]]
hazard = [null] * 20
emptyRoom = function()
while true
room = floor(rnd * 20)
if not hazard[room] then return room
end while
end function
for i in range(1, 2)
hazard[emptyRoom] = "bat"
hazard[emptyRoom] = "pit"
end for
hazard[emptyRoom] = "wumpus"
 
print "*** HUNT THE WUMPUS ***"
print "-----------------------"
curRoom = emptyRoom
arrows = 5
 
checkWumpus = function()
if hazard[curRoom] == "wumpus" then
print "You find yourself face to face with the wumpus."
print "It eats you whole."
print "GAME OVER"; exit
end if
end function
 
while true
print "You are in room " + curRoom + "."
checkWumpus
// ToDo: other hazard effects
for r in exits[curRoom]
if hazard[r] == "wumpus" then print "You smell something terrible nearby."
if hazard[r] == "bat" then print "You hear a rustling."
if hazard[r] == "pit" then print "You feel a cold wind blowing from a nearby cavern."
end for
print "Tunnels lead to: " + exits[curRoom].join(", ")
print "You have " + arrows + " arrows."; print
while true
m = input("M)ove, S)hoot, or Q)uit? ").lower
if m == "q" then exit
if m != "m" and m != "s" then continue
target = input("Which room? ").val
if exits[curRoom].indexOf(target) == null then
print "Cannot get there from here."
else if m == "m" then
curRoom = target
if hazard[curRoom] == "bat" then
print "You have entered the lair of a giant bat."
curRoom = emptyRoom
print "It picks you up and drops you in room " + curRoom + "."
else if hazard[curRoom] == "pit" then
print "The ground gives way beneath your feet."
print "You fall into a deep abyss."
print "GAME OVER"; exit
end if
else
arrows = arrows - 1
if hazard[target] == "wumpus" then
print "Congratulations! You shot the wumpus!"
exit
end if
print "You missed."
if rnd < 0.75 then
print "The wumpus wakes from his slumber."
hazard[hazard.indexOf("wumpus")] = null
hazard[emptyRoom] = "wumpus"
checkWumpus
end if
if arrows == 0 then
print "As you grasp at your empty quiver, "
print "you hear a large beast approaching..."
hazard[curRoom] = "wumpus"
checkWumpus
end if
end if
break
end while
end while</lang>
 
 
=={{header|Perl}}==
222

edits