Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Hangman game Posted by Mobix on 11 Apr 2009 at 9:07 AM
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 ?





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 }

{$APPTYPE CONSOLE}

uses
  SysUtils,
  StrUtils;

Type
  TGuessStatusArray = Array[1..20] Of Char;   //declares a new type of variable that counts letter from 1 to 20 of word
  TLettersGuessedArray = Array[1..26] Of Char;  //declares a new type of variabel that counts letter 1 to 26 of word
Var
  NewPhrase : String; //new variable string
  PhraseHasBeenSet : Boolean;  //new variable boolean
  PhraseGuessed : Boolean; //new variable boolean
  Choice : Integer;  //new variable integer
  GuessStatusArray : TGuessStatusArray; //new variable new variable type 1
  LettersGuessedArray : TLettersGuessedArray; // new variable
  NextGuessedLetter : Char;  //new variable char
  Index : Integer;   //new variable number

Procedure DisplayMenu;   // new procedure that will display the menu
  Begin
    Writeln('__________________________________');     //WTF   looks pretty
    Writeln;
    Writeln('1. SETTER - Makes new word/phrase');  // tells the option
    Writeln;
    Writeln('2. USER - Next letter guess');      //tells the options
    Writeln;
    Writeln('5. End');  //tells the options
    Writeln;
  End;




Function GetNewPhrase : String; //function for getting new phrase
  Var    //local variables
    PhraseOK : Boolean;  // creates a new boolean  to check if the phrase is ok
    ThisNewPhrase : String; //  Variable that stores new phrase

  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
          Begin
PhraseOK := True;     //changes boolean to true
GetNewPhrase := 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;

Function GetNextLetterGuess : Char;  // gets next letter quess
  Var
    Position : Integer;
    GuessedLetter : Char;  //stores quessed letter as a character

  Begin
    Writeln;  // leaves a blank line
    Write('Next guess ? ');  // asks for a next letter
    Readln(GuessedLetter); //reades the letter
    GetNextLetterGuess := GuessedLetter; // makes getnextletterquess the letter inputted
  End;


Function AllLettersGuessedCorrectly(GuessStatusArray: TGuessStatusArray;
                                    NewPhrase : String)  : Boolean;
  Var
    Position : Integer;  // counts position of a letter
    MissingLetter : Boolean; // looks if its a missing letter

  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 MissingLetter = False      // if missing letter is still false
      Then AllLettersGuessedCorrectly := True     //then all letters quessed correctly
      Else AllLettersGuessedCorrectly := False;  //if it isnt false then all letters werent quessed
  End;

{ Main program block starts here }
Begin
  PhraseHasBeenSet := False;     //starts by indicating that there is no phrase
  Repeat
    DisplayMenu;    //shows menu
    Write('Choice? '); //writes choice
    Readln(Choice); //reads into variable choice

    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;

End.
Report
Re: Hangman game Posted by ShadoWsaZ on 12 Apr 2009 at 4:38 AM
Hello,

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:

program Hangman;

{$APPTYPE CONSOLE}

uses
  Crt,
  SysUtils,
  StrUtils;

const
  MaxLength = 20; // Max length of phrase
  MinLength = 10; // Min length of phrase

type
  Phrase = string[MaxLength];

var
  NewPhrase,   // Set phrase
  HiddenPhrase: Phrase;   // Partly hidden phrase
  PhraseLength: integer;
  PhraseHasBeenSet, PhraseGuessed: boolean;
  Choice, NextGuessedLetter: char;

function GetMenuOption: char;
begin
  Writeln('_________________________________________');
  Writeln;
  Writeln('1. SETTER - Makes new word/phrase');
  Writeln;
  Writeln('2. USER - word/phrase guess (give up - ?)');
  Writeln;
  Writeln('3. End');
  Writeln;
  GetMenuOption := ReadKey
end;

function GetNewPhrase: Phrase;
{ Get phrase from setter }
  var PhraseOK: boolean;
      ThisNewPhrase: Phrase;
begin
  repeat
    write('Key in new phrase ... (letters and any spaces) ');
    Readln(ThisNewPhrase);
    PhraseOK := Length(ThisNewPhrase) >= MinLength;
    if not PhraseOK then Writeln('Not enough letters')
  until PhraseOK;
  GetNewPhrase := ThisNewPhrase
end;

procedure SetUpGuessStatus(NewPhrase: Phrase; PhraseLength: integer;
                           var HiddenPhrase: Phrase);
{  To create hidden phrase }
  var i: integer;
begin
  HiddenPhrase := '';
  for i := 1 to PhraseLength do
    if NewPhrase[i] = ' '
      then HiddenPhrase := HiddenPhrase + ' '
      else HiddenPhrase := HiddenPhrase + '*'
end;

procedure RevealLetter(NextGuessedLetter: char; var HiddenPhrase: Phrase;
                       NewPhrase: Phrase; PhraseLength: integer);
  var i: integer;
begin
  for i := 1 to PhraseLength do
    if UpCase(NewPhrase[i]) = Upcase(NextGuessedLetter) then // C = c
      HiddenPhrase[i] := NewPhrase[i]
end;

function GetNextLetterGuess: char;
begin
  Writeln;
  write('Next guess? '); Readln(GetNextLetterGuess)
end;

