Hangman game

Can u tell me what does this line do DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray)And tell me if my comments are correct thanks

I know that this will display the current status which means running the function but what do the words inside brackets means ?

[code]Program Hangman;

{ Skeleton Program code for the AQA COMP1 Summer 2009 examination this code should be used in conjunction with the Preliminary materials written by the AQA COMP1 Programmer Team developed in the Delphi 7 (Console Mode) programming environment (PASCAL) the DisplayMenu procedure has deliberately omitted a menu choice 3 and 4 }

Begin Repeat //repeat loop Write('Key in new phrase ...(letters and any Spaces) '); //asks the user to write new phrase Readln(ThisNewPhrase); //reads the line and puts it into the new phrase vaariable If Length(ThisNewPhrase) < 10 //If length of the variable is less than 10 then it Then Begin PhraseOK := False; // sets the boolean to false so it asks for another one Writeln('Not enough letters ... '); // Writes that there is not enough letters

{ possible further validation check(s) } End Else // if phrase is long enough BeginPhraseOK := True; //changes boolean to trueGetNewPhrase := ThisNewPhrase; //assign the new phrase to get newphrase variable End; Until PhraseOK = True; //repeats until the phrase is long enough End;

Procedure SetUpGuessStatusArray(NewPhrase : String; //Sets up quess phrase. Var GuessStatusArray : TGuessStatusArray); //display the variable var Position : Integer; //new variable that will show position of a letter Begin // FOR LOOP For Position := 1 To Length(NewPhrase) // from first letter to the last letter of the phrase Do Begin If NewPhrase[Position] = ' ' //if the new phrase position is a space Then GuessStatusArray[Position] := ' ' // then make it a space Else GuessStatusArray[Position] := '*'; // if it isnt space make it a star End; End;

Procedure DisplayCurrentStatus(PhraseLength : Byte; GuessStatusArray : TGuessStatusArray); Var Position : Integer; // variable that will show position of a letter Begin // FOR LOOP For Position := 1 To PhraseLength // from first letter to length of phrase Do Write(GuessStatusArray[Position]); //writes quessstatus array Writeln; //leave a blank line End;

Begin MissingLetter := False; // sets the missing letter to false Position := 1; //starts from 1 Repeat If GuessStatusArray[Position] <> NewPhrase[Position] //if the letter in quesstatus array equal to new phrase same position Then MissingLetter := True // It changes boolean to true Else Position := Position+1; //else it increments position Until (MissingLetter = True) or (Position = Length(NewPhrase)+1); // Does the loop until it reaches the end of phrase or it found letter

If Choice = 1 // if choice is 1 then it starts the get new phrase Then Begin NewPhrase := GetNewPhrase; // new phrase will be the outcome of function get newphrase SetUpGuessStatusArray(NewPhrase, GuessStatusArray); // start procedure PhraseHasBeenSet := True; //the phrase has been set End;

If Choice = 2 // begins quess code Then Begin If PhraseHasBeenSet = True // if there is a new phrase then it continues to work Then Begin DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);// NextGuessedLetter := GetNextLetterGuess; For Index := 1 To Length(NewPhrase) Do If NextGuessedLetter = NewPhrase[Index] Then GuessStatusArray[Index] := NextGuessedLetter; DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray); PhraseGuessed := AllLettersGuessedCorrectly(GuessStatusArray,NewPhrase); If PhraseGuessed = True Then Writeln('You have guessed correctly'); End Else Writeln('The setter has not specified the word/phrase ..'); // if there is no phrase it asks for one End;

If (Choice = 5) And (PhraseGuessed = False) Then Begin Writeln('You have not completed this word/phrase...Press return to exit'); Readln; End; Until Choice = 5;

Comments

DisplayCurrentStatus calls procedure which show hidden phrase - GuessStatusArray. Length(NewPhrase) calls function which result is length of new phrase, so procedure knows how much GuessStatusArray positions to show. However, an array of char is almost the same as a string. With string you could write a simpler version of the program.Second very annoying thing is that user have to choose from menu after each guess. I think it is better to make 'give up' option. And, in my opinion, if you use long variable names - frequent comments 'hide' program text from reader. Here is the other version of your program:

: When i load your program into turbo delphi i get these errors Cannot : resolve unit name CRT: Undeclared identifier Readkey: Undeclared identifier ClrScr: : I was looking for the way to clear screen but since ClrScr doesnt : work i am stuck again;/: i am assuming that turbo delphi is the same as Turbo pascal. the Crt needs to be changed to wincrt... below is a copy of the code for turbo pascal...

Program Hangman;

{ Skeleton Program code for the AQA COMP1 Summer 2009 examination this code should be used in conjunction with the Preliminary materials written by the AQA COMP1 Programmer Team developed in the Delphi 7 (Console Mode) programming environment (PASCAL) the DisplayMenu procedure has deliberately omitted a menu choice 3 and 4 }

A couple of others have been asking the same things.I would suggest you work together and post a list of everthing that still needs to be added to the program to make it complete, then work through the list and finish each missing section.

I noticed that a file MYPHRASES.TXT will be made available to you as well. Do you think they will require you to have an option to load a random line from this file and use it instead of having a second person enter the phrase? I would put that on the list unless you are sure they won't!

We may also need to show the letters that were guessed incorrectly.i have been trying for ages now with my classmates but we are all having no luck.im starting to get worried now 'cos my exam is on monday!!!

This took me an hour to do :Pit still lacks few things but oh well... the only thing i cant do is clear the screen since turbo delphi doesnt have clrscr command ...

[code]program secondattempt;

{ Skeleton Program code for the AQA COMP1 Summer 2009 examination this code should be used in conjunction with the Preliminary materials written by the AQA COMP1 Programmer Team developed in the Delphi 7 (Console Mode) programming environment (PASCAL) the DisplayMenu procedure has deliberately omitted a menu choice 3 and 4 }

for Index := 1 to Length(NewPhrase) do if Uppercase(NextGuessedLetter) = NewPhrase[Index] then GuessStatusArray[Index] := NextGuessedLetter; For Index := 1 to 26 do if nextguessedletter = Letters[Index] then Lettersguessedarray[Index] := Nextguessedletter;