Groups

    Delphi HELP.

    Hello people, im having a bit of difficulty with a project that I am doing.. I am trying to link my delphi document with a .txt file that will store the highscore. If the score is greater than that saved then it flashes a message 5 times saying "Top Scorer" and overwrites the score on the .txt file. All help would be appreciated

    Please help me if you can!

    Code:

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, ExtCtrls;

    type
    TForm1 = class(TForm)
    buStart: TButton;
    LbDisplay: TLabel;
    RadioGroup1: TRadioGroup;
    procedure FormCreate(Sender: TObject);
    procedure buStartClick(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    {The Variables}
    var
    Form1: TForm1;
    count:integer; {RAM Variable}
    var Question:array[1..6]of string;
    var Answers1:array[1..6]of string;
    var PosAnswers1:array[1..6]of string;
    var PosAnswers2:array[1..6]of string;
    var Highscore : Textfile;

    totalscore, Password: Integer;
    implementation

    {$R *.dfm}

    procedure TForm1.FormCreate(Sender: TObject);

    var
    userAnswer, Counter, correctAnswer: Integer;


    begin

    {The Password system}

    totalscore :=0;
    Password :=7;

    CorrectAnswer:= 7;
    Counter := 0;

    repeat
    userAnswer :=strToInt(inputBox('','Enter your password.',''));
    if userAnswer correctAnswer then
    begin
    showMessage ('Password Entered Incorrectly.');
    Counter:= Counter + 1
    end;
    if (UserAnswer = correctAnswer) then showmessage ('Password Entered Correctly.');
    if counter =3 then
    showMessage ('Password entered incorrectly too often. Try again in 15 minutes.')
    until (userAnswer = correctAnswer) or (counter=3) ;
    If counter=3 then application.terminate;
    Count:=1;

    {Questions and possible answers}

    Question[1]:='"Who owns Microsoft?"';
    Question[2]:='"Who is the current U.S President?"';
    Question[3]:='"What is better.. A Mac or a PC?"';
    Question[4]:='"What software is used mainly in software development?"';
    Question[5]:='"How many fruit and veg are you meant to get each day?"';
    Question[6]:='"What was the OS before microsoft vista?"';

    Answers1[1]:='Bill Gates';
    Answers1[2]:='George Bush';
    Answers1[3]:='They are both the same!';
    Answers1[4]:='Html';
    Answers1[5]:='5';
    Answers1[6]:='Windows Me';

    PosAnswers1[1]:='Duncan Ballantyne';
    PosAnswers1[2]:='Barrack Obama';
    PosAnswers1[3]:='Mac';
    PosAnswers1[4]:='C++';
    PosAnswers1[5]:='3';
    PosAnswers1[6]:='Windows 98';

    PosAnswers2[1]:='Mr Apple';
    PosAnswers2[2]:='Bill Clinton';
    PosAnswers2[3]:='PC';
    PosAnswers2[4]:='Visual Basic';
    PosAnswers2[5]:='None!';
    PosAnswers2[6]:='Windows XP';

    LbDisplay.caption:=Question[count];
    RadioGroup1.Items.Clear;
    RadioGroup1.Items.Insert(0,Answers1[Count]);
    RadioGroup1.Items.Insert(1,PosAnswers1[Count]);
    RadioGroup1.Items.Insert(2,PosAnswers2[Count]);

    end;

    procedure TForm1.buStartClick(Sender: TObject);
    begin

    {score system}

    {question1}
    if (count=1) and (radiogroup1.ItemIndex=0) then
    totalscore:=totalscore+100;

    {question2}
    if (count=2) and (radiogroup1.ItemIndex=1) then
    totalscore:=totalscore+100;

    {question3}
    if (count=3) and (radiogroup1.ItemIndex=2) then
    totalscore:=totalscore+100;

    {question4}
    if (count=4) and (radiogroup1.ItemIndex=2) then
    totalscore:=totalscore+100;

    {question5}
    if (count=5) and (radiogroup1.ItemIndex=0) then
    totalscore:=totalscore+100;

    {question6}
    if (count=6) and (radiogroup1.ItemIndex=2) then
    totalscore:=totalscore+100;
    if (count=6) then
    ShowMessage('Your total score is: '+inttostr(totalscore));
    If totalscore=600 then showmessage('Well Done! You scored 100%!');

    {The Highscore }

    AssignFile(Highscore, 'Highscore.txt');

    If (Count =6) then application.terminate;


    Count:=Count+1;
    LbDisplay.caption:=Question[count];
    RadioGroup1.Items.Clear;
    RadioGroup1.Items.Insert(0,Answers1[Count]);
    RadioGroup1.Items.Insert(1,PosAnswers1[Count]);
    RadioGroup1.Items.Insert(2,PosAnswers2[Count]);

    end;

    end.

    1 Comment

    You really need to make it clear exactly where you're having a problem and what behaviour you require.
    Post a comment
    Avatar
    @
      Text
      Top Discussions
      1. word association Game73944533
      2. What do you feel like whinging about today?1927371
      3. So Brexit isn't going how a lot of Brexiters thought it would1947
      4. Just heard this...2 ★★★★★★★★★★★★★★ congrats to all on 392k ★★★★★★★★★★★★★★7767359

      See more discussions