Original Wumpus

User projects written in or related to FreeBASIC.
Destructosoft
Posts: 88
Joined: Apr 03, 2011 3:44
Location: Inside the bomb
Contact:

Original Wumpus

Postby Destructosoft » Jul 12, 2011 23:36

Another thing I threw together in a hurry.

This is a FreeBASIC remake of the original Wumpus by Gregory Yob. Unlike Richard Clark's excellent version of the game (download at http://users.freebasic-portal.de/rdc/programs.html#mozTocId153108) this is the version which has a dodecahedral maze and mentions room numbers instead of supplying a picture.

I tried to preserve as much of the original text as possible, although I hated his instructions and had to rewrite them.

Code: Select all

/'Hunt the Wumpus 1
1972 Gregory Yob
1973 People's Computer Company
1975 Creative Computing
1985,2011 Destructosoft
Open source

This is a FreeBASIC remake of the original game by Gregory Yob.

Acknowledgements to Richard Clark for his interesting version.

Remember to give yourself credit in the title screen if you modify this!
'/

Declare Sub k
Declare Function ts(As LongInt)As String

Enum
 bat=1,pit,wumpus
End Enum

Const blue  =Rgb(  0,  0,255)
Const cyan  =Rgb(  0,255,255)
Const green =Rgb(  0,255,  0)
Const purple=Rgb(255,  0,255)
Const red   =Rgb(255,  0,  0)
Const yellow=Rgb(255,255,  0)

Dim As Byte l(4)=>{bat,bat,pit,pit,wumpus}
Dim As Byte m(1 To 20,2)=>{{2,5,8},{1,3,10},{2,4,12},{3,5,14},{1,4,6},{5,7,15},{6,8,17},{1,7,9},{8,10,18},{2,9,11},_
 {10,12,19},{3,11,13},{12,14,20},{4,13,15},{6,14,16},{15,17,20},{7,16,18},{9,17,19},{11,18,20},{13,16,19}}
Dim As Byte arrow,b,n(1 To 20),o(2),p(4),r,room,s,t,wroom
Dim As Integer rn
Dim Shared As String a

Screenres 640,480,32'need at least 80 columns of text
Randomize Timer
rn=Int(Rnd*4294967395)+1'random seed
Locate 2'print title logo
For r=0 To 6
 Color Rgb(255-(r*24),0,0)
 Read a
 For s=0 To Len(a)-1
  Select Case a[s]
  Case 32
   Print" ";
  Case 35
   Print Chr(177);
  Case 64
   Print Chr(219);
  End Select
 Next
 Print
Next
Color cyan
Print
Print Tab(21);"1972: Original version by Gregory Yob"
Print
Print Tab(20);"2011: FreeBASIC version by Destructosoft"
Print Tab(30);"Coded by Eric Draves"
Print
Color blue

main:
Print"Instructions [Y/N]"
Print
k
If a="y" Then
 Color cyan
 Print Tab(26);"How to play Hunt the Wumpus"
 Print
 Print"  The Wumpus lives in a cave of twenty rooms. Each room connects to three other"
 Print"rooms by means of tunnels. You must traverse these tunnels to hunt the pesty"
 Print"creature."
 Print
 Print"  There are hazards to avoid whilst hunting. Pits are bottomless and a one-way"
 Print"trip to certain death. You'll feel a draft when one is nearby. Also, there are"
 Print"giant superbats which will pick you up and deposit you in another room. You"
 Print"will hear one as you approach."
 Print
 Print"  The Wumpus itself is a cunning and arrogant beast. It sleeps until you either"
 Print"bump into it or shoot an arrow, whereupon it wakes up and moves. An awake"
 Print"Wumpus will eat adventurers, so be careful!"
 Print
 Print"  Each turn you may move or shoot a crooked arrow. The crooked arrow will"
 Print"travel from 1-5 rooms. Specify each room it will fly into, if you can. You have"
 Print"five shots. Results may vary."
 Print
 Print Tab(35);"Good luck!"
 Print
End If
Randomize rn'new game
Erase n
For r=0 To 4'place items
 Do
  s=Int(Rnd*20)+1
 Loop Until n(s)=0
 n(s)=l(r)
 If r=4 Then wroom=s
Next
Do'you start in an empty room
 room=Int(Rnd*20)+1
Loop Until n(room)=0
Randomize Timer
arrow=5
Color yellow
Print Tab(32),"HUNT THE WUMPUS"
Print

turn:
For r=0 To 2
 o(r)=n(m(room,r))
Next
Color blue
b=0
/'Have to check for everything seperately so any "spider sense" of something is only
reported ONCE. Also, without a for/next to check, you don't have to worry about reporting
in a certain order and thus giving clues about which rooms have it. If you change this to
allow for a for/next, make sure you scramble the o() array'/
If o(0)=bat Or o(1)=bat Or o(2)=bat Then Print"Bats nearby!":b=1
If o(0)=pit Or o(1)=pit Or o(2)=pit Then Print"You feel a draft!":b=1
If o(0)=wumpus Or o(1)=wumpus Or o(2)=wumpus Then Print"You smell a Wumpus!":b=1
If b=1 Then Print

