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

Username:   Password: 
 RegisterRegister   
 Hangman Game (Graphics won't remain on screen)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Loomis




PostPosted: Wed Dec 16, 2009 6:13 pm   Post subject: 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. Sad

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

Turing:


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)

                        %[Man] Chest
                        if mistake = 1 then
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm
                        elsif mistake = 2 then
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm
                        elsif mistake = 3 then
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm, Left Leg
                        elsif mistake = 4 then
                            drawline (835, 280, 865, 250, black)
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm, Left Leg, Right Leg
                        elsif mistake = 5 then
                            drawline (835, 280, 805, 250, black)
                            drawline (835, 280, 865, 250, black)
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)
                            delay (1000)
                        end if

                        %Winning Page
                        for i : 1 .. length (animals (a))
                            if dash (i) = animals (a) then
                                cls
                                put ""
                                put "YOU WIN!!"
                                put ""
                                put "Good Job!!"
                                exit
                            end if
                        end for

                        %Losing Page
                        if mistake = 5 then
                            cls
                            put ""
                            put "GAME OVER!!"
                            put ""
                            put "The word was ", (animals (a)), "."
                            put ""
                            put "Better luck next time!!"
                            exit
                        end if
                    end if
                end loop
                exit
            %Category is "Cartoons"
            elsif choice = 2 then
                randint (a, 1, 5)
                %Dashes
                var dash : array 1 .. length (cartoons (a)) of string
                for i : 1 .. length (cartoons (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 (cartoons (a))
                        if letter = cartoons (a) (i) then
                            dash (i) := letter
                        end if
                    end for
                    for i : 1 .. length (cartoons (a))
                        put dash (i), " " ..
                    end for
                    for i : 1 .. length (cartoons (a))
                        right := right + index (dash (i), " _ ")
                    end for

                    %Mistakes
                    if index (cartoons (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)

                        %[Man] Chest
                        if mistake = 1 then
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm
                        elsif mistake = 2 then
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm
                        elsif mistake = 3 then
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm, Left Leg
                        elsif mistake = 4 then
                            drawline (835, 280, 865, 250, black)
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm, Left Leg, Right Leg
                        elsif mistake = 5 then
                            drawline (835, 280, 805, 250, black)
                            drawline (835, 280, 865, 250, black)
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)
                            delay (1000)
                        end if
                    end if
                   
                    %Winning Page
                    for i : 1 .. length (cartoons (a))
                        if dash (i) = cartoons (a) then
                            cls
                            put ""
                            put "YOU WIN!!"
                            put ""
                            put "Good Job!!"
                            exit
                        end if
                    end for
                   
                    %Losing Page
                    if mistake = 5 then
                        cls
                        put ""
                        put "GAME OVER!!"
                        put ""
                        put "The word was ", (cartoons (a)), "."
                        put ""
                        put "Better luck next time!!"
                        exit
                    end if
                end loop
                exit
               
                %Category is "Random"
            elsif choice = 3 then
                randint (a, 1, 5)
               
                %Dashes
                var dash : array 1 .. length (random (a)) of string
                for i : 1 .. length (random (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 (random (a))
                        if letter = random (a) (i) then
                            dash (i) := letter
                        end if
                    end for
                    for i : 1 .. length (random (a))
                        put dash (i), " " ..
                    end for
                    for i : 1 .. length (random (a))
                        right := right + index (dash (i), " _ ")
                    end for

                    %Mistakes
                    if index (random (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)

                        %[Man] Chest
                        if mistake = 1 then
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm
                        elsif mistake = 2 then
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm
                        elsif mistake = 3 then
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm, Left Leg
                        elsif mistake = 4 then
                            drawline (835, 280, 865, 250, black)
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)

                        %[Man] Chest, Right Arm, Left Arm, Left Leg, Right Leg
                        elsif mistake = 5 then
                            drawline (835, 280, 805, 250, black)
                            drawline (835, 280, 865, 250, black)
                            drawline (835, 310, 805, 340, black)
                            drawline (835, 310, 865, 340, black)
                            drawline (835, 340, 835, 280, black)
                            delay (1000)
                        end if
                    end if
                   
                    %Winning Page
                    for i : 1 .. length (random (a))
                        if dash (i) = random (a) then
                        Text.Cls
                           
                            put ""
                            put "YOU WIN!!"
                            put ""
                            put "Good Job!!"
                            exit
                        end if
                    end for
                    if mistake = 5 then
                        cls
                        put ""
                        put "GAME OVER!!"
                        put ""
                        put "The word was ", (random (a)), "."
                        put ""
                        put "Better luck next time!!"
                        exit
                    end if
                end loop
                exit
            else
                % Incorrect Input for "Categories"
                put "That is an invalid choice, please enter a valid number."
            end if
        end loop
    elsif choice = 2 then
        % The does not wish to play
        put "Goodbye"
        exit
    else
        % Incorrect Input for "Wanting/Not Wanting to Play"
        put "That is an invalid choice, please enter a valid number."
    end if
end loop



Please specify what version of Turing you are using
Turing Version 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
yumrum




PostPosted: Sat Dec 19, 2009 10:19 pm   Post subject: 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




PostPosted: Sat Dec 19, 2009 11:20 pm   Post subject: 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)

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...


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.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: