Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Łączenie plików cpp

Ostatnio zmodyfikowano 2012-06-03 20:51
Autor Wiadomość
Cookie_Monster
Temat założony przez niniejszego użytkownika
Łączenie plików cpp
» 2012-06-03 19:55:53
bfs.cpp

#include"naglowek.h"
#include<algorithm>
using namespace std;
struct found
{
int x,y,odl;
found(int a,int b,int w)
{
x=a;
y=b;
odl=w;
}
};
vector<found> Fcreep;
bool cmp(found a,found b)
{
if(a.odl<b.odl) return 1;
return 0;
}
void bfs(int a, int b, int odl)
{
//.......
}
void widocznosc(int x,int y)
{
Fcreep.resize(0);
memset(widok,0,47*47*sizeof(bool));
bfs(x,y,0);
sort(Fcreep.begin(),Fcreep.end(),cmp);
}

main.cpp

#include<iostream>
#include"naglowek.h"
using namespace std;
int swiat[47][47];
bool widok[47][47];
int heroy=6,herox=6;
int main()
{
for(int i=0;i<13;i++)
for(int j=0;j<13;j++)
cin>>swiat[j][i];

widocznosc(herox,heroy);
creepMove();
cout<<endl;

for(int i=0;i<Fcreep.size();++i)
cout<<Fcreep[i].x<<" "<<Fcreep[i].y<<endl;
cout<<"\n";
for(int i=0;i<13;i++)
{
for(int j=0;j<13;j++)
cout<<swiat[j][i]<<" ";
cout<<"\n";
}
system("pause");
return 0;
}

sad.cpp

#include"naglowek.h"
#include<algorithm>
using namespace std;
bool checked[12][12];
int ustawX=herox-5;
int ustawY=heroy-5;
int creepWay;
bool fhero;
bool search(int x,int y)
{
if(fhero) return 1;

if((swiat[x+1][y]==1||swiat[x+1][y]==2)&&!checked[x+1-ustawX][y-ustawY])
{
if(swiat[x+1][y]==2) {fhero=1; return 1;}
checked[x+1-ustawX][y-ustawY]=1;
if(search(x+1,y)) {creepWay=1; return 1;}
}
if((swiat[x-1][y]==1||swiat[x-1][y]==2)&&!checked[x-1-ustawX][y-ustawY])
{
if(swiat[x-1][y]==2) {fhero=1; return 1;}
checked[x-1-ustawX][y-ustawY]=1;
if(search(x-1,y)) {creepWay=2; return 1;}
}
if((swiat[x][y+1]==1||swiat[x][y+1]==2)&&!checked[x-ustawX][y+1-ustawY])
{
if(swiat[x][y+1]==2) {fhero=1; return 1;}
checked[x-ustawX][y+1-ustawY]=1;
if(search(x,y+1)) {creepWay=3; return 1;}
}
if((swiat[x][y-1]==1||swiat[x][y-1]==2)&&!checked[x-ustawX][y-1-ustawY])
{
if(swiat[x][y-1]==2) {fhero=1; return 1;}
checked[x-ustawX][y-1-ustawY]=1;
if(search(x,y-1)) {creepWay=4; return 1;}
}
return 0;
}

void creepMove()
{
for(int i=0;i<Fcreep.size();++i)
{
memset(checked,0,12*12*sizeof(bool));
fhero=0;
creepWay=0;
if(search(Fcreep[i].x,Fcreep[i].y))
switch(creepWay)
{
case 1: swap(swiat[Fcreep[i].x][Fcreep[i].y],swiat[Fcreep[i].x+1][Fcreep[i].y]);
break;
case 2: swap(swiat[Fcreep[i].x][Fcreep[i].y],swiat[Fcreep[i].x-1][Fcreep[i].y]);
break;
case 3: swap(swiat[Fcreep[i].x][Fcreep[i].y],swiat[Fcreep[i].x][Fcreep[i].y+1]);
break;
case 4: swap(swiat[Fcreep[i].x][Fcreep[i].y],swiat[Fcreep[i].x][Fcreep[i].y-1]);
break;
}

}
}
naglowek.h
#include<vector>
void widocznosc(int x,int y);
extern int swiat[47][47];
extern bool widok[47][47];
extern struct found;// co tu pisac
extern vector<found> Fcreep;//co tu wpisac
extern int heroy,herox;
void creepMove();

Teraz jest pytanie: Jak z vectora Fcreep, który jest zadeklarowany w bfs.cpp, odczytywać dane w main.cpp i sad.cpp? Czyli co wpisać w nagłówku?

Pozdrawiam
P-57769
DejaVu
» 2012-06-03 20:51:01
P-57774
« 1 »
  Strona 1 z 1