| 
% Hangman in Turing
 % Coded by Johnny F
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 var input : string                      % User's guess
 var puzzle, puzzleCaps : string := ""   % Phrase to guess, Phrase in all caps
 var unString, unDisplay : string := ""  % Phrase with underlines, To display
 
 var bodyCount : int := 0                % # of errors
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 % Procedure centers text and displays it at current row as per Text.Whatrow
 proc PutCenter (inputString : string)
 locate (Text.WhatRow, (maxcol div 2) - (length (inputString) div 2))
 put (inputString)
 end PutCenter
 
 % Draws a hangman
 %   xLeftFoot - x position of left foot
 %   yLeftFoot - y position of left foot
 %   headRad - radius of head
 %   legHeight - height of legs in pixels
 %   torsoHeight - height of torso
 %   footToTorso - distance of foot to torso (center) horizontally
 %   armsOut - how far out the arms are horizontally (in pixels)
 %   armsVertOffset - 0 will set arms straight, another number will allow offset
 %   state - a value from 0-6. 0 = no hangman, 1 = head, 2 = torso, 3 = r arm, 4 = l arm, 5 = r leg, 6 = l leg
 %   example call...  DrawHangman (100,120,10,50,45,15,50,-10,6,10)
 proc DrawHangman (xLeftFoot : int, yLeftFoot : int, headRad : int, legHeight : int, torsoHeight : int, footToTorso : int, armsOut : int, armsVertOffset : int, state : int, colorOf : int)
 
 % Left Leg (6)
 if bodyCount > 5 then
 Draw.Line (xLeftFoot, yLeftFoot, xLeftFoot + footToTorso, yLeftFoot + legHeight, colorOf)
 end if
 
 % Right Leg (5)
 if bodyCount > 4 then
 Draw.Line (xLeftFoot + footToTorso * 2, yLeftFoot, xLeftFoot + footToTorso, yLeftFoot + legHeight, colorOf)
 end if
 
 % Left Arm (4)
 if bodyCount > 3 then
 Draw.Line (xLeftFoot + footToTorso, yLeftFoot + legHeight + (torsoHeight - (torsoHeight div 6)), (xLeftFoot + footToTorso) - armsOut, (yLeftFoot + legHeight + (torsoHeight - (torsoHeight
 div 6))) + armsVertOffset, colorOf)
 end if
 
 % Right Arm (3)
 if bodyCount > 2 then
 Draw.Line (xLeftFoot + footToTorso, yLeftFoot + legHeight + (torsoHeight - (torsoHeight div 6)), (xLeftFoot + footToTorso) + armsOut, (yLeftFoot + legHeight + (torsoHeight - (torsoHeight
 div 6))) + armsVertOffset, colorOf)
 end if
 
 % Torso (2)
 if bodyCount > 1 then
 Draw.Line (xLeftFoot + footToTorso, yLeftFoot + legHeight, xLeftFoot + footToTorso, (yLeftFoot + legHeight) + torsoHeight, colorOf)
 end if
 
 % Head (1)
 if bodyCount >= 1 then
 Draw.Oval (xLeftFoot + footToTorso, yLeftFoot + legHeight + torsoHeight + headRad, headRad, headRad, colorOf)
 end if
 
 end DrawHangman
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 % Set colors
 View.Set ("graphics:max;max")
 RGB.SetColor (1, 0.11328125, 0.15234375, 0.1953125) % Dark blue
 RGB.SetColor (2, 0.90234375, 0.99609375, 0.234375)  % Bright lime
 colourback (1)
 colour (2)
 cls
 
 
 
 % Welcome Screen
 %include "welcomeScreen.t"
 
 
 
 % Prompt user for phrase to be used FIXME - hangman not showing up!
 DrawHangman (100, 600, 10, 40, 30, 15, 10, -20, 6, white)
 delay (2000)
 
 locate (2, 3)
 put "Please enter the phrase to be used:"
 locate (3, 3)
 get puzzle : *
 
 % Convert puzzle to puzzleCaps
 for i : 1 .. length (puzzle)
 if ord (puzzle (i)) > 96 and ord (puzzle (i)) < 123 then
 puzzleCaps := puzzleCaps + chr (ord (puzzle (i)) - 32)
 else
 puzzleCaps := puzzleCaps + puzzle (i)
 end if
 end for
 
 % Create underline string, store in unString
 for i : 1 .. length (puzzleCaps)
 if ord (puzzleCaps (i)) > 64 and ord (puzzleCaps (i)) < 91 then
 unString := unString + "_"
 else
 unString := unString + puzzleCaps (i)
 end if
 end for
 
 loop
 
 % set up unDisplay for centering
 unDisplay := ""
 for i : 1 .. length (unString)
 unDisplay := unDisplay + unString (i) + " "
 end for
 
 cls
 % Draw Hangman
 DrawHangman (100, 120, 10, 40, 30, 15, 10, -20, bodyCount, 2)
 
 % Draw gallows
 Draw.Box (100,100,200,200,2)
 
 % Put underlines on third row
 locate (3, 1)
 PutCenter (unDisplay)
 
 % Prompt for input (guess)
 locate (5, 1)
 PutCenter ("Enter your guess. (FIXME - in caps for now)")
 get input
 
 % Convert input to caps
 
 % If letter is there then go through and change unString
 if index (puzzleCaps, input) > 0 then
 for i : 1 .. length (puzzleCaps)
 if puzzleCaps (i) = input then
 unString := unString (1 .. i - 1) + input + unString (i + 1 .. *)
 end if
 end for
 elsif index (puzzleCaps, input) = 0 then
 bodyCount += 1
 end if
 
 end loop
 
 |