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

Username:   Password: 
 RegisterRegister   
 Anyone know how to fix this?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zoltrix




PostPosted: Wed Jun 11, 2008 11:02 am   Post subject: Anyone know how to fix this?

I have to create a "Wheel of Fortune" type game, and so far it's working up to par. Only problem is that i only have one player at a time. Anyone have an idea as to how i can have 2 players?

here's my program:

Turing:
var sn, counter, wheelValue, playerTotal : int := 0
var word, letter, guess, response, spinResponse, vowelguess, consonantguess : string := " "
var alphabet : array 1 .. 26 of string := init ("A", "B", "C", "D", "E", "F", "G", "H", "I",
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
open : sn, "WheelOfFortune.txt", get     %Open file to read.

loop
    get : sn, word
    exit when eof (sn)
end loop

close : sn

var puzzle : array 1 .. length (word) of string

proc SPINWHEEL
    var wheel : array 1 .. 24 of int := init (0, 1500, 800, 600, 2000, 500, 250, 350,
        - 1, 200, 250, 600, 0, 300, 100, 450, 400, 200, 300, 550, 400, 350, 500, 700)
    var n : int := 0
    randint (n, 1, 24)
    if wheel (n) = -1 or wheel (n) = 0 then
        wheelValue := 0
    else
        wheelValue := wheel (n)
    end if
    locate (16, 20)
    put "                                   "
    locate (16, 20)
    put "Wheel Value: " ..
    put wheelValue
    locate (16, 42)
    put "                                   "
    locate (16, 42)
    put "Player Total: $", playerTotal
end SPINWHEEL

proc PUZZLEANSWER
    locate (11, 1)
    put "What is the word? " ..
    get guess
    if guess = word then
        locate (13, 1)
        put "YOU WON!"
        locate (3, 32)
        for i : 1 .. length (word)
            put word (i .. i) : 2 ..
        end for
    else
        locate (13, 1)
        put "Please try again"
    end if
end PUZZLEANSWER

proc BUYVOWEL



    if playerTotal >= 300 then

        locate (5, 1)
        put "                               "
        locate (5, 1)
        put "Please guess a vowel: " ..
        get vowelguess

        if vowelguess = "A" or vowelguess = "E" or vowelguess = "I" or
        vowelguess = "O" or vowelguess = "U" or vowelguess = "Y" then

            if index (word, vowelguess) not= 0 then
                locate (7, 1)
                put "                               "
                locate (7, 1)
                put "contains the vowel ", vowelguess
                playerTotal := playerTotal - 300

                locate (16, 42)
                put "                               "
                locate (16, 42)
                put "Player Total: $", playerTotal
                for i : 1 .. length (word)
                    if word (i) = vowelguess then
                        puzzle (i) := vowelguess
                    end if
                end for
                SPINWHEEL
            else
                locate (7, 1)
                put "                               "
                locate (7, 1)
                put "does not conatain the vowel ", vowelguess
                locate (16, 42)
                put "                               "
                locate (16, 42)
                playerTotal := playerTotal - 300
                put "Player Total: $", playerTotal
            end if
        else
            locate (7, 1)
            put "                               "
            locate (7, 1)
            put vowelguess, " is not a vowel. You lose your turn."
            locate (16, 42)
            put "                               "
            locate (16, 42)
            playerTotal := playerTotal - 300
            put "Player Total: $", playerTotal
            wheelValue := -1
        end if
    else
        put "You do not have enough money to buy a vowel. Please try again."
    end if

    locate (20, 15)
    for i : 1 .. 26
        if vowelguess = alphabet (i) then
            alphabet (i) := "_"
        end if
        put alphabet (i) : 2 ..
    end for

    for i : 1 .. length (word)
        if word (i) = vowelguess then
            puzzle (i) := vowelguess
        end if
    end for

    locate (3, 32)
    for i : 1 .. length (word)
        put puzzle (i) : 2 ..
    end for

end BUYVOWEL

proc GUESSLETTER

    var consonants : string := " "

    locate (5, 1)
    put "                               "
    locate (5, 1)
    put "Please guess a letter: " ..
    get consonantguess

    if consonantguess = "A" or consonantguess = "E" or consonantguess = "I" or
    consonantguess = "O" or consonantguess = "U" or consonantguess = "Y" then

        locate (7, 1)
        put "                               "
        locate (7, 1)
        put consonantguess, " is a vowel. You lose your turn."
        locate (16, 42)
        put "                               "
        locate (16, 42)
        playerTotal := playerTotal - 300
        put "Player Total: $", playerTotal
        wheelValue := -1

    else

        if index (word, consonantguess) not= 0 then
            locate (7, 1)
            put "                               "
            locate (7, 1)
            put "contains the letter ", consonantguess

            locate (16, 42)
            put "                               "
            locate (16, 42)
            put "Player Total: $", playerTotal
            for i : 1 .. length (word)
                if word (i) = consonantguess then
                    puzzle (i) := consonantguess
                end if
            end for
        else
            locate (7, 1)
            put "                               "
            locate (7, 1)
            put "does not conatain the letter ", consonantguess
            locate (16, 42)
            put "                               "
            locate (16, 42)
            put "Player Total: $", playerTotal
        end if

    end if

end GUESSLETTER

for i : 1 .. length (word)
    puzzle (i) := "_"
end for

locate (1, 32)
put "WHEEL OF FORTUNE!"

locate (3, 32)
for i : 1 .. length (word)
    put puzzle (i) : 2 ..
end for


loop

    put skip

    loop
        loop
            locate (4, 1)
            put "What would you like to do?"
            locate (5, 1)
            put "F2= Spin Wheel   F3= Buy Vowel   F4= Guess Puzzle   " ..
            get spinResponse
            exit when ord (spinResponse) = 188 or ord (spinResponse) = 189 or ord
            (spinResponse) = 190
        end loop
        if ord (spinResponse) = 188 then
            SPINWHEEL
        elsif ord (spinResponse) = 189 then
            BUYVOWEL
        elsif ord (spinResponse) = 190 then
            PUZZLEANSWER
        end if
        exit when ord (spinResponse) = 188
    end loop

    locate (4, 1)
    put "                                                                       "
    locate (5, 1)
    put "                                                                       "

    if wheelValue = 0 then
        playerTotal := 0
        locate (19, 30)
        put "You got bankrupt!"
        locate (16, 10)
        put "                               "
        locate (16, 10)
        put "Player Total: $", playerTotal
    elsif wheelValue = -1 then
        playerTotal := playerTotal
        locate (19, 30)
        put "You lost a turn!"
        locate (16, 45)
        put "                               "
        locate (16, 45)
        put "Player Total: $", playerTotal
    else
        GUESSLETTER
    end if

    loop
        if index (word, consonantguess) not= 0 then
            locate (7, 1)
            put "                               "
            locate (7, 1)
            put "contains an ", consonantguess
            playerTotal := playerTotal + wheelValue
            locate (16, 42)
            put "                               "
            locate (16, 42)
            put "Player Total: $", playerTotal
            for i : 1 .. length (word)
                if word (i) = consonantguess then
                    puzzle (i) := consonantguess
                end if
            end for
        else
            locate (7, 1)
            put "                               "
            locate (7, 1)
            put "does not conatain an ", consonantguess
            locate (16, 42)
            put "                               "
            locate (16, 42)
            put "Player Total: $", playerTotal
            exit
        end if

        locate (3, 32)
        for i : 1 .. length (word)
            put puzzle (i) : 2 ..
        end for

        if wheelValue = 0 or wheelValue = -1 then
            locate (21, 1)
            put "Next Players Turn"
            exit
        else
            locate (9, 1)
            put "                                   "
            locate (9, 1)
            put "Do you want to guess the puzzle? (Y/N) " ..
            get response
        end if

        locate (9, 1)
        put "                                                                 "
        locate (7, 1)
        put "                                                                 "
        if response = "Y" then
            locate (11, 1)
            put "What is the word? " ..
            get guess
            if guess = word then
                locate (13, 1)
                put "YOU WON!"
                locate (3, 30)
                for i : 1 .. length (word)
                    put word (i .. i) : 2 ..
                end for
                exit
            else
                locate (13, 1)
                put "Incorrect. You lose your turn"
                exit
            end if
        elsif
                response = "N" then
            exit
        end if
    end loop

    if guess = word then
        exit
    end if

    locate (3, 32)
    for i : 1 .. length (word)
        put puzzle (i) : 2 ..
    end for

end loop



Thanks in advance Smile
Sponsor
Sponsor
Sponsor
sponsor
Aziz




PostPosted: Wed Jun 11, 2008 12:33 pm   Post subject: RE:Anyone know how to fix this?

Here's some steps to think about:

In your main loop:

1) First player takes turn, do everything thats in there
2) Second player takes turn, do everything the same for first person, except exchanging variables for score, name, etc where appropriate

If you've learned procedures and functions, this would be a great place to do it. If not, either learn them now (look for some tuts here), or just copy-paste.
riveryu




PostPosted: Wed Jun 11, 2008 11:03 pm   Post subject: RE:Anyone know how to fix this?

Adding to Aziz , procedures and functions can have parameters, use that to change values conviniently.
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: