var s:string;
    t:string;
    b:boolean;
    c:boolean;
    q:integer;

procedure CIRCALab;
begin
   writeln;
   writeln('This is the CIRCA lab.  It is guarded by bluejackets.');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         q := 5;
         b:=false;
      end
      else if (s = 'S') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'W') then
      begin
         q:=1;
         b:=false;
      end
      else if (s = 'E') then
      begin
         q:=3;
         b:=false;
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with bluejacket.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey that worked.  You have bested bluejacket.');
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested bluejacket.');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure CIRCAOffice;
begin
   writeln;
   writeln('This is the headquarters for the army of bluejackets.  They rule over the CIRCA lab.');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         q := 6;
         b:=false;
      end
      else if (s = 'S') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'W') then
      begin
         q:=2;
         b:=false;
      end
      else if (s = 'E') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with CIRCA Overload.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey you failed.  You are dead now');
            halt;
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested CIRCA Overload.');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure TAOffice;
begin
   writeln;
   writeln('You are in the TA Office.  It is a hive of scum and villany.');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         q := 7;
         b:=false;
      end
      else if (s = 'S') then
      begin
         q:=1;
         b:=false;
      end
      else if (s = 'W') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'E') then
      begin
         q:=5;
         b:=false;
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with Evil TA Man.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey that worked.  You have bested Evil TA Man.');
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested Evil TA Man.');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure GraduateLab;
begin
   writeln;
   writeln('You are in the graduate student lab.  There are graduate students here.  They are doing work.');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         q := 8;
         b:=false;
      end
      else if (s = 'S') then
      begin
         q:=2;
         b:=false;
      end
      else if (s = 'W') then
      begin
         q:=4;
         b:=false;
      end
      else if (s = 'E') then
      begin
         q:=6;
         b:=false;
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with Evil Graduate Student.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey that worked.  You have bested Evil Graduate Student.');
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested Evil Graduate Student');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure Frank;
begin
   writeln;
   writeln('You are in Dr. Frank''s office.  There ia lots of reversible computing stuff.');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         q := 9;
         b:=false;
      end
      else if (s = 'S') then
      begin
         q:= 3;
         b:=false;
      end
      else if (s = 'W') then
      begin
         q:=2;
         b:=false;
      end
      else if (s = 'E') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with Dr. Frank.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey that worked.  You have bested Dr. Frank.');
         end
         else if (t = 'S') then
         begin
            writeln('Hey you failed.  You are dead now.');
            halt;
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure ACM;
begin
   writeln;
   writeln('You are in the ACM Lab.  It is full of computers and crazy students.');
   writeln('You think both of them have been here for a very long time');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         writeln('You can''t go that way.');
      end
      else if (s = 'S') then
      begin
         q:= 4;
         b:=false;
      end
      else if (s = 'W') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'E') then
      begin
         q:=8;
         b:=false;
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with Mentally Unstable ACM Member.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey that worked.  You have bested Mentally Unstable ACM Member.');
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested Mentally Unstable ACM Member.');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure Dave;
begin
   writeln;
   writeln('You are in Dave Small''s office.');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'S') then
      begin
         q:= 5;
         b:=false;
      end
      else if (s = 'W') then
      begin
         q:=7;
         b:=false;
      end
      else if (s = 'E') then
      begin
         q:=9;
         b:=false;
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with Dave Small');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey you failed.  You are dead now.');
            halt;
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested Dave Small.');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure Ritter;
begin
   writeln;
   writeln('You are in Ritter''s office.  It is very nice.');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         writeln('You can''t go that way.');
      end
      else if (s = 'S') then
      begin
         q:= 6;
         b:=false;
      end
      else if (s = 'W') then
      begin
         q:=8;
         b:=false;
      end
      else if (s = 'E') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with Dr. Ritter.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey you failed.  You are dead now.');
            halt;
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested Dr. Ritter.');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

procedure Entrance;
begin
   writeln;
   writeln('You are in the entrance to CSE.  Come find the evil that awaits inside');
   writeln;
   writeln('<N>orth          <W>est          <F>ight');
   writeln('<S>outh          <E>ast          <Q>uit');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'N') then
      begin
         q := 4;
         b:=false;
      end
      else if (s = 'S') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'W') then
      begin
         writeln('You can''t go that way');
      end
      else if (s = 'E') then
      begin
         q:=2;
         b:=false;
      end
      else if (s = 'F') then
      begin
         writeln('Oh no!  You''re in combat with Evil CIS Student.');
         writeln;
         writeln('<W>eapon');
         writeln('<S>pell');
         writeln('<R>un');
         writeln;
         write('Please enter your selection: ');
         readln(t);
         t[1]:=upcase(t[1]);
         if (t = 'W') then
         begin
            writeln('Hey that worked.  You have bested Evil CIS Student.');
         end
         else if (t = 'S') then
         begin
            writeln('Hey that worked.  You have bested Evil CIS Student.');
         end
         else if (t = 'R') then
         begin
            writeln('You are a pathetic coward!  When you try to run away you are killed.');
            halt;
         end
      end
      else if (s = 'Q') then
      begin
         halt;
      end
      else writeln('Invalid command');
   end;

end;

begin
   writeln('Welcome to the CSE Dungeon.  Please choose a character');
   writeln;
   writeln('<F>roodlemaker the Fighter');
   writeln('<W>ee Willy Winky the Wizard');
   writeln('<P>usillanimous the Priest');
   b:=true;
   while (b)
   do begin
      writeln;
      write('Please enter your selection: ');
      readln(s);
      s[1]:=upcase(s[1]);
      if (s = 'F') then
      begin
         b:=false;
      end
      else if (s = 'W') then
      begin
         b:=false;
      end
      else if (s = 'P') then
      begin
         b:=false;
      end
      else writeln('Invalid command.');
   end;
   q:=1;
   repeat
      if (q = 1) then
      begin
         Entrance;
      end
      else if (q = 2) then
      begin
         CIRCALab;
      end
      else if (q = 3) then
      begin
         CIRCAOffice;
      end
      else if (q = 4) then
      begin
         TAOffice;
      end
      else if (q = 5) then
      begin
         GraduateLab;
      end
      else if (q = 6) then
      begin
         Frank;
      end
      else if (q = 7) then
      begin
         ACM;
      end
      else if (q = 8) then
      begin
         Dave;
      end
      else if (q = 9) then
      begin
         Ritter;
      end;
   until 3=4;
end.