begin
  PhraseHasBeenSet := false;
  repeat
    Choice := GetMenuOption;   // Takes choice from menu
    case Choice of
      '1': begin
             NewPhrase := GetNewPhrase; // Takes phrase from function
             PhraseLength := Length(NewPhrase);
             SetUpGuessStatus(NewPhrase, PhraseLength, HiddenPhrase);
             PhraseHasBeenSet := true;
             ClrScr // Clears screen
           end;
      '2': if PhraseHasBeenSet then
             begin
               Writeln(HiddenPhrase);
               NextGuessedLetter := GetNextLetterGuess; // Takes from function
               PhraseGuessed := false;
               While (NextGuessedLetter <> '?') and not PhraseGuessed do
                 begin
                   RevealLetter(NextGuessedLetter, HiddenPhrase,
                                NewPhrase, PhraseLength);
                   Writeln(HiddenPhrase);
                   PhraseGuessed := HiddenPhrase = NewPhrase;
                   if not PhraseGuessed then
                     NextGuessedLetter := GetNextLetterGuess
                 end;
               If PhraseGuessed
                 then Writeln('Congratulations! You have guessed')
                 else Writeln('Maybe you will be luckier other time :)');
               { to hide for next user }
               SetUpGuessStatus(NewPhrase, PhraseLength, HiddenPhrase)
             end
           else Writeln('The phrase has not been set')
    end
  until Choice = '3'
end.

Report
This post has been deleted. Posted by lcgyy on 12 Apr 2009 at 7:45 PM
This post has been deleted.
Report
Re: Hangman game Posted by Mobix on 15 Apr 2009 at 7:47 AM
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;/
Report
Re: Hangman game Posted by eatgrub on 27 Apr 2009 at 3:54 AM
: 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 }

Uses
Wincrt;

Type
TGuessStatusArray = Array[1..20] Of Char;
TLettersGuessedArray = Array[1..26] Of Char;
Var
NewPhrase : String;
PhraseHasBeenSet : Boolean;
PhraseGuessed : Boolean;
Choice : Integer;
GuessStatusArray : TGuessStatusArray;
LettersGuessedArray : TLettersGuessedArray;
NextGuessedLetter : Char;
Index : Integer;

Procedure DisplayMenu;
Begin
Writeln('__________________________________');
Writeln;
Writeln('1. SETTER - Makes new word/phrase');
Writeln;
Writeln('2. USER - Next letter guess');
Writeln;
Writeln('5. End');
Writeln;
End;




Function GetNewPhrase : String;
Var
PhraseOK : Boolean;
ThisNewPhrase : String;

Begin
Repeat
Write('Key in new phrase ...(letters and any Spaces) ');
Readln(ThisNewPhrase);
If Length(ThisNewPhrase) < 10
Then
Begin
PhraseOK := False;
Writeln('Not enough letters ... ');
{ possible further validation check(s) }
End
Else
Begin
PhraseOK := True;
GetNewPhrase := ThisNewPhrase;
End;
Until PhraseOK = True;
End;


Procedure SetUpGuessStatusArray(NewPhrase : String;
Var GuessStatusArray : TGuessStatusArray);
Var
Position : Integer;
Begin
For Position := 1 To Length(NewPhrase)
Do
Begin
If NewPhrase[Position] = ' '
Then GuessStatusArray[Position] := ' '
Else GuessStatusArray[Position] := '*';
End;
End;

Procedure DisplayCurrentStatus(PhraseLength : Byte;
GuessStatusArray : TGuessStatusArray);
Var
Position : Integer;
Begin
For Position := 1 To PhraseLength
Do Write(GuessStatusArray[Position]);
Writeln;
End;

Function GetNextLetterGuess : Char;
Var
Position : Integer;
GuessedLetter : Char;

Begin
Writeln;
Write('Next guess ? ');
Readln(GuessedLetter);
GetNextLetterGuess := GuessedLetter;
End;


Function AllLettersGuessedCorrectly(GuessStatusArray: TGuessStatusArray;
NewPhrase : String) : Boolean;
Var
Position : Integer;
MissingLetter : Boolean;

Begin
MissingLetter := False;
Position := 1;
Repeat
If GuessStatusArray[Position] <> NewPhrase[Position]
Then MissingLetter := True
Else Position := Position+1;
Until (MissingLetter = True) or (Position = Length(NewPhrase)+1);

If MissingLetter = False
Then AllLettersGuessedCorrectly := True
Else AllLettersGuessedCorrectly := False;
End;

{ Main program block starts here }
Begin
PhraseHasBeenSet := False;
Repeat
DisplayMenu;
Write('Choice? ');
Readln(Choice);

If Choice = 1
Then
Begin
NewPhrase := GetNewPhrase;
SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
PhraseHasBeenSet := True;
End;

If Choice = 2
Then
Begin
If PhraseHasBeenSet = True
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 ..');
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;

End.




anyone got ideas of what they may ask us?

cheers matt
Report
Re: Hangman game Posted by Phat Nat on 28 Apr 2009 at 12:31 AM
: anyone got ideas of what they may ask us?

Check the thread below this one (http://www.programmersheaven.com/mb/pasprog/389822/389822/need-help-urgently-plz/?S=B20000#389822)

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!
Report
Re: Hangman game Posted by franklinferdi on 3 May 2009 at 8:34 AM
NO No No.. they would certainly as us to load a random line from the file.. But any one know how to do it!?
Report
Re: Hangman game Posted by mayonayz on 6 May 2009 at 9:00 AM
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!!!
Report
Re: Hangman game Posted by franklinferdi on 6 May 2009 at 9:09 AM
Hi Mate.. Same here.. I am really getting nervous.. I am working on it.. I think surely I will get a solution by tomoz evening..!! Be Confident!! We can do it!!!
Report
Re: Hangman game Posted by Mobix on 6 May 2009 at 9:30 AM
This took me an hour to do :P
it still lacks few things but oh well...
the only thing i cant do is clear the screen since turbo delphi doesnt have clrscr command ...

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 }

{$APPTYPE CONSOLE}

uses
  SysUtils;

Const
myphrases = 'phrases.txt';

type
  TGuessStatusArray    = array[1..20] of char;
  TLettersGuessedArray = array[1..26] of char;

var
  NewPhrase           : string;
  PhraseHasBeenSet    : Boolean;
  PhraseGuessed       : Boolean;
  Choice              : integer;
  GuessStatusArray    : TGuessStatusArray;
  LettersGuessedArray : TLettersGuessedArray;
  NextGuessedLetter   : char;
  Index               : integer;
  Phraseguesse       : string;
  phrases            : Textfile;
  a_phrases          : array[0..99] of string;
  Letters            : String;
  GuessesLeft        : Integer;


procedure DisplayMenu;
begin
  Writeln('__________________________________');
  Writeln;
  Writeln('1. SETTER - Makes new word/phrase');
  Writeln;
  Writeln('2. USER - Next letter guess');
  Writeln;
  Writeln('3. User - Whole phrase guess');
  Writeln;
  Writeln('4. User - Set a random phras');
  Writeln;
  Writeln('5. End');
  Writeln;
end;

function GetNewPhrase : string;
var
  PhraseOK      : Boolean;
  ThisNewPhrase : string;
begin
  repeat
    Write('Key in new phrase ...(letters and any Spaces) ');
    Readln(ThisNewPhrase);

    if Length(ThisNewPhrase) < 10 then
    begin
      PhraseOK := False;
      Writeln('Not enough letters ... ');
      { possible further validation check(s) }
    end else
    if length(thisnewphrase) > 20 then
    begin
    PhraseOK := False;
      Writeln('Too many letters ... ');
    end else

    begin
      PhraseOK     := True;
      GetNewPhrase := Uppercase(ThisNewPhrase);
      Letters := 'abcdefghijklmnopqrstuvwxyz';
      Guessesleft := 10;
    end;
  until PhraseOK = True;
end;

function GetRandomPhrase : string;
var
  PhraseOK      : Boolean;
  ThisNewPhrase : string;
  i_phrases     : integer;
begin
AssignFile(phrases, myphrases);
Reset(phrases);


i_phrases := 0;
While not EOF(phrases)do
  begin
    Readln(phrases, a_phrases[i_phrases]);
    inc(i_phrases);
  end;

 Closefile(phrases);
Repeat
 Randomize();

 Thisnewphrase := a_phrases[Random(i_phrases-1)];
   if Length(ThisNewPhrase) < 10 then
    begin
      PhraseOK := False;
      Writeln('Random phrase has not enough letters try again ... ');
      { possible further validation check(s) }
    end else
    if length(thisnewphrase) > 20 then
    begin
    PhraseOK := False;
      Writeln('Random phrase has got too many letters ... ');
    end else
    begin
      PhraseOK     := True;
      GetrandomPhrase := Uppercase(ThisNewPhrase);
      Letters := 'abcdefghijklmnopqrstuvwxyz';
      Guessesleft := 10;
    end;
  until PhraseOK = True;
end;

procedure SetUpGuessStatusArray(NewPhrase : string; var GuessStatusArray : TGuessStatusArray);
var
  Position : integer;
begin
  for Position := 1 to Length(NewPhrase) do
    begin
    if NewPhrase[Position] = ' ' then
      GuessStatusArray[Position] := ' '
    else
      GuessStatusArray[Position] := '*';
     end;
  for position  := 1 to 26 do
  Lettersguessedarray[Position] := '*';
end;

procedure DisplayCurrentStatus(PhraseLength : byte; GuessStatusArray : TGuessStatusArray);
var
  Position : integer;
begin
  for Position := 1 to PhraseLength do

    Write(GuessStatusArray[Position]);

  Writeln;
  Writeln;
  Writeln('Letters used so far');

  for Position := 1 to 26 do
    Write(Lettersguessedarray[Position]);
    writeln;
    Writeln('Guesses left ', Guessesleft);
end;

function GetNextLetterGuess : char;
var
  Position      : integer;
  GuessedLetter : char;
  b_letter      : Boolean;

begin

Repeat
  Begin
  B_letter := True;
  Writeln;
  Write('Next guess ? ');
  Readln(GuessedLetter);
    For Position := 0 to Length(Letters) do
      if GuessedLetter = Lettersguessedarray[Position] then
       begin
         Writeln('You have already used this letter ');
         Writeln;
         b_letter := False;
       end;
  end;
Until B_letter = True ;
GetNextLetterGuess := GuessedLetter;
GuessesLeft := Guessesleft-1;
end;

function GetWholephrase : string;
var
  Guessedphrase : string;
begin
  Writeln;
  Write('Next guess ? ');
  Readln(guessedphrase);
  Getwholephrase := guessedphrase;
  Guessesleft := guessesleft-1;
end;

function AllLettersGuessedCorrectly(GuessStatusArray: TGuessStatusArray; NewPhrase : string)  : Boolean;
var
  Position      : integer;
  MissingLetter : Boolean;
begin
  MissingLetter := False;
  Position      := 1;

  repeat
    if GuessStatusArray[Position] <> NewPhrase[Position] then
      MissingLetter := True
    else
      Position := Position+1;
  until (MissingLetter = True) or (Position = Length(NewPhrase)+1);

  if MissingLetter = False then
    AllLettersGuessedCorrectly := True
  else
    AllLettersGuessedCorrectly := False;
end;

{ Main program block starts here }
begin
  PhraseHasBeenSet := False;

  repeat
    DisplayMenu;
    Write('Choice? ');
    Readln(Choice);

    if Choice = 1 then
    begin
      NewPhrase := GetNewPhrase;
      SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
      PhraseHasBeenSet := True;
    end;

    if Choice = 2 then
    Begin
      if PhraseHasBeenSet = True then
      begin
        DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
        NextGuessedLetter := GetNextLetterGuess;

        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;

            
          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 ..');
    end;

    if choice = 3 then
       Begin
      if PhraseHasBeenSet = True then
      begin
        DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
        Phraseguesse := Getwholephrase;

          if Uppercase(Phraseguesse) = Uppercase(NewPhrase) then
            for index := 1 to Length(newphrase) do

            GuessStatusArray[Index] := Newphrase[Index];

          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 ..');
    end;

    if choice = 4 then
    begin
      NewPhrase := GetRandomphrase;
      SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
      PhraseHasBeenSet := True;
    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;
end.

Report
Re: Hangman game Posted by j_808 on 6 May 2009 at 10:42 AM
Do any of you've know how to limit the guesses on the hangman game, a bit scared as well because the exam is just monday now
Report
Re: Hangman game Posted by franklinferdi on 6 May 2009 at 10:46 AM
No idea mate.. still working on it..
Do you know how to display all the guessed words!!!???
Report
Re: Hangman game Posted by j_808 on 6 May 2009 at 10:50 AM
yh but its in visual basic
Report
Re: Hangman game Posted by j_808 on 6 May 2009 at 10:52 AM

SetUpUsedLetterArray1(NextGuessedLetter, LettersGuessedArray1)
Console.WriteLine("You have used these letters")
DisplayUsedLetterStatus1(LettersGuessedArray1)
Console.WriteLine()

' select case for the alphabet

Sub SetUpUsedLetterArray1(ByVal NextGuessedLetter As Char, ByVal LettersGuessedArray1() As Char)

Dim position As Integer

Select Case NextGuessedLetter
Case "A" : position = 1
Case "B" : position = 2
Case "C" : position = 3
Case "D" : position = 4
Case "E" : position = 5
Case "F" : position = 6
Case "G" : position = 7
Case "H" : position = 8
Case "I" : position = 9
Case "J" : position = 10
Case "K" : position = 11
Case "L" : position = 12
Case "M" : position = 13
Case "N" : position = 14
Case "O" : position = 15
Case "P" : position = 16
Case "Q" : position = 17
Case "R" : position = 18
Case "S" : position = 19
Case "T" : position = 20
Case "U" : position = 21
Case "V" : position = 22
Case "W" : position = 23
Case "X" : position = 24
Case "Y" : position = 25
Case "Z" : position = 26

End Select
LettersGuessedArray1(position) = NextGuessedLetter 'puts NextGuessed Letter into the array position

End Sub

'shows the letters used from the previous array

Sub DisplayUsedLetterStatus1(ByVal LettersGuessedArray1() As Char)
Dim position As Integer = 1
Dim UsedLetter As String

For position = 1 To 26
UsedLetter = LettersGuessedArray1(position)
Console.Write(UsedLetter)
Next
End Sub
Report
Re: Hangman game Posted by j_808 on 6 May 2009 at 10:55 AM
if there's any problems jsut ask, becuase ive tried and it does work. does anyone know any more possible questions they might ask in the exam
Report
Re: Hangman game Posted by franklinferdi on 6 May 2009 at 11:05 AM
Hey.. thank you very much mate.. I got the basic concept.. I ll try and get my head round thru it..

DO u mind if I ask u another doubt.. for the past 8 hrs.. Ive been trying to display all the guesses made by the user.. do u know how to do it..
Good luck with ur exams anyway!! :) Once again thankyou!!
Report
Re: Hangman game Posted by Mobix on 6 May 2009 at 11:06 AM
Use code tags when you insert code ......
This is a Pascal forum not visual basic.
Report
Re: Hangman game Posted by j_808 on 6 May 2009 at 11:11 AM

SetUpUsedLetterArray2(NextGuessedLetter, LettersGuessedArray2)
Console.WriteLine("You have used these letters")
DisplayUsedLetterStatus2(LettersGuessedArray2)
Console.WriteLine()


'sets up the SECOND method used letter array and inputs each guessed letter

Sub SetUpUsedLetterArray2(ByVal NextGuessedLetter As String, ByVal LettersGuessedArray2() As Char)
Static position As Integer

LettersGuessedArray2(position) = NextGuessedLetter
position = position + 1

End Sub

'shows the letters used from previous array (SECOND method)

Sub DisplayUsedLetterStatus2(ByVal LettersGuessedArray2() As Char)
Dim position As Integer = 1
Dim UsedLetter As String

For position = 1 To 26
UsedLetter = LettersGuessedArray2(position)
Console.Write(UsedLetter)
Next
End Sub











