123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home

Source Codes

Engineering Colleges

BE Students

Training  Reports (updated)

Seminar Reports (updated

Placement Papers (updated)

Forums

   Computer Science / IT

   Electronics

   Electrical

   Mechanical

   Chemical

   Civil

   CAT / MBA

   GMAT / Foreign MBA

Latest Jobs

Engineering Jobs / Technical Jobs

Management Jobs

Sitemap

About-Us

Terms of use

Displaying  Source Code(s)  
 

 
simple hangman-pascalsource

--------------------------------------------------------------------------------

Description : Not Specified

Code :

Program Hanger;
{a simple hangman-pascalsource by Seabert SoftWare, 1996}
{comments & suggestions : jjtaks@cs.ruu.nl}

Uses
Crt, WinDos;

Var
Words: Array[1..100] of String;
Sizes: Array[1..100] of Integer;
PlayWord, ChLine, word: String[10];
Ch: Char;
WordFile: Text;
i, j, lgt, Max, ChLgt: Integer;

Function ReadFile( FileName: String): Boolean;
begin
if ( FileName = '') then
ReadFile := False
else
begin
ReadFile := True;
i := 0;
Assign( WordFile, FileName)
Reset( WordFile);
While( not( EoF( WordFile))) do
begin
Inc( i);
ReadLn( WordFile, word);
Words[i] := word;
ReadLn( WordFile, lgt);
Sizes[i] := lgt;
end;
Max := i;
Close( WordFile);
end;
end;

Function ChooseWord: Boolean;
begin
Repeat
Randomize;
j := Random( Max);
Until (( j > 0) and ( j <= Max));
PlayWord := Words[j];
ChLgt := Sizes[j];
if ( PlayWord <> '') then
ChooseWord := True
else
ChooseWord := False;
end;

Procedure InitArrays;
begin
for i := 1 to 100 do
begin
Words[i] := '';
Sizes[i] := 0;
end;
end;

Procedure GamePlay;

Procedure ClrWord;
begin
For i := 1 to 10 do
PlayWord[i] := '';
end;

Procedure SetChLine;
begin
For i := 1 to 10 do
ChLine[i] := '-';
end;

begin
SetChLine;
Repeat
GoToXY( 15, 3);
For i := 1 to Max do
Write(ChLine[i]);
GoToXY( 1, 3);
Write('Enter a character: ');
ReadLn( Ch)
For i := 1 to Max do
begin
if ( Ch = PlayWord[i]) then
ChLine[i] := Ch;
end;
if ( ChLine = PlayWord) then
begin
GoToXY( 15, 1);
Write('You got it!');
end;
Until ( ChLine = PlayWord);
ClrScr;
ClrWord;
SetChLine;
end;

Begin
ClrScr;
Repeat
InitArrays;
if ( ReadFile( 'WORDS.TXT') = True) then
begin
if ( ChooseWord = True) then
GamePlay
else
begin
WriteLn('No words found.');
Halt(1);
end;
end
else
begin
WriteLn('Unable to read file WORDS.TXT.');
Halt(1);
end;
Write(' Again? ');
ReadLn( Ch);
Until ( UpCase( Ch) = 'N');
End.

{ WORDS.TXT ( example):
ape
3
book
4
circle
6
}
 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved copyright 123ENG