Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14007

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

Report
Question about display Posted by anyman on 23 Dec 2004 at 4:05 AM
I am making a crossword puzzle game
First of all, I would show the question first.
It need to fill in the answer.
My problem is how can I display the answer after the user entered his answer.
How can I prevent him not to play the same question again
Report
Re: Question about display Posted by zibadian on 23 Dec 2004 at 4:32 AM
: I am making a crossword puzzle game
: First of all, I would show the question first.
: It need to fill in the answer.
: My problem is how can I display the answer after the user entered his answer.
: How can I prevent him not to play the same question again
:
Display: That depends on the way you store the answers. If you are using a 2D-array of char, then you'll need a nested for-do loop and GotoXY(), write() and/or writeln(). If the answers are stored in a 1-D array of string, you only need 1 for-do loop and writeln().

Prevent: Add a boolean for each question, which you initialize to false. If the user want to answer a question, first check that boolean. If it is false, ask the question and set it to true. Otherwise give the user a message that he already answered the question.
Report
Re: Question about display Posted by anyman on 23 Dec 2004 at 6:21 AM
: : I am making a crossword puzzle game
: : First of all, I would show the question first.
: : It need to fill in the answer.
: : My problem is how can I display the answer after the user entered his answer.
: : How can I prevent him not to play the same question again
: :
: Display: That depends on the way you store the answers. If you are using a 2D-array of char, then you'll need a nested for-do loop and GotoXY(), write() and/or writeln(). If the answers are stored in a 1-D array of string, you only need 1 for-do loop and writeln().
:
: Prevent: Add a boolean for each question, which you initialize to false. If the user want to answer a question, first check that boolean. If it is false, ask the question and set it to true. Otherwise give the user a message that he already answered the question.
:
Well I really need a sample

can u give it to me?
I really need it
thx
Report
Re: Question about display Posted by anyman on 23 Dec 2004 at 7:55 PM
: : Prevent: Add a boolean for each question, which you initialize to false. If the user want to answer a question, first check that boolean. If it is false, ask the question and set it to true. Otherwise give the user a message that he already answered the question.

But my question is inside the textfile
I read the question from the file
and display it
Report
Re: Question about display Posted by zibadian on 24 Dec 2004 at 7:34 AM
: : : Prevent: Add a boolean for each question, which you initialize to false. If the user want to answer a question, first check that boolean. If it is false, ask the question and set it to true. Otherwise give the user a message that he already answered the question.
:
: But my question is inside the textfile
: I read the question from the file
: and display it
:
Then you need to write to another file, which questions the user has answered. If the user wants to answer a question, first check if that question is already listed. If it is, warn the user. Otherwise ask the question.
Report
Re: Question about display Posted by anyman on 25 Dec 2004 at 7:16 PM
: Then you need to write to another file, which questions the user has answered. If the user wants to answer a question, first check if that question is already listed. If it is, warn the user. Otherwise ask the question.
:
I know how to do it.
But I have another question
How can I display the question again after I enter the answer
and display the answer in the position which I wanted.
And I still don't know how to prevent the user answer the same question again.
can u give me example.
Thx!
Report
Re: Question about display Posted by zibadian on 26 Dec 2004 at 7:20 AM
: : Then you need to write to another file, which questions the user has answered. If the user wants to answer a question, first check if that question is already listed. If it is, warn the user. Otherwise ask the question.
: :
: I know how to do it.
: But I have another question
: How can I display the question again after I enter the answer
: and display the answer in the position which I wanted.
: And I still don't know how to prevent the user answer the same question again.
: can u give me example.
: Thx!
:
To display text at the same position you need to use the GotoXY() procedure. It's located in the CRT unit.
Here is a sample code to check if user has already answered the question:
var
  f: text;
  i: integer;
  AlreadyAnswered: boolean;
begin
  AlreadyAnswered := false;
  Assign(f, 'aa.dat');
  Reset(f);
  while not eof(f) do
  begin
    readln(f, i);
    AlreadyAnswered := i = QuestionIndex;
    if AlreadyAnswered then Break; { If found, break out of the loop }
  end;
  Close(f);
  if not AlreadyAnswered then
  begin
    { Ask question }
    { Update Already-Answered File: }
    Assign(f, 'aa.dat');
    Append(f);
    writeln(f, QuestionIndex);
    Close(f);
  end;
end;

The variable QuestionIndex is an integer indicating, which question the user wishes to answer. Remember to clear the aa.dat file before the game using Rewrite().



 

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.