sorry am new to programming forum, wt do u mean by adding code tags?
Report
Re: Hangman game Posted by Mobix on 6 May 2009 at 11:15 AM
Firstly, visual basic forum is here but i dont think that they have got a topic for this exam.
Secondly, Code tags are on the tool bar above the text box when you are posting a new message/post, its next to colour.

Report
Re: Hangman game Posted by j_808 on 6 May 2009 at 11:23 AM
Oh ok sorry about that....
Report
Re: Hangman game Posted by franklinferdi on 6 May 2009 at 11:25 AM
hey Thanks for the code mate!!
Report
Re: Hangman game Posted by franklinferdi on 7 May 2009 at 9:44 AM
Hi mate .. sorry to disturb you. but the code u gave me didn't work.. it only displays z... when i didn't even enter a z.. and it only shows that single alphabet.. But I want to display every guess the user has entered! CAn anyone help?! I need the code for pascal.. and does anyone know how to limit the number of incorrect guesses?!
Report
Re: Hangman game Posted by Mobix on 7 May 2009 at 9:49 AM
Can Anyone tell me if this is OK? This is the complete version i added everything i could think of:P. The only thing that annoys me is the fact that it doesnt update wrong guesses at first but id have to make a new procedure for it.
Program hangman7;

{ 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 }

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  TGuessStatusArray    = array[1..20] of char;
  TLettersGuessedArray = array[1..26] of char;



  var
  NewPhrase           : string;
  PhraseHasBeenSet    : Boolean;
  PhraseGuessed       : Boolean;
  Choice              : integer;
  GuessStatusArray    : TGuessStatusArray;
  LettersGuessedArray : TLettersGuessedArray;
  NextGuessedLetter   : char;
  Index               : integer;
  Wholephrase         : string;
  Guesses             : Integer;
  Badguesses          : Integer;
  Letters             : String;
  b_guess             : Boolean;

procedure DisplayMenu;
Begin
  Writeln('__________________________________');
  Writeln;
  Writeln('1. SETTER - Makes new word/phrase');
  Writeln;
  Writeln('2. USER - Next letter guess');
  Writeln;
  Writeln('3. USER - Whole phrase guess');
  Writeln;
  Writeln('4. USER - Set a new random phrase');
  Writeln;
  Writeln('5. End');
  Writeln;
End;

function GetNewPhrase : string;
var
  PhraseOK      : Boolean;
  ThisNewPhrase : string;
begin
  repeat
    Write('Key in new phrase ...(letters and any Spaces) ');
    Readln(ThisNewPhrase);

    If Length(ThisNewPhrase) < 10 Then
    begin
      PhraseOK := False;
      Writeln('Not enough letters ... ');
      { possible further validation check(s) }
    end Else
    if length(thisnewphrase) > 20 then
    begin
    PhraseOK := False;
    Writeln('Too many letters ... ');
    end else

    begin
      PhraseOK     := True;
      GetNewPhrase := uppercase(ThisNewPhrase);
      Letters      := 'abcdefghijklmnopqrstuvwxyz';
      Guesses      := 0;
      Badguesses   := 0;
    end;
  until PhraseOK = True;
end;

Function getrandomphrase : string;
Const
myphrases = 'myphrases.txt';
var
  PhraseOK      : Boolean;
  ThisNewPhrase : string;
  a_phrases     : array[0..99] of string;
  i_phrases     : Integer;
  phrases       : Textfile;

begin
Assign(phrases, myphrases);
Reset(phrases);
i_phrases := 0;
 While not EOF(phrases) do
  begin
    Readln(phrases, a_phrases[i_phrases]);
    inc(i_phrases);
  end;
Closefile(phrases);

  repeat
Randomize();
Thisnewphrase := a_phrases[Random(i_phrases)];

    If Length(ThisNewPhrase) < 10 Then
    begin
      PhraseOK := False;
      Writeln('Not enough letters ... ');
      { possible further validation check(s) }
    end Else
    if length(thisnewphrase) > 20 then
    begin
    PhraseOK := False;
    Writeln('Too many letters ... ');
    end else

    begin
      PhraseOK     := True;
      getrandomphrase := Uppercase(ThisNewPhrase);
      Letters      := 'abcdefghijklmnopqrstuvwxyz';
      Guesses      := 0;
      Badguesses   := 0;
    end;
  until PhraseOK = True;
end;


procedure SetUpGuessStatusArray(NewPhrase : string; var GuessStatusArray : TGuessStatusArray);
var
  Position : integer;
begin
  for Position := 1 to Length(NewPhrase) do
  begin
    if NewPhrase[Position] = ' ' then
      GuessStatusArray[Position] := ' '
    else
      GuessStatusArray[Position] := '*';
  end;
  For position := 1 to length(letters) do
  begin
     Lettersguessedarray[position]  := '*';
  end;
end;

procedure DisplayCurrentStatus(PhraseLength : byte; GuessStatusArray : TGuessStatusArray);
var
  Position : integer;
begin
  for Position := 1 to PhraseLength do
    Write(GuessStatusArray[Position]);

  Writeln;
  Writeln;
  Writeln('Letters used so far');
  For position := 1 to length(letters) do
   begin
     Write(Lettersguessedarray[Position]);
   end;
   Writeln;
   Writeln('Number of guesses so far :- ',guesses, ' Number of bad guesses left :- ', badguesses);
   Writeln('Bad guesses remaining :- ', 10-Badguesses)
end;

function GetNextLetterGuess : char;
var
  Position      : integer;
  GuessedLetter : char;
  letterok      : Boolean;