iter:
Color purple
Print"You are in room "+ts(room)+". Tunnels lead to "+ts(m(room,0))+" "+ts(m(room,1))+" "+ts(m(room,2))
Color blue
Print"Move or shoot [M/S]"
Do
 k
Loop Until a="m"Or a="s"
If a="m"Then
 Input" Move to: ",r
 If r=m(room,0)Or r=m(room,1)Or r=m(room,2)Then'move to destination
  Color red
  Print
  room=r
  Do
   b=0
   Select Case n(room)
   Case bat
    Print"ZAP! Super bat snatch! Elsewhereville for you!"
    n(r)=0'move bat
    Do
     r=Int(Rnd*20)+1
    Loop Until n(r)=0
    n(r)=bat
    room=Int(Rnd*20)+1
    b=2
   Case pit
    Print"YYYIIIIEEEE.... Fell in a pit!"
    Goto gameover
   Case wumpus
    Print"Oops! Bumped a Wumpus!"
    b=1
   End Select
  Loop Until b<>2
 Else'wrong number
  Color red
  Print"Not possible.":Goto iter
 End If
Else'Shoot. You know you have enough ammo because when you run out the game ends
 b=0
 Erase p
 Color blue
 Print"No. of rooms [1-5]"
 Do
  k
 Loop Until a>"/"And a<"6"
 r=Val(a)-1
 If r>-1 Then
  /'The arrow room numbers are all entered before the arrow is shot, requiring 2
  for/nexts. This is because no indication should be given as to the success of the shot
  in stages. One mistake early on will blow everything'/ 
  For s=0 To r
   Do
    Print" Room "+ts(s+1);
    Input": ",p(s)
   Loop Until p(s)>0 And p(s)<21
  Next
  t=room
  For s=0 To r
   If p(s)=m(t,0)Or p(s)=m(t,1)Or p(s)=m(t,2)Then
    t=p(s)
   Else
    t=m(t,Int(Rnd*3))
   End If
   If t=room Then
    Color red
    Print"OUCH! Arrow got you!"
    Goto gameover
   ElseIf n(t)=wumpus Then
    Color green
    Print"AHA! You got the Wumpus!"
    Print
    Color blue
    Print"Hee hee hee, the Wumpus'll getcha next time!"
    Goto go2
   Else
    Print"...";'signifies got through 1 room
   End If
  Next
  Color red
  Print"Missed."
  arrow-=1
  If arrow=0 Then
   Print"Out of arrows!"
   Goto gameover
  End If
  b=1
 End If
End If
If b=1 Then
 r=Int(Rnd*4)
 If r<3 Then
  Select Case n(m(wroom,r))
  Case 0'move wumpus
   n(wroom)=0
   wroom=m(wroom,r)
   n(wroom)=wumpus
  Case bat'move wumpus and displace bat
   n(wroom)=0
   wroom=m(wroom,r)
   n(wroom)=wumpus
   Do
    s=Int(Rnd*20)+1
   Loop Until n(s)=0
   n(s)=bat
  End Select
  /'Minor changes from the original program:
  1. A wumpus cannot be in the same room as a pit or bat. It used to be that if a wumpus
     was in the same room as a pit, you could walk into the room and bump the wumpus
     without falling into the pit first. It was also said the wumpus had sucker feet so
     it wouldn't fall in itself. (And yet it was too heavy for a superbat to carry...)
  2. When a wumpus moves into a room with a bat, the bat moves elsewhere. (I could have
     made it so the bat would pick IT up and move it around, but there's enough going on
     here as it is.)'/
 End If
 If wroom=room Then
  Color red
  Print"Tsk tsk tsk... Wumpus got you!"
  Goto gameover
 End If
End If
Goto turn

gameover:
Print
Color blue
Print "HA HA HA - YOU LOSE!"'yes, the original text said this. What a yob.

go2:
Print
Print"Continue [Y/N]"
k
If a="n"Then End
Print"Same setup [Y/N]"
k
If a<>"y"Then rn=Int(Rnd*4294967395)+1'new random seed
Goto main
End

Data" @  @ @  @ @#   @ @@@@@   @@@@@ @  @ #@@@   @     @ @  @ @#   #@ @@@# @  @ #@@@"
Data" @  @ @  @ @@#  @   @       @   @  @ @      @     @ @  @ @@# #@@ @  @ @  @ @"
Data" @  @ @  @ @#@# @   @       @   @  @ @      @  #  @ @  @ @#@#@#@ @  @ @  @ @"
Data" @@@@ @  @ @ #@#@   @       @   @@@@ @@@    @ #@# @ @  @ @ #@# @ @@@# @  @ #@@#"
Data" @  @ @  @ @  #@@   @       @   @  @ @      @#@#@#@ @  @ @  #  @ @    @  @    @"
Data" @  @ @  @ @   #@   @       @   @  @ @      @@# #@@ @  @ @     @ @    @  @    @"
Data" @  @ #@@# @    @   @       @   @  @ #@@@   @#   #@ #@@# @     @ @    #@@# @@@#"

Sub k
Do
 a=LCase(inkey)
 sleep 1,1
Loop Until a<>""
If a=Chr(27)Or a="q" or a=chr(255,107)Then End
End Sub

Function ts(r As LongInt)As String
Return Trim(Str(r))
End Function

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest