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

Username:   Password: 
 RegisterRegister   
 Hangman Alternating Words HELP????
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
melteaax




PostPosted: Sun Jun 07, 2015 6:13 pm   Post subject: Hangman Alternating Words HELP????

What is it you are trying to achieve?
I am writing a Hangman game program and I've gotten the program to 'replace the - with the letter guessed if it's correct' but the only word my program is allowing the user to guess is marshmallows. However, marshmallows isn't the only word in the datafile I have opened in this program. Why isn't my program alternating between the words in the datafile each time the game is being played, like it should?


What is the problem you are having?
My program isn't alternating between the words in the datafile like it should for my Hangman game.


Describe what you have tried to solve this problem
I've tried to use strings but I don't really know what to do to solve this.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:

% BELOW is my datafile

var fileNumber : int %streamnumber is used for refrencing for the computer

open : fileNumber, "hangmanWords.dat", put, seek, mod %this opens a datafile
%put - takes info from program and put into file (in this case, the file is, myFile.dat
seek : fileNumber, *

%we are going to put names into a datafile
    var sweets : string
loop
    put "Enter a sweet or dessert [exit= 1]: " ..
    get sweets : * %lets us enter names with a space inbetween
    exit when sweets = "1"
    put : fileNumber, sweets
end loop
close : fileNumber


Turing:


% BELOW is running my datafile

var fileNumber : int
open : fileNumber, "hangmanWords.dat", get % retrieve the datafile

var sweets : string
loop
    get : fileNumber, sweets : * % * tells the computer to read everything to the end of the line
    put sweets
    exit when eof (fileNumber) % eof = end of file
end loop
close : fileNumber


Turing:


% BELOW is my program

setscreen ("graphics")

var sweets : array 1..6 of string
var fileNumber : int
var vocab : string

open : fileNumber, "hangmanWords.dat", get
get : fileNumber, vocab

var display : string := ""
var guess : string := ""

locate (10, 30)
for i : 1 .. length(vocab)
    display := display + "-"
    put display (i) + "  " ..
end for

% for testing purposes only - disable before release
locate (12, 30)
for i1 : 1 .. length (vocab)
    put vocab (i1) + "  " ..
end for
%


loop
    locate (5,30)
    put "Enter a lowercase letter guess: "..
    get guess

    for i1 : 1 .. length (vocab)
        if guess = vocab (i1) then
            display := display (1 .. i1 - 1) + guess + display (i1 + 1 .. *)
    end if
    end for

    locate (10, 30)
    for i : 1 .. length (display)

        put display (i) + "  " ..
    end for
    exit when display = vocab

end loop



Please specify what version of Turing you are using
I'm not sure which version of Turing I'm using but I'm pretty sure it's not the latest one.
Sponsor
Sponsor
Sponsor
sponsor
melteaax




PostPosted: Sun Jun 07, 2015 6:14 pm   Post subject: RE:Hangman Alternating Words HELP????

I forgot to say, I'm only a beginner in Turing
Dreadnought




PostPosted: Sun Jun 07, 2015 6:35 pm   Post subject: Re: Hangman Alternating Words HELP????

I'm guessing that marshmallows is the first word in your file.

It might help to ask yourself the following:
Where do you read the words from the file?
How many words do you read?
If the game is played again, will the word picked be different?

You should at least be able to tell us why your program is doing what its doing. Afterwards we can start figuring out how to modify the behavior to suit your needs.
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: