
-----------------------------------
Devon_Jones
Sun Jan 23, 2011 4:18 pm

Turing Help
-----------------------------------
%Hangman Title
%DRAW ROAD (1P)
Draw.FillBox (00, 00, maxx, maxy, green)
Draw.FillBox (300, 00, 550, maxy, grey)
Draw.ThickLine (425, 00, 425, maxy, 10, yellow)

%DRAW RED CAR (1P)
Draw.FillBox (330, 10, 390, 70, red)
Draw.Box (340, 20, 380, 55, black)
Draw.ThickLine (330, 10, 390, 10, 05, black)
Draw.ThickLine (330, 70, 390, 70, 05, black)
%DRAW LIGHTS RED CAR
Draw.FillBox (370, 67, 390, 71, yellow)
Draw.FillBox (330, 67, 350, 71, yellow)
Draw.FillBox (370, 13, 390, 09, brightred)
Draw.FillBox (330, 13, 350, 09, brightred)

%DRAW Police(1P)
Draw.FillBox (460, 10, 520, 70, black)
Draw.FillBox (470, 20, 510, 55, white)
Draw.ThickLine (460, 10, 520, 10, 05, black)
Draw.ThickLine (460, 70, 520, 70, 05, black)
Draw.ThickLine (480, 70, 480, 71, 10, black)
Draw.ThickLine (500, 70, 500, 71, 10, black)
Draw.ThickLine (500, 10, 500, 09, 10, black)
Draw.ThickLine (480, 10, 480, 09, 10, black)
%DRAW LIGHTS Police
Draw.FillBox (460, 67, 480, 71, yellow)
Draw.FillBox (500, 67, 520, 71, yellow)
Draw.FillBox (460, 13, 480, 09, brightred)
Draw.FillBox (500, 13, 520, 09, brightred)
Draw.FillBox (472, 40, 487, 44, blue)
Draw.FillBox (492, 40, 507, 44, red)
%Hangman Questions
colourback (green)
put "To Move Foward, Guess the Word, One Letter at a Time"
%Hangman Syntax
var words : array 1 .. 10 of string := init ("engine", "tires", "brakes", "lion", "puma", "gorrilla", "eagle", "soccer", "basketball", "hockey")
var font : int
var unString, unDisplay : string := ""  % Phrase with underlines, To display
font := Font.New ("serif:12")
var wrong, times : int := 0
var userinput : string
var i : int := (Rand.Int (1, 10))
var underscore : array 1 .. length (words (i)) of string
var letter, word, choice : string := ""

for o : 1 .. length (words (i))
    underscore (o) := " _ "
end for

for o : 1 .. length (words (i))
    put underscore (o) ..
end for

locate (3,1)
put words(i)

loop
    get userinput
    put userinput

    for k : 1 .. length (words (i))
        var p : char := words (i) (k)
        if userinput = p then
            underscore (k) := userinput
        end if
    end for
    for w : 1 .. length (words (i))
        var p : char := words (i) (w)
        if userinput = p then
            underscore (w) := userinput
        end if
    end for
end loop


This is my hangman program so far. I'm trying to be a little creative instead of hanging a man its kind of like a race. But I don't know how to match the userinput with the actual word. If you try to run the program you will see that the userinput doesn't do anything. Can someone please help me? I need to match the userinput with the actual word and if its wrong tell them its wrong. I've been looking at other peoples programs, and they are using arrays and stuff, but I'm not quite sure what to do? Thanks in advance  :mrgreen:

-----------------------------------
Raknarg
Thu Feb 17, 2011 10:48 am

RE:Turing Help
-----------------------------------
Lol, im sorry, but the coding's just kindof pissing me off. I'll show you mine, see what you can do with it.

var word, fullword, dashes : string := ""
var ab : string := "abcdefghijklmnopqrstuvwxyz"
var AB : string := "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var guessedletters : string := ""
var guess : string (1)
var lettersleft : int := 0
var hangman : int := 0
var x : int := maxx - 75
var y : int := maxy - 100
var again : string (1)
var space : string := " "

