Ver Mensaje Individual
  #2  
Antiguo 14-11-2016
Snaked Snaked is offline
Baneado
NULL
 
Registrado: sep 2016
Posts: 102
Reputación: 0
Snaked Va por buen camino
Editor de Sectores (Sources)

Hola, entre ayer y hoy he estado ahi liado con el editor de Sectores del mapa...... aqui os dejo el codigo fuente por si veis algo que seguro se podrá mejorar......

Unit1.hpp
Código PHP:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.Menus.hpp>
#include <Vcl.Graphics.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    
TImage *tablero;
    
TBitBtn *BitBtn1;
    
TBitBtn *BitBtn3;
    
TScrollBar *ScrollBar;
    
TLabel *Label1;
    
TPopupMenu *PopupMenu1;
    
TMenuItem *InsertarInicioRuta1;
    
TMenuItem *InsertarFinRuta1;
    
TMenuItem *InsertarSpaceStation1;
    
TMenuItem *Coriolis11;
    
TMenuItem *MendellMedical1;
    
TMenuItem *Odissey11;
    
TMenuItem *InsertarAsteroidFields1;
    
TMenuItem *InsertarI1;
    
TMenuItem *Factory11;
    
TMenuItem *StoringContainers1;
    
TMenuItem *CancelLastInsert1;
    
TMenuItem *InsertTradeStation1;
    
TMenuItem *Goods1;
    
TMenuItem *Chemicals1;
    
TMenuItem *MetalsandMinnery1;
    
TMenuItem *BactaandPharmaceuticalGoods1;
    
TMenuItem *MilitaryEquipmentandDefense1;
    
TMenuItem *ISSInternationaSpaceStation1;
    
TMenuItem *NewAcheronMilitaryBase1;
    
TMainMenu *MainMenu1;
    
TMenuItem *SECTOR1;
    
TMenuItem *EstoesunCaosquieroempezardenuevo1;
    
TMenuItem *MegustacomovaquedandoQuieroGuardaresteSector1;
    
TMenuItem *SectorFinalizadoSbeloalSERVIDORCENTRAL1;
    
TLabel *Label_X;
    
TLabel *Label_Y;
    
TLabel *Label4;
    
TLabel *Label5;
    
TEdit *Edit1;
    
TTimer *Timer1;
    
TImage *Image1;
    
TImage *Image2;
    
TImage *Image3;
    
TImage *Image4;
    
TImage *Image5;
    
TImage *Image6;
    
TImage *Image7;
    
TImage *Image8;
    
TImage *Image9;
    
TImage *Image10;
    
TImage *Image11;
    
TImage *Image12;
    
TImage *Image13;
    
TImage *Image14;
    
TGroupBox *GroupBox1;
    
TRadioButton *RadioButton1;
    
TRadioButton *RadioButton2;
    
TRadioButton *RadioButton3;
    
TRadioButton *RadioButton4;
    
TRadioButton *RadioButton5;
    
TRadioButton *RadioButton6;
    
TRadioButton *RadioButton7;
    
TRadioButton *RadioButton8;
    
TRadioButton *RadioButton9;
    
TRadioButton *RadioButton10;
    
TRadioButton *RadioButton11;
    
TRadioButton *RadioButton12;
    
TRadioButton *RadioButton13;
    
TRadioButton *RadioButton14;
    
TRadioButton *RadioButton15;
    
TRadioButton *RadioButton16;
    
TMenuItem *InsertObjectPlanet1;
    
TGroupBox *GroupBox2;
    
TEdit *Edit2;
    
TEdit *Edit3;
    
TComboBox *ComboBox1;
    
TButton *Button1;
    
TCheckBox *CheckBox1;
    
TEdit *Edit4;
    
TEdit *Edit5;
    
TEdit *Edit6;
    
TEdit *Edit7;
    
TComboBox *ComboBox2;
    
TButton *Button2;
    
TCheckBox *CheckBox2;
    
void __fastcall BitBtn1Click(TObject *Sender);
    
