• We interpreted it that there would be a need to write a funstion to generate a random number and then pick the corresponding entry from the text file and so option 3 would be "Single Player - random phrase/word" - otherwise what is the point of the data text file?
    Number 4 would be to enter the whole word phrase...
  • hey would i be able to get a copy as well please?
    id be forever in your debt lol
  • All these posts are very frustrating to look through. For those that didn't read the rules & regulations page...


    Okay, now that I spent 5 minutes making the code readable, let's look through your random phrase function...

    procedure ComputerGeneratedList;
    FileA:Textfile; //declare file variable in console.
    [b]word:string;[/b] //the word that is going to be generated.
    This is bad.
    [italic]BYTE, CHAR, INTEGER, WORD, LONGINT, STRING, POINTER[/italic], etc are all data types. Try to avoid using these for names at all costs to keep things easier to read.
    Maybe something like PHRASE, TEXTWORD, etc.

    GeneratedWords:Array [1..24] of String;//Declare an array to hold the words
    i, numbergenerated:Integer ;//to point to the position in the hold th enumber generated by the computer
    This method is acceptable, but let's say your instructor decides to add in another 24000 lines to the file right when you walk in... uh,oh!
    Another way you could do this would be to read all the lines in the file to find out how many lines there are, then pick a random number between 1 and the total # of lines in the file.
    Reset the file and read that many lines out again.

    Assuming that no lines will be added though, you could read the lines once at the program start and then you don't have to read the file everytime. Just suggestions either way.

    Randomize;//procdeure call
    *Note: Randomize is not the procedure, but it is a very good idea to call it, otherwise your program will always give the same "random" numbers.
    Look at the bold line above. This would just set it to 24, use the first line below instead. Random(24) will always return a number between 0 and 23, so if you want 1 - 24 add one to it.
    Assign(FileA,'H:COMPUTINGexamsASExamToStudentsMyPhrases.txt'); //assigns to external file.
    Reset(FileA);//reads info from the txt file line by line
    for i:=1 to 24 //pointer goes from position 1 to 24 in the array
    do begin
    If you have been told different then okay, but it is good practice to keep the DO on the same line as the FOR. This was your BEGIN & END statments will line up and make your code easier to read.
    word:=generatedwords[numbergenerated];//takes the number generated by the random fucntion uses that to look up the position in the array, finds the position and takes the word and puts it into word1.
    NewPhrase:=word;//this uses the word [ocled frp, the text file to place it in the newphrase variable this can now be used by all of the subroutines in the program.
    Why not just write
    and get rid of the WORD variable all together?

    SetUpGuessStatusArray(NewPhrase,GuessStatusArray);//call procedure that translates each character into newphrase and globalvariable UDT GuessStatusArray. This holds the characters of the string in an array so each character can be guessed many procedures use this array
    writeln(' A random word has been picked from a list, click enter to begin');

    You *could* even tell them which random # was chosen so they know if they got the same one twice.

    Now let's look at Option #3: (notice the change in layout of the code for readability)
    If Choice = 3 Then
    if PhraseHasBeenSet = True Then
    Writeln('The setter has not specified the word/phrase..');

    The only thing I'd say here is your procedure name. It makes it sound like the user already guessed correctly. I would recommend naming it GUESSPHRASE or something along those lines.

    Sorry if I seem to be picking your code apart, just take it as suggestions. All-in-all it looks good. I assume you have compiled & ran it and it works (I do not have FreePascal, so I am just looking at the code setup and may miss little errors)

  • I am doing the VB version of this exam, so we still have the same objectives, our class (4) and teacher interpreted the hints in this way:

    1. Set a maximum limit of input digits for guess word.
    2. Set a maximum amount of guesses before the guesser loses and a message box is displayed.
    3. Display letters guessed in a text box or something similar, so guesser can see what they have used.
    4. The game currently makes sure the letter's case matches so upper case words need upper case letters guessed etc.. Make this so that any case will work.
    5. The program does not currently allow the user to make complete guesses, chage this so that words/phrases can be entered.

    However I have no idea what the examiners could want us to do for the text document we will get.

    Hope this could be of help, and im also in a sticky spot like you all so could be fun when we sit this exam ;)
  • Does anyone know how to do any of the following below, would be gratelly appreciated!

    code to say you have already used a letter already

    how many wrong and correct guesses you've had

    show the number of incorrect and correct guessers the user has taken

    limit the number of incorrect guesses

    Max number of guesses
  • does anyone know how to write code for the the following: a procedure which goes through the Myphrases.txt file and counts how many phrases there are. e.g. if Myphrases.txt has 25 words/phrases in it the procedure with return the value of 25
  • [code]
    FUNCTION CountLines(filename : String) : Word;
    t : text; { or : textfile; }
    Count : Word;
    Line : String;
    Assign(t, filename); Reset(t);
    Count := 0;
    While Not(Eof(t)) Do
    ReadLn(t, Line);
    If Line <> "" Then Inc(Count);
    Close(t); { or closefile(t); }
    CountLines := Count;

    The above will load a text file and return how many lines are contained within, ignoring blank lines.
  • thanks alot!
  • could some one help me, i want to write code that when i type the letters in to set the word to be guesses as *. could someone help me with this as i've tried for hours now and i have been successful :(
  • So that the letters needing guessing display as "*" instead of "?"???

    Sorry im misunderstanding :D
  • yh so basically if am typing in a word instead of seeing the letters u see '*'. example wud be when your typing in a password u dont see the letters u type in but instead the characters you type in appear as * instead
  • Use clear screen instead
    ClrScr; but it might not worked so u need a crt library
  • Why can global variables cause bugs? any ideas on what ther going to ask in the theory part/questions about preliminary material?
  • i personally wouldn't bother. you dont want to over do it, im just getting some last minute stuff done :D

    Good luck to all for 2moz :D
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!