begin
Repeat
  Writeln;
  Write('Next guess ? ');
  Letterok := True;
  Readln(GuessedLetter);
    For Position := 0 to length(letters) do
    begin
       if Guessedletter = LettersguessedArray[Position] then
       begin
         Writeln('You have tried this letter already');
         letterok := False;
       end;

    end;

  GetNextLetterGuess := GuessedLetter;
  inc(Guesses);

Until letterok = True;
end;


function  GetWholephrase  : string;
var
  Guessedphrase : string;
begin
  Writeln;
  Write('Next guess ? ');
  Readln(Guessedphrase);
  Getwholephrase := Uppercase(Guessedphrase);
  inc(guesses);
end;

function AllLettersGuessedCorrectly(GuessStatusArray: TGuessStatusArray; NewPhrase : string)  : Boolean;
var
  Position      : integer;
  MissingLetter : Boolean;
begin
  MissingLetter := False;
  Position      := 1;

  repeat
    if GuessStatusArray[Position] <> NewPhrase[Position] then
      MissingLetter := True
    else
      Position := Position+1;
  until (MissingLetter = True) or (Position = Length(NewPhrase)+1);

  if MissingLetter = False then
    AllLettersGuessedCorrectly := True
  else
    AllLettersGuessedCorrectly := False;
end;

{ Main program block starts here }
begin
  PhraseHasBeenSet := False;

  Repeat
    DisplayMenu;
    Write('Choice? ');
    Readln(Choice);

    if Choice = 1 then
    begin
      NewPhrase := GetNewPhrase;
      SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
      PhraseHasBeenSet := True;
    end;

    if Choice = 2 then
    Begin
      if PhraseHasBeenSet = True then
      begin
        DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
        NextGuessedLetter := GetNextLetterGuess;
        b_guess := False;
        for Index := 1 to Length(NewPhrase) do
          if Uppercase(NextGuessedLetter) = NewPhrase[Index] then
            begin
            GuessStatusArray[Index] := NextGuessedLetter;
            b_guess := True;
            end;
           For Index := 1 to Length(letters) do
             if Nextguessedletter = letters[Index] then
              begin
              Lettersguessedarray[Index] := NextguessedLetter;
              end;

          DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
          PhraseGuessed := AllLettersGuessedCorrectly(GuessStatusArray,NewPhrase);
          if b_guess = False then
           begin
             inc(badguesses);
            if badguesses > 10 then
              begin
              writeln('You have ran out of guesses');
              Phrasehasbeenset:= False;
              end;
           end;

          if PhraseGuessed = True then
            Writeln('You have guessed correctly');
      end else
        Writeln('The setter has not specified the word/phrase ..');
    end;

    if Choice = 3 then
    Begin
      if PhraseHasBeenSet = True then
      begin
        DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
        Wholephrase := Getwholephrase;

          if Wholephrase = NewPhrase then
          begin
             For  Index := 0 to length(Newphrase) do
              begin
               GuessStatusArray[Index] := Newphrase[Index];
              end;

          DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
          PhraseGuessed := True;
          Writeln('You have guessed correctly');
          Phrasehasbeenset := False;
          end else
          begin
            inc(badguesses);
            if badguesses > 10 then
            writeln('You have ran out of guesses');
            Phrasehasbeenset:= False;
            
          end;

      end else
        Writeln('The setter has not specified the word/phrase ..');
      end;

    if Choice = 4 then
    begin
      NewPhrase := Getrandomphrase;
      SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
      PhraseHasBeenSet := True;
    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;
end.

Report
Re: Hangman game Posted by Inculcate48 on 7 May 2009 at 12:28 PM
Hi can someone plzz helpme..................I know this is a pascal forum but.....

Im using VB6 and just wondering how to GUESS the whole word, also how do i limit the number of Guesses that i have ..
Report
Re: Hangman game Posted by Phat Nat on 7 May 2009 at 11:57 PM
A few things.

First off, you missed a section. The game is supposed to allow ONLY letters. Currently I can enter digits, apostrophes, etc.

When all characters have been guessed, the user is not told. You must enter the phrase in for it to say correct guess! After entering the last letter, it should say complete and no longer let you guess more letters.

If you accidentally type in a letter at the menu, it creates an error.
Don't set Choice as an INTEGER, set it as a CHAR and then use CHOICE:=READKEY();
This way you will not have to press enter after and you won't crash your program.

If you try to guess the phrase and fail, it un-sets the phrase. You need a BEGIN..END statement:
end else
begin
  inc(badguesses);
  if badguesses > 10 then
  begin
     lineDisplay := 'You have ran out of guesses';
     Phrasehasbeenset:= False;
  end;
end;


***** BELOW IS NOT ABOUT ERRORS, BUT HOW TO MAKE YOUR UI BETTER *****

Also, the layout is confusing. I just did some research and found Delphi does not support CLRSCR() or GOTOXY(), but use this code at the top of your program:
//-----------------------------------------
// Position cursor to X, Y
//-----------------------------------------
procedure GotoXY(X, Y : Word);
begin
Coord.X := X; Coord.Y := Y;
SetConsoleCursorPosition(ConHandle, Coord);
end;
//-----------------------------------------
// Clear Screen - fill it with spaces
//-----------------------------------------
procedure ClrScr;
begin
Coord.X := 0; Coord.Y := 0;
FillConsoleOutputCharacter(ConHandle, ' ', MaxX*MaxY, Coord, NOAW);
GotoXY(0, 0);
end;


