
-----------------------------------
Loomis
Wed Dec 16, 2009 6:13 pm

Hangman Game (Graphics won't remain on screen)
-----------------------------------
What is it you are trying to achieve?
I'm currently writing a program of a VERY basic hangman game. It's not completely finished yet and the code can do with a lot of editing. 

What is the problem you are having?
Well firstly, the coding is not very efficent, since for each category the same codes have to be repeated over and over again. 
But mainly, the problem is the winning page does not show! If the user wins the game, nothing happens. The page won't clear and show the winning screen.    :( 

Describe what you have tried to solve this problem
I tried putting cls in the middle of the loop but it just doesn't seem to work. 

Post any relevant code



setscreen ("graphics:1000;650") 
var choice : int 
var letter : string 
var wrongGuesses : string := "" 
var a, mistake, correct, right : int := 0 
var animals : array 1 .. 5 of string := init ("hippopotamus", "panda", "rooster", "llama ", "tiger") 
var cartoons : array 1 .. 5 of string := init ("spongebob", "cozmo", "clifford", "tigger", "tweety") 
var random : array 1 .. 5 of string := init ("steak", "history", "clowns", "fingers", "yellow") 

loop 
    put "Would you like to play this game?" 
    put "1-Yes 2-No" 
    get choice 
    cls 

    %Category Choices 
    if choice = 1 then 
        loop 
            put "0-Instructions" 
            put "Please choose a category:" 
            put "1-Animals" 
            put "2-Cartoons" 
            put "3-Random" 
            get choice 
            cls 

            %Instructions 
            if choice = 0 then 
                put "Instructions:" 

            %Category is "Animals" 
            elsif choice = 1 then 
                randint (a, 1, 5) 
                %Dashes 
                var dash : array 1 .. length (animals (a)) of string 
                for i : 1 .. length (animals (a)) 
                    dash (i) := " _ " 
                    put dash (i) .. 
                end for 
                loop 
                    put "" 
                    put "" 
                    put "Incorrect Guesses:" 
                    put wrongGuesses 
                    put "" 
                    put "Please enter one letter:" 
                    get letter 
                    cls 

                    %Correct Letter 
                    for i : 1 .. length (animals (a)) 
                        if letter = animals (a) (i) then 
                            dash (i) := letter 
                        end if 
                    end for 
                    for i : 1 .. length (animals (a)) 
                        put dash (i), " " .. 
                    end for 
                    for i : 1 .. length (animals (a)) 
                        right := right + index (dash (i), " _ ") 
                    end for 

                    %Mistakes 
                    if index (animals (a), letter) = 0 then 
                        mistake := mistake + 1 
                        wrongGuesses := wrongGuesses + letter 

                        %Gallows 
                        drawfillbox (740, 170, 760, 410, black) 
                        drawfillbox (760, 390, 860, 410, black) 
                        drawfillbox (700, 160, 900, 180, black) 
                        drawfillbox (830, 390, 840, 358, black) 
                        drawfilloval (835, 355, 15, 15, black) 

                        %

Please specify what version of Turing you are using
Turing Version 4.1.1

-----------------------------------
yumrum
Sat Dec 19, 2009 10:19 pm

Re: Hangman Game (Graphics won't remain on screen)
-----------------------------------
k so i would try View.Update after u draw everything for example...

[code]
%all your game%
%Winning page
cls
%draw and put all the stuff u want on the screen
View.Update
[\code]

and i prefer cls to Text.cls because cls just wipes the whole screen so u can start afresh

-----------------------------------
TheGuardian001
Sat Dec 19, 2009 11:20 pm

Re: Hangman Game (Graphics won't remain on screen)
-----------------------------------
He isn't using offscreenonly, View.Update will do nothing.

The problem is that you're trying to compare an array of strings to a single string.

in your for loop, you compare, for example
[code]
if dash(i) = animal(a)
[/code]
in a for loop. Lets assume they have the right word, and go through this manually. If the word is tiger:
[code]
first repetition, i = 1
    dash(1) = "t"
    is "t" equal to "tiger"?
        No.
second repetition, i = 2
    dash(2) = "i"
    is "i" equal to "tiger"?
        No.
etc...
[/code]

If you combine each element of your array of strings into a single string, you would be able to compare the two properly.

Edit: also, you spelled "llama" with a space.