loop
    put "Insert a word/sentance... (no caps or punctuation) "
    get word : *

    fullword := word

    for i : 1 .. length (word)

        if index (word (i), space) = 0 then
            dashes := dashes + "-"
        elsif index (word (i), space) not= 0 then
            dashes := dashes + "/"
        end if

    end for

    loop

        cls
        
        
        for k : 1 .. 26
            if index (word, ab (k)) not= 0 then
                lettersleft := lettersleft + 1
            end if
        end for
        
        % The hangman
        if hangman = 1 then
            Draw.FillOval (x, y, 30, 30, black)
        elsif hangman = 2 then
            Draw.FillOval (x, y, 30, 30, black)
            Draw.ThickLine (x, y, x, y - 150, 10, black)
        elsif hangman = 3 then
            Draw.FillOval (x, y, 30, 30, black)
            Draw.ThickLine (x, y, x, y - 150, 10, black)
            Draw.ThickLine (x, y - 150, x - 50, y - 200, 10, black)
        elsif hangman = 4 then
            Draw.FillOval (x, y, 30, 30, black)
            Draw.ThickLine (x, y, x, y - 150, 10, black)
            Draw.ThickLine (x, y - 150, x - 50, y - 200, 10, black)
            Draw.ThickLine (x, y - 150, x + 50, y - 200, 10, black)
        elsif hangman = 5 then
            Draw.FillOval (x, y, 30, 30, black)
            Draw.ThickLine (x, y, x, y - 150, 10, black)
            Draw.ThickLine (x, y - 150, x - 50, y - 200, 10, black)
            Draw.ThickLine (x, y - 150, x + 50, y - 200, 10, black)
            Draw.ThickLine (x, y - 50, x - 50, y - 75, 10, black)
        elsif hangman = 6 then
            Draw.FillOval (x, y, 30, 30, black)
            Draw.ThickLine (x, y, x, y - 150, 10, black)
            Draw.ThickLine (x, y - 150, x - 50, y - 200, 10, black)
            Draw.ThickLine (x, y - 150, x + 50, y - 200, 10, black)
            Draw.ThickLine (x, y - 50, x - 50, y - 75, 10, black)
            Draw.ThickLine (x, y - 50, x + 50, y - 75, 10, black)
        end if


        exit when
            lettersleft = 0 or
            hangman = 6

        lettersleft := 0

        put guessedletters
        put dashes
        put ""
        put "Pick a letter..."
        getch (guess)

        if index (word, guess) not= 0 then
            for j : 1 .. length (word)
                if guess = word (1) then
                    dashes := guess + dashes (2 .. *)
                    word := "-" + word (2 .. *)
                elsif guess = word (*) then
                    dashes := dashes (1 .. * -1) + guess
                    word := word (1 .. * -1) + "-"
                elsif guess = word (j) and guess not= word (1) and guess not= word (*) then
                    dashes := dashes (1 .. index (word, guess) - 1) + guess + dashes (index (word, guess) + 1 .. *)
                    word := word (1 .. index (word, guess) - 1) + "-" + word (index (word, guess) + 1 .. *)
                end if
            end for
        elsif index (guessedletters, guess) = 0 then
            put "Try again."
            delay (1000)
            hangman := hangman + 1
        end if

        if index (guessedletters, guess) = 0 then
            guessedletters := guess + " " + guessedletters
        else
            put "You already guessed that letter!"
            delay (1000)
        end if

    end loop

    put "The word was: ", fullword

    if lettersleft = 0 then
        put "You win!!!"
    elsif hangman = 6 then
        put "YOU LOSE"
    end if
    put ""
    put "Play again? (y or n)"

    if hangman = 6 then
        Draw.FillOval (x, y, 30, 30, black)
        Draw.ThickLine (x, y, x, y - 150, 10, black)
        Draw.ThickLine (x, y - 150, x - 50, y - 200, 10, black)
        Draw.ThickLine (x, y - 150, x + 50, y - 200, 10, black)
        Draw.ThickLine (x, y - 50, x - 50, y - 75, 10, black)
        Draw.ThickLine (x, y - 50, x + 50, y - 75, 10, black)
        Draw.Line (x, y, x, maxy, brown)
        Draw.ThickLine (x, maxy, maxx, maxy, 20, brown)
        Draw.ThickLine (maxx, maxy, maxx, 50, 20, brown)
        Draw.ThickLine (maxx, 50, maxx - 200, 50, 20, brown)
    end if

    getch (again)

    exit when
        again = "n"

    hangman := 0
    word := ""

end loop

It's probs confusing, so ask if you have questions with it. Btw, i didn't use arrays for my words, i used a choose your on word kind of thing.

-----------------------------------
TokenHerbz
Thu Feb 17, 2011 12:18 pm

RE:Turing Help
-----------------------------------
1) This post should be in the Turing Help Forums.
2) If you can't assist people then don't. We should teach people so they learn, and giving them crappy code doesn't teach them much.

3) You need to have your word obviously, and when a user enters in a guess, You should check threw that word for such a letter.  If there is something found you display this letter, otherwise you add on a "X" or part of the dude, whichever one prefers.

I would suggest creating a function(recommended), or even a procedure if its easier, that can take in a letter and check it vs the word, and results will do the necessary step.  

This will help with repetitiveness...


Last thing i wanted to share..  Use Tags with your codes,

%% 

Edits: Fixing Syntax problembs (double putting them don't work how i wanted)

-----------------------------------
huskiesgoaler34
Thu Feb 17, 2011 9:06 pm

Re: Turing Help
-----------------------------------
I am just wondering. How are you planning to move your cars? You don't have any code that checks to see the letters are right/words are right in order to move the cars? I would suggest using a image you made in Illustrator/Photshop/Paint, whatever and importing that to the screen. Raknarg's program works pretty well (although formatting could be better) so use that as a guideline. And for goodness sake, please comment/document your codes. It's pretty hard understanding what you are trying to make your program do.

A word appears at the bottom of the different lines at the top of the screen. Are you supposed to enter that exact word in?

To answer your question. Check if the inputted letters are the same in the inputted word. So if hello was inputted and then an h, then your car should move. If the letter is wrong, then the car doesn't move. You can check by storing each character (each letter) as an array. If each letter is correct then...move the car, else don't move the car.