void __fastcall BitBtn3Click(TObject *Sender);
    
void __fastcall Timer1Timer(TObject *Sender);
    
void __fastcall InsertarInicioRuta1Click(TObject *Sender);
    
void __fastcall InsertarFinRuta1Click(TObject *Sender);
    
void __fastcall InsertObjectPlanet1Click(TObject *Sender);
    
void __fastcall CheckBox1Click(TObject *Sender);
    
void __fastcall CheckBox2Click(TObject *Sender);
    
void __fastcall EstoesunCaosquieroempezardenuevo1Click(TObject *Sender);

private:    
// User declarations
public:        // User declarations
 
TGraphic *g;
  
TGraphic *g1;
 
TGraphic *g2;
    
__fastcall TForm1(TComponentOwner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif 

Unit1.cpp
Código PHP:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------

#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;

TPoint mouse_pos;
int current_route 0;
int current_object 0;
struct mapp {
              
AnsiString Nombre_Sector;
              
int objetos[15];
              
int coordX_objeto[15];
              
int coordY_objeto[15];
              
int total_objetos;
              
int rutas_inicio_X[15];
              
int rutas_fin_X[15];
              
int rutas_inicio_Y[15];
              
int rutas_fin_Y[15];
              
int total_rutas;
mapita;

bool SALIR false;
bool rejilla false;
bool muestra_rutas false;
bool muestra_objetos true;
int ini_rutaX 0int ini_rutaY 0;
int fin_rutaX 0int fin_rutaY 0;
void SECTOR_VEGA(void);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponentOwner)
    : 
TForm(Owner)
{
  
Form1->DoubleBuffered true;
}

//--------------------------------------------------------------------------
void Muestra_Mapa(void)
{

   
SECTOR_VEGA();

 
Form1->tablero->Repaint();
 
Application->ProcessMessages();

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

void SECTOR_VEGA(void)
{
 
Form1->0;

         
//Dibujamos fondo grafico
     
Form1->g2 0;
     
Form1->g2 Form2->Image12->Picture->Graphic;
     
Form1->tablero->Canvas->Draw(00,  Form1->g2);


 for(
int cont=0cont<=current_routecont++)
 {
      if(
muestra_rutas)
   {
     
Form1->tablero->Canvas->MoveTo(mapita.rutas_inicio_X[cont],mapita.rutas_inicio_Y[cont]);
     
Form1->tablero->Canvas->Pen->Color clLime;
     if(
mapita.rutas_fin_X[cont] != && mapita.rutas_fin_Y[cont] != 0)
     
Form1->tablero->Canvas->LineTo(mapita.rutas_fin_X[cont], mapita.rutas_fin_Y[cont]);
     }

   }

 for(
int cont=0cont<=current_objectcont++)
 {
      if(
muestra_objetos)
   {

     if(
mapita.objetos[cont] != 0)
      {
         
Form1->g2 0;
         switch(
mapita.objetos[cont])
         {
           case 
1:
           
Form1->g2 Form2->Image12->Picture->Graphic;
           
Form1->tablero->Canvas->Draw(00,  Form1->g2); break;

           case 
2:
           
Form1->g2 Form2->Image12->Picture->Graphic;
           
Form1->tablero->Canvas->Draw(00,  Form1->g2); break;

           case 
3:
           
Form1->g2 Form2->Image12->Picture->Graphic;
           
Form1->tablero->Canvas->Draw(00,  Form1->g2); break;

         }
      }
     }

   }
}


void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
int cont 0;
 
SALIR false;


 for(
cont 0cont 20000cont++)
 {

   
Muestra_Mapa();
   
Label1->Caption cont;
   if(
SALIR == true) break;
  }
}
//---------------------------------------------------------------------------


void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
 
SALIR true;
}
//---------------------------------------------------------------------------



void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
  
