: : : : : :
This message was edited by anyman at 2004-12-12 3:37:8
: : : : : : The sample is here
: : : : : : program project;
: : : : : : uses wincrt;
: : : : : :
: : : : : : var word : array[1..8,1..5] of char;
: : : : : : i,j,k,score,choice:integer;
: : : : : : secret:array[1..3] of string;
: : : : : : answer : string;
: : : : : :
: : : : : :
: : : : : : Procedure Initial;
: : : : : : begin
: : : : : : for i:=1 to 8 do
: : : : : : for j:= 1 to 5 do
: : : : : : word[i,j] := '*';
: : : : : : end;
: : : : : :
: : : : : : Procedure display;
: : : : : : begin
: : : : : : for i := 1 to 8 do
: : : : : : begin
: : : : : : for j := 1 to 5 do
: : : : : : begin
: : : : : : write(word[i,j]);
: : : : : : end;
: : : : : : writeln;
: : : : : : end;
: : : : : : end;
: : : : : :
: : : : : : procedure assign;
: : : : : : begin
: : : : : : {Assign the first secret word}
: : : : : : word[1,1] := '1';
: : : : : : for i := 2 to 8 do
: : : : : : begin
: : : : : : word[i,1] := '?';
: : : : : : end;
: : : : : : {Assign the second sercet word}
: : : : : : word[2,1] := '2';
: : : : : : for j:= 2 to 4 do
: : : : : : begin
: : : : : : word[2,j] := '?';
: : : : : : end;
: : : : : : word[6,1] := '3';
: : : : : : {Assign the third secret word}
: : : : : : for j := 2 to 4 do
: : : : : : begin
: : : : : : word[6,j] := '?';
: : : : : : end;
: : : : : : end;
: : : : : : procedure start;
: : : : : : begin
: : : : : : writeln;
: : : : : : writeln;
: : : : : : writeln;
: : : : : : write('Which word do you want to guess(1,2,3)?');
: : : : : : readln(K);
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint1;
: : : : : : var done : boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[1] := 'CHANGJEI';
: : : : : : writeln;
: : : : : : writeln('Hint 1 : A 8 character word');
: : : : : : writeln('Meaning : The most common chinese typing method');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer?');
: : : : : : readln(answer);
: : : : : : If answer = secret[1] then
: : : : : : begin
: : : : : : writeln('You are correct !');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : procedure hint2;
: : : : : : var done:boolean;
: : : : : : begin
: : : : : : done:= false;
: : : : : : secret[2] := 'HTML';
: : : : : : writeln;
: : : : : : writeln('Hint 2: A 4 character phrase');
: : : : : : writeln('Meaning : the programming language for the web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[2] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Procedure Hint3;
: : : : : : var done: boolean;
: : : : : : begin
: : : : : : done := false;
: : : : : : secret[3] := 'JAVA';
: : : : : : writeln;
: : : : : : writeln('Hint 3: A 4 character phrase');
: : : : : : writeln('Meaning : The cross-platform programming language for the dynamic web page');
: : : : : : writeln;
: : : : : : Repeat
: : : : : : write('Enter your answer ?');
: : : : : : readln(answer);
: : : : : : if answer = secret[3] then
: : : : : : begin
: : : : : : writeln('You are correct!');
: : : : : : done := true;
: : : : : : end
: : : : : : else
: : : : : : writeln('You are wrong! Try it again!');
: : : : : : until done;
: : : : : : end;
: : : : : :
: : : : : : Begin {main}
: : : : : : initial;
: : : : : : assign;
: : : : : : display;
: : : : : : start;
: : : : : : if k = 1 then
: : : : : : hint1
: : : : : : else
: : : : : : if k = 2 then
: : : : : : hint2
: : : : : : else
: : : : : : if k = 3 then
: : : : : : hint3;
: : : : : : End.
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : wt can I improve
: : : : : I donna wt should I do
: : : : :
: : : : You can do the following to improve it:
: : : : - Add a loop to the main program so that the user can enter all three words
: : : : - Move the hints, words and their location and directions into an array, which generalizes the code
: : : : - Add the correct indentation, which makes the code itself more readable by others
: : : :
: : : :
: : : well
: : : I don't know how to add your suggestion into the program
: : : can u help me
: : :
: : Adding a loop to the main program should not be a problem, because you've done it before in procedures.
: : If you know what indentation is (see english dictionary and my Crossword puzzle), then that should also not be a problem.
: : You are already using the array to store your words in, but only for a short time. You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: :
:
: You should move all the Secret[] assignments to the Initial() procedure. If you then make an array for the hints, you can recode all the Hint() procedures into 1, with a single parameter to specify which word the user is entering.
: I don't exactly know what u mean
: Do u think that if I make the word into wordfile will be better
: by the way, do u hv e-mail,msn , icq or something like that, so I can contact u
:
An array is mostly used as a list of variables. The main advantage of an array over a true list of variables is that you can use other variables to control which array element you get.
For example:
This code
var
Number1, Number2, Number3, Number4, Number5: integer;
Sum: integer;
UserEntry: integer;
begin
Sum := Number1 + Number2 + Number3 + Number4 + Number5;
{...}
readln(UserEntry);
if UserEntry = 1 then
writeln(Number1)
else if UserEntry = 2 then
writeln(Number2)
else if UserEntry = 3 then
writeln(Number3)
else if UserEntry = 4 then
writeln(Number4)
else if UserEntry = 5 then
writeln(Number5);
end.
and this code give the same result:
const
NumberOfNumbers = 5;
var
Numbers: array[1..NumberOfNumbers] of integer;
Sum, i: integer;
begin
Sum := 0;
for i := 1 to NumberOfNumbers do
Sum := Sum + Numbers[i];
{...}
readln(UserEntry);
writeln(Numbers[UserEntry]);
end.
The main difference from a programmer's perspective is that the latter is far easier to modify. Suppose you want to expand the sum to 100 numbers. In the first case, you would need to create 95 additional variables. Then recode the calculation to include those 95 numbers. Also you need to change add 95 time the following 2 lines:
else if UserEntry = 5 then
writeln(Number5);
and change the 5 into a 6, 7, 8, etc.
In the second case, you just change the value of NumberOfNumbers to 100 and you're done.
As to the number of arrays, that completely depends on the way you want to store your data. I've used 1 array for all the words, hints and locations. And another one for the display of the game. I was able to do this, because I know about records. In your case I would use more than 2 arrays:
- Words
- Hints
- Locations (2-dimensional array)
- IsVertical
- Display