and then you can do a little more visual formatting.

Here's an example that doesn't require many changes and makes the program alot smoother to use.
First, in your main procedure at the start of your loop, change the first few lines to :
{ Main program block starts here }
begin
  PhraseHasBeenSet := False;

  Repeat
    clrscr;
    DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
    DisplayMenu;
    GotoXY(1,23); WriteLn(lineDisplay);
    GotoXY(1,22); Write('Choice? ');
    Readln(Choice);
    lineDisplay := '';

Add the lineDisplay variable to your global variables as a STRING. Since we clear the screen everytime, we need a way to write the error information to the screen.
So change the following lines from WriteLn() to:
lineDisplay := 'You have ran out of guesses';
lineDisplay := 'You have guessed correctly';
lineDisplay := 'The setter has not specified the word/phrase ..';


Your display menu needs a start point:
procedure DisplayMenu;
Begin
  GotoXY(1,10);
  Writeln('__________________________________');
  Writeln;
  Writeln('1. SETTER - Makes new word/phrase');


and so does your DisplayCurrentStatus:
procedure DisplayCurrentStatus(PhraseLength : byte; GuessStatusArray : TGuessStatusArray);
var
  Position : integer;
begin
  GotoXY(1,1); WriteLn('Phrase:');
  for Position := 1 to PhraseLength do
    Write(GuessStatusArray[Position]);

  Writeln; Writeln;
  Writeln('Letters used so far:');
  For position := 1 to length(letters) do
   begin
     Write(Lettersguessedarray[Position]);
   end;
   Writeln;WriteLn;
   Writeln('Number of guesses so far :- ',guesses, ' Number of bad guesses :- ', badguesses);
   Writeln('Bad guesses remaining :- ', 10-Badguesses)
end;


This will always display your coded phrase at the top of the screen as well as the letters guessed, right & wrong guesses and the number of guesses left. You can now remove all other calls to DisplayCurrentStatus() in the rest of your code.

The last suggestion I would make is to change the letters already guessed from '*' to something that makes the letters easier to see, such as '.'
In your SetUpGuessStatusArray() procedure:
  For position := 1 to length(letters) do
  begin
     Lettersguessedarray[position]  := '.';
  end;



Well, my wife is calling me to bed now, so I hope this helps you out a bit more ;)
Report
Re: Hangman game Posted by Mobix on 8 May 2009 at 6:23 AM
Its OK i like constructive criticism :D.
However you should know that i will have just 55 minutes to write this and that i have only been using pascal for 8 months so its a challenge they probably wont ask me to do half of the that i have just done.
To fix the menu i did
  Try
 begin
    Write('Choice? ');
    Readln(Choice);
     end;
 Except
  On EinOutError do writeln('you can only enter numbers from 1 to 5');

For accepting only letters ill use a while loop checking if character is a space or ascii character in between 65 and 90. I added Uppercase to
repeat
    if Uppercase(GuessStatusArray[Position]) <> NewPhrase[Position] then
      MissingLetter := True
    else

So now it tells the user.
Report
HELP WITH PASCAL HANGMAN PLEASE Posted by eGames on 8 May 2009 at 12:16 PM
Hey all , below is my aqa hangman 2009 code in pascal, the program works however I would like it do do 1 more thing: Display letters which have been guessed.
PLEASE NOTE: If attempting to help me, please do not reply with part codes but with my code with your code included (copy, paste) as I often make stupid mistakes when copying.

Maybe someone has a better code or can help me. If so please reply and first good responce will get awarded.

The code is:

program project1;

{ 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 }

{$APPTYPE CONSOLE}

uses
SysUtils;

Const
myphrases = 'MyPhrases.txt';

type
TGuessStatusArray = array[1..20] of char;
TLettersGuessedArray = array[1..26] of char;

var
NewPhrase : string;
PhraseHasBeenSet : Boolean;
PhraseGuessed : Boolean;
Choice : integer;
GuessStatusArray : TGuessStatusArray;
LettersGuessedArray : TLettersGuessedArray;
NextGuessedLetter : char;
Index : integer;
Phraseguesse : string;
phrases : Textfile;
a_phrases : array[0..99] of string;
Letters : String;
GuessesLeft : Integer;


procedure DisplayMenu;
begin
Writeln('__________________________________');
Writeln;
Writeln('1. SETTER - Makes new word/phrase');
Writeln;
Writeln('2. USER - Next letter guess');
Writeln;
Writeln('3. User - Whole phrase guess');
Writeln;
Writeln('4. User - Set a random phras');
Writeln;
Writeln('5. End');
Writeln;
end;

function GetNewPhrase : string;
var
PhraseOK : Boolean;
ThisNewPhrase : string;
begin
repeat
Write('Key in new phrase ...(letters and any Spaces) ');
Readln(ThisNewPhrase);

if Length(ThisNewPhrase) < 10 then
begin
PhraseOK := False;
Writeln('Not enough letters ... ');
{ possible further validation check(s) }
end else
if length(thisnewphrase) > 20 then
begin
PhraseOK := False;
Writeln('Too many letters ... ');
end else

begin
PhraseOK := True;
GetNewPhrase := Uppercase(ThisNewPhrase);
Letters := 'abcdefghijklmnopqrstuvwxyz';
Guessesleft := 10;
end;
until PhraseOK = True;
end;