mouse_pos Mouse->CursorPos;
  if(
mouse_pos.<= 4mouse_pos.1;
  if(
mouse_pos.<= 42mouse_pos.1;
  
Label_X->Caption mouse_pos.XLabel_X->Refresh();
  
Label_Y->Caption mouse_pos.Y;Label_Y->Refresh();

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

void __fastcall TForm1::InsertarInicioRuta1Click(TObject *Sender)
{
  
ini_rutaX mouse_pos.4;
  
ini_rutaY mouse_pos.42;
  if(
current_route <= 14)
  {
    
mapita.rutas_inicio_X[current_route] = ini_rutaX;
    
mapita.rutas_inicio_Y[current_route] = ini_rutaY;
  }

  else 
ShowMessage("You reach MAX routes Allowed");
}
//---------------------------------------------------------------------------

void __fastcall TForm1::InsertarFinRuta1Click(TObject *Sender)
{
  
fin_rutaX mouse_pos.4;
  
fin_rutaY mouse_pos.42;
    if(
current_route <= 14)
  {
    
mapita.rutas_fin_X[current_route] = fin_rutaX;
    
mapita.rutas_fin_Y[current_route] = fin_rutaY;

    if(
Application->MessageBox(L"Do you want to SAVE this ROUTE (Keep on map):",
                              
L"Look"MB_OKCANCEL) == ID_OK)
                              {       
//save the current route line
                                
ShowMessage("You Choose SAVE the Route");
                                
current_route++;
                              }
  else {
           
ShowMessage("Canceled: Route Deleted");
           
mapita.rutas_fin_X[current_route] = 0;
           
mapita.rutas_fin_Y[current_route] = 0;

         }

  }

  else 
ShowMessage("You reach MAX routes Allowed");

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

void __fastcall TForm1::InsertObjectPlanet1Click(TObject *Sender)
{

 if(
current_object 14) {
     
ShowMessage("MAX Objects reached!! Can't add more on this map.");
     return;
 }

  if(
RadioButton3->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 1;
     
current_object++;
   }

  if(
RadioButton4->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 2;
     
current_object++;
   }

  if(
RadioButton5->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 3;
     
current_object++;
   }

  if(
RadioButton6->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 4;
     
current_object++;
   }


  if(
RadioButton7->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 5;
     
current_object++;
   }

  if(
RadioButton8->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 6;
     
current_object++;
   }

  if(
RadioButton9->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 7;
     
current_object++;
   }


  if(
RadioButton10->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 8;
     
current_object++;
   }


  if(
RadioButton11->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 9;
     
current_object++;
   }


  if(
RadioButton12->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 10;
     
current_object++;
   }


  if(
RadioButton13->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 11;
     
current_object++;
   }


  if(
RadioButton14->Checked == true)
   {
     
mapita.coordX_objeto[current_object] = mouse_pos.x;
     
mapita.coordY_objeto[current_object] = mouse_pos.y;
     
mapita.objetos[current_object] = 12;
     
current_object++;
   }


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



void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
  if(
CheckBox1->Checked == truemuestra_rutas true;
  else 
muestra_rutas false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox2Click(TObject *Sender)
{
   if(
CheckBox2->Checked == truemuestra_objetos true;
  else 
muestra_objetos false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::EstoesunCaosquieroempezardenuevo1Click(TObject *Sender)
{
  
// Inicializamos todo a cero.
 
int contador 0;
 
current_route 0;
 
current_object 0;

 for(
contador 0contador <= 14contador++)
  {
    
mapita.coordX_objeto[contador] = 0;
    
mapita.coordY_objeto[contador] = 0;
    
mapita.rutas_fin_X[contador] = 0;
    
mapita.rutas_fin_Y[contador] = 0;
    
mapita.rutas_inicio_X[contador] = 0;
    
mapita.rutas_inicio_Y[contador] = 0;
    
mapita.objetos[contador] = 0;
  }

    
mapita.total_objetos 0;
    
mapita.total_rutas 0;
}
//--------------------------------------------------------------------------- 
y este es el aspecto visual que presenta el programa


Última edición por Snaked fecha: 14-11-2016 a las 15:27:59.
Responder Con Cita