Code:
File: game.h
#include<func.h>/*<--Contains all relevant headers*/
class field;
class install;
class field
{
public:
field();
~field();
int mn[24][80];
int clr[24][80];
int bkg[24][80];
int rsv[24][80][128];
void dis();
void fill(int x1,int x2,int y1,int y2,int z1,int z2);
void color(int x1,int x2,int y1,int y2,int z1,int z2);
void rpc(int x1,int x2,int y1,int y2,int w,int z);
void output(int x,int y);
void outpt(int x,int y,int z);
void save(char a[]);
void load(char a[]);
void graph(int t1,int t2);
};
field::field()
{
fill(0,0,23,79,32,32);
color(0,0,23,79,7,0);
}
field::~field()
{
}
void field::graph(int t1,int t2)
{
int t;
for(t=t1;t<=t2;t++)
{
if(t>-1&&t<24)
outpt(23-t,t,254);
}
}
void field::save(char a[])
{
int x,y;
ofstream file(a);
for(x=0;x<24;x++)
{
for(y=0;y<80;y++)
{
file<<(char)mn[x][y];
file<<(char)clr[x][y];
file<<(char)bkg[x][y];
}
}
file.close();
}
void field::load(char a[])
{
int x,y;
char z;
ifstream file(a);
for(x=0;x<24;x++)
{
for(y=0;y<80;y++)
{
mn[x][y]=(int)file.get();
clr[x][y]=(int)file.get();
bkg[x][y]=(int)file.get();
}
}
file.close();
}
void field::color(int x1,int y1,int x2,int y2,int z1,int z2)
{
int x,y;
for(x=x1;x<=x2;x++)
{
for(y=y1;y<=y2;y++)
{
if(z1!=-1)
clr[x][y]=z1;
if(z2!=-1)
bkg[x][y]=z2;
}
}
}
void field::fill(int x1,int y1,int x2,int y2,int z1,int z2)
{
int x,y;
for(x=x1;x<=x2;x++)
{
for(y=y1;y<=y2;y++)
mn[x][y]=rand()%(z2-z1+1)+z1;
}
}
void field::output(int x,int y)
{
textcolor(clr[x][y]);
textbackground(bkg[x][y]);
gotoxy(y+1,x+1);
cout<<(char)mn[x][y];
}
void field::outpt(int x,int y,int z)
{
mn[x][y]=z;
output(x,y);
}
void field::dis()
{
int x,y;
for(x=0;x<24;x++)
{
for(y=0;y<80;y++)
output(x,y);
}
}
void field::rpc(int x1,int y1,int x2,int y2,int w,int z)
{
int x,y;
for(x=x1;x<=x2;x++)
{
for(y=y1;y<=y2;y++)
{
if(mn[x][y]==w)
mn[x][y]=z;
}
}
}
class install
{
public:
install(int x);
~install();
void fi(field a,char*b);
int fn[2];
field board;
};
install::install(int x)
{
fn[0]=x;fn[1]=0;
board.fill(0,0,0,fn[0]-1,178,178);
board.dis();
}
install::~install()
{
cout<<"Installation Complete";
getch();
}
void install::fi(field a,char b[])/*<--Problem area*/
{
a.save(b);
fn[1]++;
board.outpt(0,fn[1],219);
}
File: krad.cpp
#include<game.h>
int main(int argc,char*argv[])
{
int x;
install stuff(5);
field yo;
for(x=0;x<5;x++)
{
getch();
stuff.fi(yo,"yo.txt");/*<--program is fine w/out calling install::fi and simply performing the same three functions manually*/
}
getch();
return 0;
}