sábado, 21 de março de 2020

C++ Builder - Novo jogo Snake

A nossa cobrinha entrou na arena muito faminta,
ela sabe que encontrará frutas boas para sua alimentação, 
o que ela não sabe é que na arena estão espalhadas,
frutas venenosas que se parece bem com as frutas boas.
Use as setas direcionais do teclado do seu computador,
para conduzir nossa simpática cobrinha dentro da arena,
em busca das frutas comestíveis.
Lembrem sempre que se ela comer uma fruta venenosa,
ficará doente, sua cor muda para amarelo,
e se tornar a comer mais uma fruta venenosa,
ficará gravemente enferma, sua cor ficará vermelha,
e se ainda assim comer mais uma fruta venenosa,
ela morrerá, "GAME OVER".





//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstopFlag
#include "Unit2.h"
#include "Unit3.h"
#include <memory>
#define P_CIMA 0
#define P_DIREITA 1
#define P_BAIXO 2
#define P_ESQUERDA 3
#define CLS 0
#define COBRA 1
#define PRESA 2
#define LOCAL 3



//Percebeu a falta de alguns códigos?
//Fale comigo ainda hoje.

//---------------------------------------------------------------------------
void __fastcall TForm2::FormKeyDown ( TObject *Sender, WORD &Key,
        TShiftState Shift )
{
    if ( Key == VK_LEFT ) sentido = 3;
    if ( Key == VK_RIGHT) sentido = 1;
    if ( Key == VK_UP   ) sentido = 0;
    if ( Key == VK_DOWN ) sentido = 2;
}
//---------------------------------------------------------------------------
 void __fastcall TForm2::Partida ( TObject *Sender ) {
   Limpa_Tela ( Sender );
   Sorteia_Posicao_Snake ( );
   Embaralha_Frutas ( Sender );
   Posiciona_Coordenadas ( );

   Inicializa_Processos ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Timer1Timer ( TObject *Sender )
{
    Form2 -> Timer1 -> Enabled = true;
    Direciona_Snake ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Label1Click(TObject *Sender)
{
   x = true;
   Partida ( Sender );
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Label2Click(TObject *Sender)
{
  exit ( 0 );
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormShow(TObject *Sender)
{    a = -1;
    a_1 = 6;
    b = false;
    c = false;
    d = false;
    Form2 -> Image1 -> Visible = true;
    Form2 -> Label5 -> Visible = true;
    Lbl -> Visible = true;
    Label3 -> Caption = " ";
    Label4 -> Caption = " ";

}
//---------------------------------------------------------------------------



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

#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <Vcl.Imaging.GIFImg.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include <Vcl.Buttons.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published:    // IDE-managed Components
    TImage *Imagem_P_cima;
    TImage *Imagem_P_baixo;
    TImage *Imagem_P_direita;
    TImage *Imagem_P_esquerda;
    TTimer *Timer1;
    TImage *Image1;
    TShape *Shape1;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;
    TLabel *Label5;
   void __fastcall FormKeyDown ( TObject *Sender, WORD &Key,
          TShiftState Shift );
    void __fastcall Timer1Timer ( TObject *Sender );
    void __fastcall Inicializa_Processos ( TObject *Sender );
    void __fastcall gameOver ( TObject *Sender );
    void __fastcall Partida ( TObject *Sender );
    void __fastcall Direciona_Snake ( TObject *Sender );
    void __fastcall Limpa_Tela ( TObject *Sender );
    void __fastcall Label1Click ( TObject *Sender );
    void __fastcall Label2Click ( TObject *Sender );
    void __fastcall FormShow ( TObject *Sender );
    void __fastcall Embaralha_Frutas ( TObject *Sender );
private:    // User declarations
public:        // User declarations
        __fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.