Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 My hangman only draws in one part of the program <_<
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HyperFlexed




PostPosted: Sat Nov 06, 2004 9:19 pm   Post subject: My hangman only draws in one part of the program <_<

It isn't done. But I am having trouble, I have a screen where it prompts the user for a phrase to be used. Before it I have used my DrawHangman procedure. I figured I'd add it to make things fancy and get a few extra marks. Now I've traced it on paper, but I don't see why it won't draw.

also, and inneficiencies you could point out would be cool. I'm also looking for ideas.

code:

% 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


note that the hangman draws in the main part of the game.
Sponsor
Sponsor
Sponsor
sponsor
HyperFlexed




PostPosted: Sat Nov 06, 2004 9:24 pm   Post subject: (No subject)

hah, I just thought of one way to be more efficient. Instead of using puzzleCaps, I could catenate it into puzzle on the end, and then I could initialize puzzle as...

code:

puzzle := puzzle ((length(puzzle) div 2) + 1 .. *)


I'm clever... Laughing
HyperFlexed




PostPosted: Sun Nov 07, 2004 2:39 am   Post subject: (No subject)

yeah so.. any help would be appreciated.
HyperFlexed




PostPosted: Sun Nov 07, 2004 2:06 pm   Post subject: (No subject)

http://www.compsci.ca/v2/viewtopic.php?t=6573

I fixed it. I realized that in my DrawHangman procedure, I was checking the value of bodyCount (global), when I should have been checking state (local)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: