Смекни!
smekni.com

Программа игры Кости (стр. 2 из 3)

Form1

// ---------------------------------------------------------------------------

#include <vcl. h>

#pragma hdrstop

#include "Unit1. h"

#include "Unit2. h"

// ---------------------------------------------------------------------------

#pragma package (smart_init)

#pragma resource "*. dfm"

TForm1 *Form1;

AnsiString name;

// ---------------------------------------------------------------------------

__fastcall TForm1:: TForm1 (TComponent* Owner)

: TForm (Owner)

{

Image3->Visible=false;

}

// ---------------------------------------------------------------------------

void __fastcall TForm1:: Animate1Close (TObject *Sender)

{

Edit1->Text=2;

}

// ---------------------------------------------------------------------------

void __fastcall TForm1:: Image2MouseMove (TObject *Sender, TShiftState Shift,

int X, int Y)

{

Image3->Visible=true;

}

// ---------------------------------------------------------------------------

void __fastcall TForm1:: Image2MouseDown (TObject *Sender,

TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image3->Show ();

}

// ---------------------------------------------------------------------------

void __fastcall TForm1:: Image2MouseUp (TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y)

{

Image3->Hide ();

name=Edit1->Text;

if ( (name! ="") && (name! =" ")) {

Form2->Show ();

Form2->Label4->Caption=name;

Form1->Hide (); }

else

{ShowMessage ("Ââåäèòå èìÿ"); }

}

// ---------------------------------------------------------------------------

Form2

// ---------------------------------------------------------------------------

#include <vcl. h>

#pragma hdrstop

#include "Unit1. h"

#include "Unit2. h"

#include "Unit4. h"

#include "Unit3. h"

#include "Unit1. h"

#include "Unit5. h"

// ---------------------------------------------------------------------------

#pragma package (smart_init)

#pragma resource "*. dfm"

TForm2 *Form2;

int i=0;

int v=0;

int l=0;

int a,b,sum=0;

int h,x,st,ns;

// ---------------------------------------------------------------------------

__fastcall TForm2:: TForm2 (TComponent* Owner)

: TForm (Owner)

