
-----------------------------------
WhatDotColourMaster
Sun Dec 04, 2005 9:04 pm

HANGMAN
-----------------------------------

The falowing code was orgainl posted here:
http://www.compsci.ca/v2/viewtopic.php?t=2769&highlight=creates+procedures+drawing+hangman

The user in question has copyed the code in almost competation with giving litte to no cerited to the orgianl poster. Therefor the topic is being locked. For any questions or coments realting to the code pleas post them in the orgianl topic.


Well, this is my hangman game...still working to make it better but check it out and give me messages for more improvements...


%hangman 
%creates procedures for drawing hangman 
%head 


var font := Font.New ("serif:24") 

Draw.Text ("Welcome to WhatDotColour'z Hangman Game!", 180, 10, font, blue) 
proc draw1 
    drawoval (560, 250, 20, 20, black) 
end draw1 
%body 
proc draw2 
    drawline (560, 230, 560, 170, black) 
end draw2 
%arms 
proc draw3 
    drawline (560, 200, 540, 170, black) 
end draw3 

proc draw4 
    drawline (560, 200, 585, 170, black) 
end draw4 
%legs 
proc draw5 
    drawline (560, 170, 530, 130, black) 
end draw5 

proc draw6 
    drawline (560, 170, 585, 130, black) 
end draw6 
%noose 
proc draw7 
drawline (550, 255, 555, 245, black) 
    drawline (555, 255, 550, 245, black) 
end draw7 
proc draw8 
    drawline (565, 255, 570, 245, black) 
    drawline (570, 255, 565, 245, black) 
end draw8 
proc draw9 
    drawarc (563, 230, 7, 7, 20, 160, black) 
end draw9 

%end drawing stickman 

var d, f : int := 1 
var word : array 1 .. 10 of string := init ("dog", "cat", "mouse", "tiger", "human", 
    "box", "fox", "map", "rat", "car") %some words to guess from 
var a, counter, ind, counter1, counter3, add : int := 0 
var letter, guess, guessed, wor : string := "" 
var font2 := Font.New ("serif:12") 
var z := 15 
randint (a, 1, 10) %chooses a random word 
%inputs same number of lines as the number of letters 

loop 
    add := 0 
    for b : 1 .. length (word (a)) 
        Draw.Text (" _ ", maxx div 2 + add - 13, maxy div 2, font, red) 
        add := add + 20 
    end for 
    wor := word (a) 
    drawline (545, 230, 535, 290, black) 
    drawline (560, 290, 460, 290, black) 
    drawline (460, 290, 460, 100, black) 
    drawline (435, 100, 510, 100, black) 
    drawoval (560, 230, 15, 5, black) 

    loop 

        locate (1, 1) 
        put "Please guess a letter: " .. 

        get letter 
Draw.Text ("Already guessed, please enter another letter.", 0, 250, font2, white) 
        ind := index (word (a), letter) %checks if letter is in the word 
        if ind not= 0 and index (guessed, letter) = 0 

                then %if letter is found, then put the letter above the corresponding space 

            Draw.Text (letter, maxx div 2 + 20 * ind - 24, maxy div 2, font, red) 
            counter := counter + 1 
            locate (5, 1) 
            put "Would you like to guess the word?(Y/N)?" 
            get guess 
            if guess = "Y" or guess = "y" 
                    then 
                locate (7, 1) 
                put "Guess: " .. 
                get guess 
                if guess = word (a) then 
                    counter := length (word (a)) 
                    locate (5, 1) 
                    put "                             " 
                    locate (7, 1) 
                    put "                             " 
                else 
                    cls 
                    counter3 := 6 
                    cls 
                end if 
            end if 
            exit 

        end if 
        if guessed not= "" then 
            if index (guessed, letter) not= 0 then 
                locate (maxrow - 10, 1) 
                Draw.Text ("Already guessed, please enter another letter.", 0, 250, font2, red) 

            end if 
        end if 
        exit 
    end loop 
    guessed := guessed + letter 
    locate (maxrow - 5, 10) 
    if index (guessed, letter) not= 0 then 
        Draw.Text ("Guessed Letters: ", 17, 85, font2, black) 
        Draw.Text (letter, z, 65, font2, black) 

        z := z + 20 
    end if 
    %calls procedures to draw stickman, if letter not found 
    if ind = 0 and counter3 = 0 then 
        draw1 
        counter3 := counter3 + 1 
    elsif ind = 0 and counter3 = 1 then 
        draw2 
        counter3 := counter3 + 1 
    elsif ind = 0 and counter3 = 2 then 
        draw3 
        counter3 := counter3 + 1 
    elsif ind = 0 and counter3 = 3 then 
        draw4 
        counter3 := counter3 + 1 
    elsif ind = 0 and counter3 = 4 then 
        draw5 
        counter3 := counter3 + 1 

    elsif ind = 0 and counter3 = 5 then 
        draw6 
        counter3 := counter3 + 1 

    elsif ind = 0 and counter3 = 6 then 
        draw7 
        counter3 := counter3 + 1 
    elsif ind = 0 and counter3 = 7 then 
        draw8 
        counter3 := counter3 + 1 
    elsif ind = 0 and counter3 = 8 then 
        draw9 
        counter3 := counter3 + 1 
    end if 

    exit when counter3 = 9 or counter = length (word (a)) 

end loop 
delay (1000) 

font := Font.New ("serif:26") 
if counter3 = 9 then 
    loop %if you dont guess right in time, you loose 
        cls 
        randint (a, 32, 150) 
        Draw.Text ("THE WORD IS: ", 0, maxy - 50, font, a) 
        Draw.Text (wor, 230, maxy - 50, font, a) 
        Draw.Text ("Sorry, You got HANGED, please try again!", 0, maxy - 80, font, a) 
        drawline (545, 230, 535, 290, black) 
        drawline (560, 290, 460, 290, black) 
        drawline (460, 290, 460, 100, black) 
        drawline (435, 100, 510, 100, black) 
        drawoval (560, 230, 15, 5, black) 
        draw1 
        draw2 
        draw3 
        draw4 
        draw5 
        draw6 
        draw7 
        draw8 
        draw9 
        delay (100) 

    end loop 
end if 


if counter = length (word (a)) then 
    cls 
    randint (f, 1, maxy) 
    randint (d, 1, maxx) 
    loop % if you do guess right, you win 
        randint (a, 32, 150) 
        randint (f, 1, maxy) 
        randint (d, 1, maxx) 
        Draw.Text ("YOU WIN!!!", 0, maxy - 200, font, a) 
        Draw.Text ("THE WORD IS: ", 0, maxy - 50, font, a) 
        Draw.Text (wor, 230, maxy - 50, font, a) 
        drawfillstar (0 + d, 0 + f, 25 + d, 25 + f, a) 
        delay (100) 

    end loop 
end if 

