Od razu mówię, że sprawdzałem w google, ale jestem do dupy w szukaniu i nie znalazłem ;) Więc tak mam 3 pliczki (main.cpp, source.cpp, source.h) i chcę do funkcji w source.h wysłać oryginał dwuwymiarowej tablicy typu char, ale jakoś mi to nie wychodzi, więc proszę o pomoc i zamieszczam kod programu C:
main.cpp
#include <iostream>
#include "source.h"
#include <windows.h>
#include <conio.h>
#include <vector>
using namespace std;
int x[10];
int y[10];
char mapa[20][20];
string kierunek="up";
int main()
{
saveto(x, y, 10);
drawmap(mapa, 20, 20);
while(true)
{
system("cls");
movesnake(x, y, 10, kierunek);
drawsnakeonmap(x, y, 10, mapa)
displaymap(mapa, 20, 20);
}
}
source.cpp
#include <iostream>
#include "source.h"
#include <windows.h>
#include <conio.h>
#include <vector>
using namespace std;
void saveto(int *x, int *y, int s)
{
for(int a=0; a<=s-1; a++)
{
if(a==0) {
x[a]=10;
y[a]=10;
} else {
x[a]=x[a-1]+1;
y[a]=y[0];
}
}
}
void movesnake(int *x, int *y, int s, string k)
{
for(int a=s-1; a>=0; a--)
{
if(a==0) {
if(k=="up") {
y[a]=y[a]-1;
if(colision(x[a], y[a])==true) exit(0);
}
if(k=="down") {
y[a]=y[a]+1;
if(colision(x[a], y[a])==true) exit(0);
}
if(k=="right") {
x[a]=x[a]+1;
if(colision(x[a], y[a])==true) exit(0);
}
if(k=="left") {
x[a]=x[a]-1;
if(colision(x[a], y[a])==true) exit(0);
}
} else {
x[a]=x[a-1];
y[a]=y[a-1];
}
}
}
bool colision(int x, int y)
{
if(x<2 || y<2 || x>19 || y>19) return true;
else if(x>=2 && y>=2 && x<=19 && y<=19) return false;
}
void drawmap(char **s, int x, int y)
{
for(int ys=0; ys<=y-1; ys++)
{
for(int xs=0; xs<=x-1; xs++)
{
s[xs][ys] = '.';
}
}
}
void displaymap(char **s, int x, int y)
{
for(int ys=0; ys<=y-1; ys++)
{
for(int xs=0; xs<=x-1; xs++)
{
cout<< s[xs][ys];
}
cout<<endl;
}
}
void drawsnakeonmap(int *x, int *y, int s, string **st)
{
for(int a=s; a>=0; a--)
{
st[x[a]][y[a]] = 'X';
if (a==0) st[x[a]][y[a]] = 'O';
}
}
source.h
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <vector>
using namespace std;
void saveto(int *x, int *y, int s);
void movesnake(int *x, int *y, int s, string k);
bool colision(int x, int y);
void drawmap(char **s, int x, int y);
void displaymap(char **s ,int x, int y);
void drawsnakeonmap(int *x, int *y, int s, char **st);
PS Z góry dziękuje ;)