function GetRandomPhrase : string;
var
PhraseOK : Boolean;
ThisNewPhrase : string;
i_phrases : integer;
begin
AssignFile(phrases, myphrases);
Reset(phrases);


i_phrases := 0;
While not EOF(phrases)do
begin
Readln(phrases, a_phrases[i_phrases]);
inc(i_phrases);
end;

Closefile(phrases);
Repeat
Randomize();

Thisnewphrase := a_phrases[Random(i_phrases-1)];
if Length(ThisNewPhrase) < 10 then
begin
PhraseOK := False;
Writeln('Random phrase has not enough letters try again ... ');
{ possible further validation check(s) }
end else
if length(thisnewphrase) > 20 then
begin
PhraseOK := False;
Writeln('Random phrase has got too many letters ... ');
end else
begin
PhraseOK := True;
GetrandomPhrase := Uppercase(ThisNewPhrase);
Letters := 'abcdefghijklmnopqrstuvwxyz';
Guessesleft := 10;
end;
until PhraseOK = True;
end;

procedure SetUpGuessStatusArray(NewPhrase : string; var GuessStatusArray : TGuessStatusArray);
var
Position : integer;
begin
for Position := 1 to Length(NewPhrase) do
begin
if NewPhrase[Position] = ' ' then
GuessStatusArray[Position] := ' '
else
GuessStatusArray[Position] := '*';
end;
end;

procedure DisplayCurrentStatus(PhraseLength : byte; GuessStatusArray : TGuessStatusArray);
var
Position : integer;
begin
for Position := 1 to PhraseLength do

Write(GuessStatusArray[Position]);

Writeln;
writeln;
Writeln('Guesses left ', Guessesleft);
end;

function GetNextLetterGuess : char;
var
Position : integer;
GuessedLetter : char;
b_letter : Boolean;

begin

Repeat
Begin
B_letter := True;
Writeln;
Write('Next guess ? ');
Readln(GuessedLetter);
For Position := 0 to Length(Letters) do
if GuessedLetter = Lettersguessedarray[Position] then
begin
Writeln('You have already used this letter ');
Writeln;
b_letter := False;
end;
end;
Until B_letter = True ;
GetNextLetterGuess := GuessedLetter;
GuessesLeft := Guessesleft-1;
end;

function GetWholephrase : string;
var
Guessedphrase : string;
begin
Writeln;
Write('Next guess ? ');
Readln(guessedphrase);
Getwholephrase := guessedphrase;
Guessesleft := guessesleft-1;
end;

function AllLettersGuessedCorrectly(GuessStatusArray: TGuessStatusArray; NewPhrase : string) : Boolean;
var
Position : integer;
MissingLetter : Boolean;
begin
MissingLetter := False;
Position := 1;

repeat
if GuessStatusArray[Position] <> NewPhrase[Position] then
MissingLetter := True
else
Position := Position+1;
until (MissingLetter = True) or (Position = Length(NewPhrase)+1);

if MissingLetter = False then
AllLettersGuessedCorrectly := True
else
AllLettersGuessedCorrectly := False;
end;

{ Main program block starts here }
begin
PhraseHasBeenSet := False;

repeat
DisplayMenu;
Write('Choice? ');
Readln(Choice);

if Choice = 1 then
begin
NewPhrase := GetNewPhrase;
SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
PhraseHasBeenSet := True;
end;

if Choice = 2 then
Begin
if PhraseHasBeenSet = True then
begin
DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
NextGuessedLetter := GetNextLetterGuess;

for Index := 1 to Length(NewPhrase) do
if Uppercase(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 ..');
end;

if choice = 3 then
Begin
if PhraseHasBeenSet = True then
begin
DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
Phraseguesse := Getwholephrase;

if Uppercase(Phraseguesse) = Uppercase(NewPhrase) then
for index := 1 to Length(newphrase) do

GuessStatusArray[Index] := Newphrase[Index];

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 ..');
end;

if choice = 4 then
begin
NewPhrase := GetRandomphrase;
SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
PhraseHasBeenSet := True;
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;
END.
Report
Re: HELP WITH PASCAL HANGMAN PLEASE Posted by franklinferdi on 9 May 2009 at 1:15 AM
well.. thats of no use mate.. you can try the other posts.. they've got your answer..
search for the post written by mobix.. he has given the whole code somewhere.. may be in this same page..
Report
Re: HELP WITH PASCAL HANGMAN PLEASE Posted by j_808 on 9 May 2009 at 11:03 AM
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
Report
Re: HELP WITH PASCAL HANGMAN PLEASE Posted by Mobix on 9 May 2009 at 1:40 PM
you are so lazy and so annoying...
Report
Re: HELP WITH PASCAL HANGMAN PLEASE Posted by j_808 on 9 May 2009 at 3:32 PM
blimbly heck man! i just ask one question and i am suddenly called lazy?
Report
Re: HELP WITH PASCAL HANGMAN PLEASE Posted by Mobix on 9 May 2009 at 6:44 PM
There is an exam topic on the VB forum. I dont think that youll find many VB experts here.
Report
Re: HELP WITH PASCAL HANGMAN PLEASE Posted by Mobix on 10 May 2009 at 5:48 AM
I think ill be ok with programming but my programming looks messy and they might penalize me for it, anyone got any indentation tips?
Report
Re: HELP WITH PASCAL HANGMAN PLEASE Posted by j_808 on 10 May 2009 at 10:50 AM
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 :(
1 2  Next



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.