{

Form2->Caption = ("Êîñòè " + DateToStr (Now ()));

Button2->Enabled=false;

Button3->Enabled=false;

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: N4Click (TObject *Sender)

{

Form1->Close ();

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Button2Click (TObject *Sender)

{

Button3->Enabled=true;

a=random (6) +1;

b=random (6) +1;

i=i+1;

Memo1->Lines->Add ("Èãðîê " + Label4->Caption);

Memo1->Lines->Add ("Áðîñîê ¹ " + IntToStr (i));

Memo1->Lines->Add ("Ïåðâûé êóáèê = " + IntToStr (a));

Memo1->Lines->Add ("Âòîðîé êóáèê = " + IntToStr (b));

switch (a)

{

case 1: Image2->Picture->LoadFromFile ("1. jpg"); break;

case 2: Image2->Picture->LoadFromFile ("2. jpg"); break;

case 3: Image2->Picture->LoadFromFile ("3. jpg"); break;

case 4: Image2->Picture->LoadFromFile ("4. jpg"); break;

case 5: Image2->Picture->LoadFromFile ("5. jpg"); break;

case 6: Image2->Picture->LoadFromFile ("6. jpg"); break;

}

switch (b)

{

case 1: Image3->Picture->LoadFromFile ("1. jpg"); break;

case 2: Image3->Picture->LoadFromFile ("2. jpg"); break;

case 3: Image3->Picture->LoadFromFile ("3. jpg"); break;

case 4: Image3->Picture->LoadFromFile ("4. jpg"); break;

case 5: Image3->Picture->LoadFromFile ("5. jpg"); break;

case 6: Image3->Picture->LoadFromFile ("6. jpg"); break;

}

sum=a+b;

Memo1->Lines->Add ("Ñóììà êóáèêîâ = " + IntToStr (sum));

if (sum == x)

{

Memo1->Lines->Add ("Âû âûèãðàëè! Âàø âûéãðûøü óâåëè÷èí = (");

ns=ns+st*4;

Animate1->Visible=true;

Animate1->FileName= ("win. avi");

Animate1->Play (1,60,10000);

v=v+1;

Memo1->Lines->Add ("Êîëè÷åñòâî ïîáåä: "+IntToStr (v));

Memo1->Lines->Add ("Êîëè÷åñòâî ïîðàæåíèé: "+IntToStr (l));

}

else

{

if (sum < x)

{

Memo1->Lines->Add ("Âû âûèãðàëè!! = (");

ns=ns+st;

Animate1->Visible=true;

Animate1->FileName= ("win. avi");

Animate1->Play (1,60,10000);

v=v+1;

Memo1->Lines->Add ("Êîëè÷åñòâî ïîáåä: "+IntToStr (v));

Memo1->Lines->Add ("Êîëè÷åñòâî ïîðàæåíèé: "+IntToStr (l));

}

}

if (sum > x)

{

Memo1->Lines->Add ("Âû ïðîèãðàëè!! =)");

ns=ns-st;

Animate1->Visible=true;

Animate1->FileName= ("loose. avi");

Animate1->Play (1,60,10000);

l=l+1;

Memo1->Lines->Add ("Êîëè÷åñòâî ïîðàæåíèé: "+IntToStr (l));

Memo1->Lines->Add ("Êîëè÷åñòâî ïîáåä: "+IntToStr (v));

}

Edit1->Text=IntToStr (ns);

if (ns<=0) {

Form3->ShowModal ();

}

Memo1->Lines->Add ("Ñîîòíîøåíèå ïîáåä è ïîðàæåíèé: "+IntToStr (v) +" ê "+IntToStr (l));

Button2->Enabled=true;

Button3->Enabled=true;

// Button4->Enabled=true;

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: FormClose (TObject *Sender, TCloseAction &Action)

{

Form1->Close ();

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Button1Click (TObject *Sender)

{

if ( (Edit2->Text! ="") && (Edit3->Text! ="")) {

ns=StrToInt (Edit1->Text);

st=StrToInt (Edit2->Text);

x=StrToInt (Edit3->Text);

if ( (x<2) || (x>12) || (st>ns)) {ShowMessage ("Ïðîâåðüòå ïðàâèëüíîñòü ââîäà"); }

else

Button2->Enabled=true;

}

else

{ShowMessage ("Îäíî èç ïîëåé íå çàïîëíåíî!"); }

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Edit2Change (TObject *Sender)

{

Button2->Enabled=false;

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Edit3Change (TObject *Sender)

{

Button2->Enabled=false;

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Edit2KeyPress (TObject *Sender, char &Key)

{

if ( (Key >= '0') && (Key <= '9') || (Key == 8)) {} // öèôðû

else

{

Key = 0; // íå öèôðà

}

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Edit3KeyPress (TObject *Sender, char &Key)

{

if ( (Key >= '0') && (Key <= '9') || (Key == 8)) {} // öèôðû

else

{

Key = 0; // íå öèôðà

}

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Image1MouseMove (TObject *Sender, TShiftState Shift,

int X, int Y)

{

Label5->Caption = TimeToStr (Now ());

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: N3Click (TObject *Sender)

{

Form2->Hide ();

Form1->Show ();

Edit1->Text=100;

Edit2->Text="2";

Edit3->Text="3";

i,v,l=0;

Button2->Enabled=false;

Button3->Enabled=false;

Form1->Edit1->Text="";

Memo1->Clear ();

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: Button3Click (TObject *Sender)

{

Memo1->Clear ();

i,v,l=0;

Edit1->Text=100;

Button3->Enabled=false;

Animate1->Visible=false;

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: N5Click (TObject *Sender)

{

Form4->Show ();

}

// ---------------------------------------------------------------------------

void __fastcall TForm2:: N6Click (TObject *Sender)

{

Form5->Show ();

}

// ---------------------------------------------------------------------------

Form3

// ---------------------------------------------------------------------------

#include <vcl. h>

#pragma hdrstop

#include "Unit3. h"

#include "Unit2. h"

// ---------------------------------------------------------------------------

#pragma package (smart_init)

#pragma resource "*. dfm"

TForm3 *Form3;

// ---------------------------------------------------------------------------

__fastcall TForm3:: TForm3 (TComponent* Owner)

: TForm (Owner)

{

}

// ---------------------------------------------------------------------------

void __fastcall TForm3:: Button1Click (TObject *Sender)

{

Form2->N3->Click ();

Form3->Close ();

}

// ---------------------------------------------------------------------------

void __fastcall TForm3:: Button2Click (TObject *Sender)

{

Form2->Close ();

}

// ---------------------------------------------------------------------------

Листинг программы Delphi

Form2

unit Unit2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls, Menus, jpeg, ExtCtrls, ComCtrls;

type

TForm2 = class (TForm)

Image1: TImage;

Label1: TLabel;

MainMenu1: TMainMenu;

N1: TMenuItem;

N2: TMenuItem;

N3: TMenuItem;

N4: TMenuItem;

N5: TMenuItem;

N6: TMenuItem;

Edit1: TEdit;

Label2: TLabel;

Edit2: TEdit;

Label3: TLabel;

Button1: TButton;

Edit3: TEdit;

Label4: TLabel;

Button2: TButton;

Memo1: TMemo;

Image2: TImage;

Image3: TImage;

Animate1: TAnimate;

Button3: TButton;

Label5: TLabel;

procedure Button1Click (Sender: TObject);

procedure FormClose (Sender: TObject; var Action: TCloseAction);

procedure N3Click (Sender: TObject);

procedure Edit2Change (Sender: TObject);

procedure Edit1Change (Sender: TObject);

procedure Edit1KeyPress (Sender: TObject; var Key: Char);

procedure Edit2KeyPress (Sender: TObject; var Key: Char);

procedure Button2Click (Sender: TObject);

procedure N2Click (Sender: TObject);

procedure Button3Click (Sender: TObject);

procedure N5Click (Sender: TObject);

procedure N6Click (Sender: TObject);

procedure Image1MouseMove (Sender: TObject; Shift: TShiftState; X,

Y: Integer);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

k,v,p,a,b,ns,st,x: integer;

prov1, prov2: string;

implementation

uses Unit1, Unit3, Unit4, Unit5;

{$R *. dfm}

procedure TForm2. Button1Click (Sender: TObject);

begin

prov1: =Edit1. Text;

prov2: =Edit2. Text;

if ( (prov1<>'') or (prov2<>'')) then begin

x: =Strtoint (Edit2. Text);

st: =Strtoint (Edit1. Text);

ns: =Strtoint (Edit3. Text);

if ( (x<2) or (x>12) or (st>ns)) then

begin

ShowMessage ('Проверьте правильность вводимых данных');

end

else

begin

button2. Enabled: =true;

end;

end

else begin

ShowMessage ('Проверьте правильность вводимых данных'); end;

end;

procedure TForm2. FormClose (Sender: TObject; var Action: TCloseAction);

begin

Form1. close;

end;

procedure TForm2. N3Click (Sender: TObject);

begin

form1. close;

end;

procedure TForm2. Edit2Change (Sender: TObject);

begin

Button2. Enabled: =false;

end;

procedure TForm2. Edit1Change (Sender: TObject);

begin

Button2. Enabled: =false;

end;

procedure TForm2. Edit1KeyPress (Sender: TObject; var Key: Char);

begin

if ( (Key >= '0') and (Key <= '9') or (Key = #8)) then begin end // цифры