void random_question (void)
– забезпечує хаотичний вибір питання з бази даних питань.
void out_text (AnsiString x0,AnsiString x1,AnsiString x2,AnsiString x3,AnsiString x4)
– виводить на панелі текст питання та варіанти відповідей.
void update (void)
– оновляє текст питання та варіантів відповідей на панелях.
void fifty (void)
– прибирає дві неправильні відповіді.
void play (AnsiString file_name)
– відтворюєзвуковіфайли.
void save_rating (void)
- записує виграну суму в таблицю рейтингу гравців
void level (void)
– вибирає одну з трьох баз з питаннями для зчитування, в залежності від номера питання та не дозволяє повторюватись питанням.
void restore_base1 (void) , void restore_base2 (void),
void restore_base3 (void)
– заповнють тимчасові таблиці Temp1.dbf, Temp2.dbf,Temp3 даними з таблиць Level1.dbf , Level2.dbf, Level3.dbf.
Лістинг програми.
Модуль Millionar.cpp
#include <vcl.h>
#include <dos.h>
#pragma hdrstop
#include "Millionar.h"
#include "Millionar2.h"
#include "Telefon.h"
#include "Auditorium.h"
#include "Welcome.h"
#include "Stop.h"
#include "EditQuest.h"
#include "Password.h"
#include "Rating.h"
#include "Score.h"
#include "Game_end.h"
#include "No_Fire.h"
#include "Final.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
int position=1,telefon=1,fift=1,auditoria=1,pr_otv,
count_fields=0,next_player=0,auditorium;// Global variables
long summa;
AnsiString v0="",v1="",v2="",v3="",v4="";
//----------------------------------------------------------------------------
void out_text (AnsiString x0,AnsiString x1,AnsiString x2,
AnsiString x3,AnsiString x4);
//----------------------------------------------------------------------------
void restore_base1 (void);
void restore_base2 (void);
void restore_base3 (void);
void random_question (void);
//---------------------------------------------------------------------------
void level (void)
{
if (position<6)
{
if (Form1->Table4->RecordCount==0) restore_base1();
random_question ();
v0=Form1->Table4->FieldValues[("VOPROS")];
v1=Form1->Table4->FieldValues[("A")];
v2=Form1->Table4->FieldValues[("B")];
v3=Form1->Table4->FieldValues[("C")];
v4=Form1->Table4->FieldValues[("D")];
pr_otv=Form1->Table4->FieldValues[("PR_OTV")];
Form1->Table4->Delete();
}
if (position>=6 && position<11)
{
if (Form1->Table5->RecordCount==0) restore_base2();
random_question ();
v0=Form1->Table5->FieldValues[("VOPROS")];
v1=Form1->Table5->FieldValues[("A")];
v2=Form1->Table5->FieldValues[("B")];
v3=Form1->Table5->FieldValues[("C")];
v4=Form1->Table5->FieldValues[("D")];
pr_otv=Form1->Table5->FieldValues[("PR_OTV")];
Form1->Table5->Delete();
}
if (position>=11)
{
if (Form1->Table6->RecordCount==0) restore_base3();
random_question ();
v0=Form1->Table6->FieldValues[("VOPROS")];
v1=Form1->Table6->FieldValues[("A")];
v2=Form1->Table6->FieldValues[("B")];
v3=Form1->Table6->FieldValues[("C")];
v4=Form1->Table6->FieldValues[("D")];
pr_otv=Form1->Table6->FieldValues[("PR_OTV")];
Form1->Table6->Delete();
}
}
//-----------------------------------------------------------------------------
void play (AnsiString file_name)
{
Form1->Player1->FileName=file_name;
Form1->Player1->Open();
Form1->Player1->Play();
}
//-----------------------------------------------------------------------------
void flash (int panel,TColor color)
{
switch (panel)
{
case 1:Form1->Panel1->Color=color;break;
case 2:Form1->Panel2->Color=color;break;
case 3:Form1->Panel3->Color=color;break;
case 4:Form1->Panel4->Color=color;break;
}
}
//----------------------------------------------------------------------------
void fifty (void)
{
switch (auditorium)
{
case 1:
{
v1=v1;
v2=v4="";
}break;
case 2:
{
v2=v2;
v3=v1="";
}break;
case 3:
{
v3=v3;
v4=v1="";
}break;
case 4:
{
v4=v4;
v1=v2="";
}
}
out_text (v0,v1,v2,v3,v4);
fift=0;
}
//----------------------------------------------------------------------------
void clear_level (void)
{
TColor form_color=Form1->Color;
Form1->Label1->Color=form_color;
Form1->Label2->Color=form_color;
Form1->Label3->Color=form_color;
Form1->Label4->Color=form_color;
Form1->Label5->Color=form_color;
Form1->Label6->Color=form_color;
Form1->Label7->Color=form_color;
Form1->Label8->Color=form_color;
Form1->Label9->Color=form_color;
Form1->Label10->Color=form_color;
Form1->Label11->Color=form_color;
Form1->Label12->Color=form_color;
Form1->Label13->Color=form_color;
Form1->Label14->Color=form_color;
Form1->Label15->Color=form_color;
}
//----------------------------------------------------------------------------
void update (void)
{
Form1->Panel1->Color=clBtnFace;
Form1->Panel2->Color=clBtnFace;
Form1->Panel3->Color=clBtnFace;
Form1->Panel4->Color=clBtnFace;
level();
out_text (v0,v1,v2,v3,v4);
}
//---------------------------------------------------------------------------
void out_text (AnsiString x0,AnsiString x1,AnsiString x2,
AnsiString x3,AnsiString x4)
{
Form1->Panel1->Caption=x1;
Form1->Panel2->Caption=x2;
Form1->Panel3->Caption=x3;
Form1->Panel4->Caption=x4;
Form1->Panel5->Caption=x0;
}
//---------------------------------------------------------------------------
void random_question (void)
{
int base;
if (position<=6) base=1;
if (position>=6 && position<=11) base=2;
if (position>11) base=3;
randomize();
switch (base)
{
case 1:
{
randomize();
int rnd=random (Form1->Table4->RecordCount);
Form1->Table4->First();
Form1->Table4->MoveBy(rnd);
}break;
case 2:
{
randomize();
int rnd=random (Form1->Table5->RecordCount);
Form1->Table5->First();
Form1->Table5->MoveBy(rnd);
}break;
case 3:
{
randomize();
int rnd=random (Form1->Table6->RecordCount);
Form1->Table6->First();
Form1->Table6->MoveBy(rnd);
}break;
}
}
//---------------------------------------------------------------------------
void no_fire ()
{
if (position==6)
{
NoFire->Summa->Left=160;
NoFire->Summa->Caption=("1 000 грн.");
NoFire->Level->Caption="першої";
NoFire->ShowModal();
}
if (position==11)
{
NoFire->Summa->Left=144;
NoFire->Summa->Caption=("32 000 грн.");
NoFire->Level->Caption="другої";
NoFire->ShowModal();
}
}
//---------------------------------------------------------------------------
void next (void)
{
clear_level();
random_question ();
switch (position)
{
case 1:{Form1->Label1->Color=clYellow;summa=100;break;}
case 2:{Form1->Label2->Color=clYellow;summa=200;break;}
case 3:{Form1->Label3->Color=clYellow;summa=300;break;}
case 4:Form1->Label4->Color=clYellow;summa=500;break;
case 5:Form1->Label5->Color=clYellow;summa=1000;break;
case 6:Form1->Label6->Color=clYellow;summa=2000;break;
case 7:Form1->Label7->Color=clYellow;summa=4000;break;
case 8:Form1->Label8->Color=clYellow;summa=8000;break;
case 9:Form1->Label9->Color=clYellow;summa=16000;break;
case 10:Form1->Label10->Color=clYellow;summa=32000;break;
case 11:Form1->Label11->Color=clYellow;summa=64000;break;
case 12:Form1->Label12->Color=clYellow;summa=100000;break;
case 13:Form1->Label13->Color=clYellow;summa=200000;break;
case 14:Form1->Label14->Color=clYellow;summa=500000;break;
case 15:Form1->Label15->Color=clYellow;summa=1000000;break;
}
position++;
}
//---------------------------------------------------------------------------
void score (int s)
{
if (s==1)fmScore->ShowModal ();
if (s==0) return;
}
//---------------------------------------------------------------------------
void save_rating (void)
{
AnsiString name_player=Form4->Edit1->Text;
if (fmRating->Table1->RecordCount>10)
{
for (int i=0; i<fmRating->Table1->RecordCount; i++)
{
fmRating->Table1->Delete();
fmRating->Table1->Next();
}
fmRating->Table1->First();
}
if (position==6) summa=1000;
if (position==11) summa=100000;
fmRating->Table1->Edit();
fmRating->Table1->FieldValues[("NAME")]=name_player;
fmRating->Table1->FieldValues[("BODY")]=summa;
fmRating->Table1->Next();
}
//---------------------------------------------------------------------------
void nepravilno (int panel)
{
AnsiString sound="Gong.wav";
TColor color=clRed;
switch (panel)
{
case 1:Form1->Panel1->Color=color;break;
case 2:Form1->Panel2->Color=color;break;
case 3:Form1->Panel3->Color=color;break;
case 4:Form1->Panel4->Color=color;break;
}
play(sound);
EndGame->ShowModal();
save_rating ();
}
//---------------------------------------------------------------------------
void verify (int p)
{
if (p==pr_otv)
{
int s=1;
TColor color=clGreen;
if (position==15)
{
summa=1000000;
save_rating();
score (s);
fmFinal->Show();
s=0;
}
next ();
score (s);
flash (p,color);
update();
no_fire();
}
else nepravilno (p);
}
//---------------------------------------------------------------------------
void restore_base1 (void)
{
Form1->Table1->First();
Form1->Table4->First();
for (int i=0; i<Form1->Table1->RecordCount; i++)
{
Form1->Table4->Insert();
Form1->Table4->FieldValues[("VOPROS")]=Form1->Table1->FieldValues[("VOPROS")];
Form1->Table4->FieldValues[("A")]=Form1->Table1->FieldValues[("A")];
Form1->Table4->FieldValues[("B")]=Form1->Table1->FieldValues[("B")];
Form1->Table4->FieldValues[("C")]=Form1->Table1->FieldValues[("C")];
Form1->Table4->FieldValues[("D")]=Form1->Table1->FieldValues[("D")];
Form1->Table4->FieldValues[("PR_OTV")]=Form1->Table1->FieldValues[("PR_OTV")];
Form1->Table1->Next();
Form1->Table4->Next();
}
}
void restore_base2 (void)
{
Form1->Table2->First();
Form1->Table5->First();
for (int i=0; i<Form1->Table2->RecordCount; i++)
{
Form1->Table5->Insert();
Form1->Table5->FieldValues[("VOPROS")]=Form1->Table2->FieldValues[("VOPROS")];
Form1->Table5->FieldValues[("A")]=Form1->Table2->FieldValues[("A")];
Form1->Table5->FieldValues[("B")]=Form1->Table2->FieldValues[("B")];
Form1->Table5->FieldValues[("C")]=Form1->Table2->FieldValues[("C")];
Form1->Table5->FieldValues[("D")]=Form1->Table2->FieldValues[("D")];
Form1->Table5->FieldValues[("PR_OTV")]=Form1->Table2->FieldValues[("PR_OTV")];
Form1->Table2->Next();
Form1->Table5->Next();
}
}
void restore_base3 (void)
{
Form1->Table3->First();
Form1->Table6->First();
for (int i=0; i<Form1->Table3->RecordCount; i++)
{
Form1->Table6->Insert();
Form1->Table6->FieldValues[("VOPROS")]=Form1->Table3->FieldValues[("VOPROS")];
Form1->Table6->FieldValues[("A")]=Form1->Table3->FieldValues[("A")];
Form1->Table6->FieldValues[("B")]=Form1->Table3->FieldValues[("B")];