Page 1 of 1

Turing: Hangman

Posted: Tue Jan 22, 2008 8:06 pm
by Anonymous
So I'm stuck with my hangman game right now.

Code: Select all

import shape in "shape.tu"

var found : boolean := false
var choice, letter : string
var font1 : int
font1 := Font.New ("Comic Sans MS:20")

colorback (53)
cls
put "Do you want to Play?"
put "Yes"
put "No"
get choice
if choice = "Yes" or choice = "YES" or choice = "yes" then
    cls
    put "Choose a Category"
    put "1. Animals"
    put "2. Music"
    put "3. Solar System"
    put "4. Vegetables"
    put "5. Transportation"
    put "Enter 1, 2, 3, 4 or 5, the press 'Enter'"
    get choice
    cls
    case choice of
        label "1" :
            put "Animals"
            Draw.Line (500, 100, 500, 280, black)
            Draw.Line (400, 280, 500, 280, black)
            Draw.Line (400, 260, 400, 280, black)
            Draw.Line (20, 100, 50, 100, black)
            Draw.Line (60, 100, 90, 100, black)
            Draw.Line (100, 100, 130, 100, black)
            Draw.Line (140, 100, 170, 100, black)
            Draw.Line (180, 100, 210, 100, black)
            Draw.Line (220, 100, 250, 100, black)
            loop
                put "Guess a letter"
                get letter
                for i : 1 .. 20
                    if letter = "b" or letter = "B" then
                        Font.Draw (letter, 20, 100, font1, 12)
                    elsif letter = "e" or letter = "E" then
                        Font.Draw (letter, 60, 100, font1, 12)
                        Font.Draw (letter, 180, 100, font1, 12)
                    elsif letter = "a" or letter = "A" then
                        Font.Draw (letter, 100, 100, font1, 12)
                    elsif letter = "v" or letter = "V" then
                        Font.Draw (letter, 140, 100, font1, 12)
                    elsif letter = "r" or letter = "R" then
                        Font.Draw (letter, 220, 100, font1, 12)
                    end if
                end for
                if found = true then
                else
                    cls
                end if
            end loop
    end case
end if
[code]

This is what I have, and I am completely stuck. Anyone be able to help me figure out how to make this work?
My problems are:
I can't get the pieces of the hangman to show up when the letter is wrong. I can't even get the letter to show up when it's right! I just need to get it working properly. So can anyone help me? Or does anyone have a hangman game that's done that I could use for a referance? I am desperate for help. Please anyone?

Thanks :). 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:4984, old post ID:38653[/size][/color]

Turing: Hangman

Posted: Wed Oct 01, 2008 3:09 pm
by onykage
i wish i would have noticed this thread a year ago. Well for future inquiries,

first problem is label is not ended,
label "1" :
<-- you only have 1 choice. label acts like a switch. You have to close it.

another problem is

Code: Select all

if found = true then[code]
$found = false; nothing anywhere in the code sets $found = true.

[code]#boolean is a logic statement
#this is an example of reverse logic
found = true;
if( !found )
    println ('found is false')
else
    println ('found is true')
end if[code]

another problem is
[code]if letter = "b" or letter = "B" then
   Font.Draw (letter, 20, 100, font1, 12)
elsif letter = "e" or letter = "E" then
    Font.Draw (letter, 60, 100, font1, 12)
    Font.Draw (letter, 180, 100, font1, 12)
elsif letter = "a" or letter = "A" then
     Font.Draw (letter, 100, 100, font1, 12)
elsif letter = "v" or letter = "V" then
     Font.Draw (letter, 140, 100, font1, 12)
elsif letter = "r" or letter = "R" then
     Font.Draw (letter, 220, 100, font1, 12)
end if
[code]
this is a switch statement.  when you have if()elseif()--> you have to end with else and then end if. like so..
[code]#a switch is used if->elseif->elseif->else->end
if( white == "black" )
    do something
else if( white == "green" )
    do something else
else
    do this if all else fails
end if[code]


thats just a few bugs that jumped out at me, there is ALOT more wrong with this code snippit.  I just hope someone learning turing or programming can look at this thread and understand how and why some of these problems exist, and possibly find other problems. 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:4984, old post ID:38954[/size][/color]