Gierka w jezyku C++ // pomocy !! pilne !!

0

Witam.
Potrzebuje pomocy przy przerobieniu gry z jednego na dwoch graczy.

  • pileczka powinna przechodzic na dole i u gory co bedzie oznaczalo zdobycie punktu.

Program wyglada nastepujaco:

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

#include <vcl.h>
#pragma hdrstop

#include "PPong.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int x,  y;    //wspolrzedne pilki
int dx, dy;   //przyrost wspolrzednych
int r;        //promin pilki
TColor cBall; //color pilki
TColor cBack; //color tla
int wp, hp;   //rozmir pola dla ping-pongu

// zmienne dla sterowania gra
int rd;        // 0  - stop / 1  - wlewo 2 - wprawo
int rx1, rx2;  // wspolrzedne X paska dla odbicia
int ry;        // wpolrzedna  Y paska
int rdx;       // krok przesowania paska
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
r = 5;           // polka
x  = 10; y = 10;   // polozenie startowe pilki
dx = 1;
dy = 1;
cBall = (TColor)RGB(217, 217, 25); // color pilki
cBack = (TColor)RGB(33, 94, 33);  // color tla
Form1->Color = cBack;
wp = Form1->ClientWidth;
hp = Form1->ClientHeight;
//    sterowanie paskiem
rd = 0;       // pasek stoi na miejscy
rx1=100;
rx2=155;
ry = Form1->ClientHeight  - 20;  // polozenie pionowe pasku
rdx = 2;  // krok ruchu paska

// ustawenia zegara
Timer1->Interval = 10;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
if (rd != 0 )
// trzymamy klawisz
 return ;
switch (Key)
 {
 case VK_LEFT : // wlewo
   rd = 2;   break;
 case VK_RIGHT: // wprawo
   rd = 1; break;
 }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
 rd = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
 // rysujeme pasek
  Form1->Canvas->Pen->Color = clRed;
  Form1->Canvas->Rectangle(rx1, ry, rx2, ry+1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 // scieranie pilki
 Form1->Canvas->Pen->Color = cBack;
 Form1->Canvas->Ellipse(x,y,x+r,y+r);
 //  nowe wspolrzedne pilki
if  ( dx > 0  )
{
// pilka leci wprawo
if  ((x + dx + r) >wp) dx = -dx;
}
// ....wlewo
if  ((x + dx - r) < 0 ) dx = -dx;

if ( dy >  0 )
{
 // .... wdol
 if ((x >= rx1) && (x <= rx2 -r) && (y == ry - r - 1))
 // trafienie w pasek
  dy = - dy;
 else
 if (y + dy + r > Form1->ClientHeight ) dy = -dy;
}
 else
{
// .... dogory
if   ((x >= rx1) && (x <= rx2) && (y >= ry - r) && (y <= ry + r))
{
// Pilka odbila sie od dolnej sciany i trafila w pasek z tylu
// Rysujemy ponownie pasek
 Form1->Canvas->Pen->Color = clRed;
 Form1->Canvas->Rectangle(rx1, ry, rx2, ry+1);
}
if  (y + dy - r < 0)  dy = -dy;
}
x+= dx;
y+= dy;
// rysowanie pilki w nowym punkcie
Form1->Canvas->Pen->Color = cBall;
Form1->Canvas->Ellipse(x,y,x+r,y+r);

// ruch paska
if   (rd != 0)
{
// ncisniety i utrymywany klawisz "wlewo" lub "wprawo"

if  (rd == 1)
{
// wprawo
if  (rx2 < wp)
{
// rysujem ponownie pasek
Form1->Canvas->Pen->Color  =  cBack;
Form1->Canvas->Rectangle(rx1,ry,rx1+rdx,ry + 1);
Form1->Canvas->Pen->Color = clRed;
Form1->Canvas->Rectangle(rx2,ry,rx2+rdx,ry+1);
 rx1+= rdx;
 rx2+= rdx;
}
}
else
// wlewo
if  (rx1 > 1 )
{
Form1->Canvas->Pen->Color = cBack;
Form1->Canvas->Rectangle(rx2,ry,rx2-rdx,ry+1);
Form1->Canvas->Pen->Color = clRed;
Form1->Canvas->Rectangle(rx1 - rdx, ry, rx1 +rdx, ry+1);
rx1-=rdx;
rx2-=rdx;
}
}

}

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

do tego sa jeszcze 2 pliczki:

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

#ifndef PPongH
#define PPongH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
        TTimer *Timer1;
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall FormKeyUp(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall FormPaint(TObject *Sender);
        void __fastcall Timer1Timer(TObject *Sender);
private:    // User declarations
public:     // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

i

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

#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("PPong.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->CreateForm(__classid(TForm1), &Form1);
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        catch (...)
        {
                 try
                 {
                         throw Exception("");
                 }
                 catch (Exception &exception)
                 {
                         Application->ShowException(&exception);
                 }
        }
        return 0;
}
//---------------------------------------------------------------------------
0

to opis gry ?

0

To jest gra.. tylko na 1 gracza... potrzebuje na 2 graczy...

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0