1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ufmMainTANK.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
Label1->Caption = Key;
if (Key == 38)
{
Tank1->Top = Tank1->Top -5;
}
if (Key == 40)
{
Tank1->Top = Tank1->Top +5;
}
if (Key == 37)
{
Tank1->Left = Tank1->Left -5;
}
if (Key == 39)
{
Tank1->Left = Tank1->Left +5;
}
if (Key == 13)
{
Balle1->SetBounds(Tank1->Left + 5,Tank1->Top - 5,Tank1->Height - 5,Tank1->Width );
Timer1->Enabled = true;
MessageBeep(MB_OK); //balle1 + bruit
}
if( (Balle1->Left > Tank2 -> Left) && (Balle1->Left < Tank2->Left ) )
{
Tank2->Visible = false;
Timer1->Enabled = false;
}
if((Balle1->Top > Tank2 -> Top) && (Balle1->Top < Tank2->Top))
{
Tank2->Visible = false;
Timer1->Enabled = false;
}
if((Balle1->Height > Tank2->Height) && (Balle1->Height < Tank2->Height))
{
Tank2->Visible = false;
Timer1->Enabled = false;
}
if((Balle1->Width > Tank2->Width) && (Balle1->Width < Tank2->Width))
{
Tank2->Visible = false;
Timer1->Enabled = false;
}
// joueur 2 pas encore configuré...
if (Key == 87)
{
Tank2->Top = Tank2->Top -5;
Balle2->Top = Balle2->Top -5;
}
if (Key == 83)
{
Tank2->Top = Tank2->Top +5;
Balle2->Top = Balle2->Top +5;
}
if (Key == 65)
{
Tank2->Left = Tank2->Left -5;
Balle2->Left = Tank2->Left -5;
}
if (Key == 68)
{
Tank2->Left = Tank2->Left +5;
Balle2->Left = Tank2->Left -5;
}
if (Key == 32)
{
Timer2->Enabled = true;
MessageBeep(MB_ICONEXCLAMATION); //balle2
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Balle1->Left = Balle1->Left +5;
Balle1->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Quitter1Click(TObject *Sender)
{
Form1->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
Balle2->Left = Balle2->Left -5;
Balle2->Visible = true;
}
//--------------------------------------------------------------------------- |