F
flyoverXml
Unregistered / Unconfirmed
GUEST, unregistred user!
我在square类里定义了SquareArray[4][4],在screens类里定义了ScreenArray[N][M],
并把他们互设为友员,但是我在screens类成员函数里访问SquareArray[4][4],它竟然
出现没有定义SquareArray[4][4]变量,在square类成员函数里访问ScreenArray[N][M],
也竟然出现没有定义ScreenArray[N][M]变量,难道是友员用错?那我就避开这个问题,
把这两个变量都定义在public里,但是还是出现上面的错误,
这是怎么回事呢?????????????
程序见下(急救,赶着交作业),
错误在函数bool Square::CanMove(int nextX, int nextY)和void Screens::copyToScreen(int currentX,int currentY)里
//-------------定义了一个基本方块类-----------------------------------------
class Screens;
class Square;
class BaseSquare
{
private: // User declarations
TColor color;
int empty;
public: // User declarations
//initArray(int emp);
void initArray(int *array,int SCount);
// virtual void initArray(int array[][][],int SCount);
// virtual void paint();
bool CanMove(int currentX, int currentY);
// virtual bool CanMove(currentX,int currentY);
virtual void move(int currentX,int currentY);
};
//---------------定义了一个方块类---------------------------------------
class Square : public BaseSquare
{
private: // User declarations
int SquareArray[4][4];
TColor sqcolor;
TImage *image;
public: // User declarations
//virtual void initArray(int array[][][],int SCount);
virtual bool CanMove(int currentX,int currentY);
void paint(TCanvas *Canvas,int x,int y);
void move(int currentX,int currentY);
bool Change(int curx,int cury);
bool Canchange(int currentX,int currentY);
void initArray(int array[7][4][4],int SCount);
friend class Screens;
};
//-------------定义了 一个屏幕类-----------------------------------------
class Screens//: public BaseSquare
{
private: // User declarations
bool line[N];
TColor bgcolor;
int count;
int ScreenArray[N][M];
public: // User declarations
// int currentX,currentY,nextX,nextY;
void initArray();
bool IfLineFull(int currentX);
void deteLine(int currentX);
void paint(TCanvas *Canvas );
void copyToScreen(int currentX,int currentY);
void initline();
void setbgcolor(int bcolor);
int getcount();
void setcount();
// int getscores();
friend class Square;
friend class addSquare;
friend class deleSqure;
};
//--------------定义了一个可任意加的方块类----------------------------------------
class addSquare: public BaseSquare
{
private: // User declarations
int SquareArray[4][4];
public: // User declarations
//virtual void initArray(int array[][][],int SCount);
//virtual bool CanMove(currentX,int currentY);
// virtual void move(currentX,int currentY);
virtual void Paint();
void add();
};
//--------------定义了一个可任意减的方块类----------------------------------------
class deleSquare: public BaseSquare
{
private: // User declarations
int SquareArray[4][4];
public: // User declarations
// virtual void initArray(int array[][][],int SCount);
virtual bool CanMove(int currentX, int currentY);
// virtual void move(currentX,int currentY);
virtual void Paint();
void delect();
};
void Square::initArray(int array[7][4][4],int SCount)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
SquareArray[j]=array[SCount][j];
}
}
//------------------初始化屏幕----------------------------------------------
void Screens::initArray()
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<M;j++)
{
ScreenArray[j]=0;
}
}
//----------------------------------------------------------------
void Square::move(int currentX, int currentY)
{
//程序被paint包括
}
//--------------------------------------------------------------------
bool Square::CanMove(int nextX, int nextY)
{
bool flag=true;
int i,j;
if(nextX<0|| nextY<0|| nextX>N || nextY>M) //注意
return false;
else
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if((ScreenArray[i+nextX][j+nextY]==1)&&(SquareArray[j]==1)) flag=false;
}
return flag;
}
//-----------------------------------------------------------------
//---------------------------------------------------------------
bool Square::Canchange(int currentX,int currentY)
{
return true;
//程序包括在change里面
}
//---------------------画方块----------------------------
void Square:aint(TCanvas *Canvas,int x, int y)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(SquareArray[j]==1)
{
Canvas->Brush->Color=clGreen;// sqColor;
Canvas->Pen->Color=clGreen;// sqColor;
Canvas->Rectangle(x+j*15,y+i*15,x+15+j*15,y+15+i*15);
}
}
}
//-------------------------判断方块是否可以变形----------------------
bool Square::Change(int curx, int cury)
{
int temp[4][4],temp2[4][4],i,j,k;
int n=4;
//表示4维矩阵;
for(k=0;k<=1;k++)
{
for(i=0;i<n;i++)
{
temp[n-i-1][k]=SquareArray[k];
temp[n-i-1][n-k-1]=SquareArray[n-k-1];
}
// for(j=0;j<n;j++)
// {
// temp[n-k-1][j]=SquareArray[j][k];
// temp[k][j]=SquareArray[j][n-k-1];
// }
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
temp2[j]=SquareArray[j];
SquareArray[j]=temp[j];
}
if(!CanMove(curx,cury))
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
SquareArray[j]=temp2[j];
}
return false;
}
else
return true;
}
//---------------------初始化line[]全为false,表示全为非满;
void Screens::initline()
{
int i;
for(i=0;i<N;i++)
{
line=false;
}
}
//---------------把方块信息赋予screen中-------------------------------
void Screens::copyToScreen(int currentX,int currentY)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
[red] ScreenArray[i+currentX][j+currentY]=SquareArray[j]; [/red] }
}
//-----------------------检查screen中是否有行满---------------------------
bool Screens::IfLineFull(int currentX)
{
int i,j;
bool flag=false;
for(i=currentX;i<currentX+4;i++)
{
line=true;
for(j=0;j<M;j++)
{
if(ScreenArray[j]==0)
{
line=false;
continue;
}
}
if(line==true)
{
flag=true;
}
}
return flag;
}
//------------------------------消去screen中的满行-----------------------
void Screens::deteLine(int currentX)
{
int i,j,k;
count=0;
for(i=currentX;line==true&&i<currentX+4;i++)
{
for(k=i;k>=0;
k--)
{
for(j=0;j<M;j++)
{
ScreenArray[k][j]=ScreenArray[k-1][j];
}
}
count++;
}
}
//---------------------------在屏幕上画方块--------------------------------
void Screens:aint(TCanvas *Canvas )
{
int i,j;
Canvas->Pen->Color=clCream;//clSilver;
Canvas->Brush->Color=clCream;//clSilver;
Canvas->Rectangle(5,5,M*15+5,N*15+5);
for(i=0;i<N;i++)
for(j=0;j<M;j++)
{
if(ScreenArray[j]==1)
{
Canvas->Brush->Color=clGreen;// sqColor;
Canvas->Pen->Color=clGreen;// sqColor;
Canvas->Rectangle(5+j*15,5+i*15,5+(j+1)*15,5+(i+1)*15);
}
}
}
//---------------------------得到删除的行数值--------------------------------
int Screens::getcount()
{
return count;
}
void Screens::setcount()
{
count=0;
}
//---------------------------得到删除的行数值并计算分数--------------------------------
并把他们互设为友员,但是我在screens类成员函数里访问SquareArray[4][4],它竟然
出现没有定义SquareArray[4][4]变量,在square类成员函数里访问ScreenArray[N][M],
也竟然出现没有定义ScreenArray[N][M]变量,难道是友员用错?那我就避开这个问题,
把这两个变量都定义在public里,但是还是出现上面的错误,
这是怎么回事呢?????????????
程序见下(急救,赶着交作业),
错误在函数bool Square::CanMove(int nextX, int nextY)和void Screens::copyToScreen(int currentX,int currentY)里
//-------------定义了一个基本方块类-----------------------------------------
class Screens;
class Square;
class BaseSquare
{
private: // User declarations
TColor color;
int empty;
public: // User declarations
//initArray(int emp);
void initArray(int *array,int SCount);
// virtual void initArray(int array[][][],int SCount);
// virtual void paint();
bool CanMove(int currentX, int currentY);
// virtual bool CanMove(currentX,int currentY);
virtual void move(int currentX,int currentY);
};
//---------------定义了一个方块类---------------------------------------
class Square : public BaseSquare
{
private: // User declarations
int SquareArray[4][4];
TColor sqcolor;
TImage *image;
public: // User declarations
//virtual void initArray(int array[][][],int SCount);
virtual bool CanMove(int currentX,int currentY);
void paint(TCanvas *Canvas,int x,int y);
void move(int currentX,int currentY);
bool Change(int curx,int cury);
bool Canchange(int currentX,int currentY);
void initArray(int array[7][4][4],int SCount);
friend class Screens;
};
//-------------定义了 一个屏幕类-----------------------------------------
class Screens//: public BaseSquare
{
private: // User declarations
bool line[N];
TColor bgcolor;
int count;
int ScreenArray[N][M];
public: // User declarations
// int currentX,currentY,nextX,nextY;
void initArray();
bool IfLineFull(int currentX);
void deteLine(int currentX);
void paint(TCanvas *Canvas );
void copyToScreen(int currentX,int currentY);
void initline();
void setbgcolor(int bcolor);
int getcount();
void setcount();
// int getscores();
friend class Square;
friend class addSquare;
friend class deleSqure;
};
//--------------定义了一个可任意加的方块类----------------------------------------
class addSquare: public BaseSquare
{
private: // User declarations
int SquareArray[4][4];
public: // User declarations
//virtual void initArray(int array[][][],int SCount);
//virtual bool CanMove(currentX,int currentY);
// virtual void move(currentX,int currentY);
virtual void Paint();
void add();
};
//--------------定义了一个可任意减的方块类----------------------------------------
class deleSquare: public BaseSquare
{
private: // User declarations
int SquareArray[4][4];
public: // User declarations
// virtual void initArray(int array[][][],int SCount);
virtual bool CanMove(int currentX, int currentY);
// virtual void move(currentX,int currentY);
virtual void Paint();
void delect();
};
void Square::initArray(int array[7][4][4],int SCount)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
SquareArray[j]=array[SCount][j];
}
}
//------------------初始化屏幕----------------------------------------------
void Screens::initArray()
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<M;j++)
{
ScreenArray[j]=0;
}
}
//----------------------------------------------------------------
void Square::move(int currentX, int currentY)
{
//程序被paint包括
}
//--------------------------------------------------------------------
bool Square::CanMove(int nextX, int nextY)
{
bool flag=true;
int i,j;
if(nextX<0|| nextY<0|| nextX>N || nextY>M) //注意
return false;
else
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if((ScreenArray[i+nextX][j+nextY]==1)&&(SquareArray[j]==1)) flag=false;
}
return flag;
}
//-----------------------------------------------------------------
//---------------------------------------------------------------
bool Square::Canchange(int currentX,int currentY)
{
return true;
//程序包括在change里面
}
//---------------------画方块----------------------------
void Square:aint(TCanvas *Canvas,int x, int y)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
if(SquareArray[j]==1)
{
Canvas->Brush->Color=clGreen;// sqColor;
Canvas->Pen->Color=clGreen;// sqColor;
Canvas->Rectangle(x+j*15,y+i*15,x+15+j*15,y+15+i*15);
}
}
}
//-------------------------判断方块是否可以变形----------------------
bool Square::Change(int curx, int cury)
{
int temp[4][4],temp2[4][4],i,j,k;
int n=4;
//表示4维矩阵;
for(k=0;k<=1;k++)
{
for(i=0;i<n;i++)
{
temp[n-i-1][k]=SquareArray[k];
temp[n-i-1][n-k-1]=SquareArray[n-k-1];
}
// for(j=0;j<n;j++)
// {
// temp[n-k-1][j]=SquareArray[j][k];
// temp[k][j]=SquareArray[j][n-k-1];
// }
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
temp2[j]=SquareArray[j];
SquareArray[j]=temp[j];
}
if(!CanMove(curx,cury))
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
SquareArray[j]=temp2[j];
}
return false;
}
else
return true;
}
//---------------------初始化line[]全为false,表示全为非满;
void Screens::initline()
{
int i;
for(i=0;i<N;i++)
{
line=false;
}
}
//---------------把方块信息赋予screen中-------------------------------
void Screens::copyToScreen(int currentX,int currentY)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
[red] ScreenArray[i+currentX][j+currentY]=SquareArray[j]; [/red] }
}
//-----------------------检查screen中是否有行满---------------------------
bool Screens::IfLineFull(int currentX)
{
int i,j;
bool flag=false;
for(i=currentX;i<currentX+4;i++)
{
line=true;
for(j=0;j<M;j++)
{
if(ScreenArray[j]==0)
{
line=false;
continue;
}
}
if(line==true)
{
flag=true;
}
}
return flag;
}
//------------------------------消去screen中的满行-----------------------
void Screens::deteLine(int currentX)
{
int i,j,k;
count=0;
for(i=currentX;line==true&&i<currentX+4;i++)
{
for(k=i;k>=0;
k--)
{
for(j=0;j<M;j++)
{
ScreenArray[k][j]=ScreenArray[k-1][j];
}
}
count++;
}
}
//---------------------------在屏幕上画方块--------------------------------
void Screens:aint(TCanvas *Canvas )
{
int i,j;
Canvas->Pen->Color=clCream;//clSilver;
Canvas->Brush->Color=clCream;//clSilver;
Canvas->Rectangle(5,5,M*15+5,N*15+5);
for(i=0;i<N;i++)
for(j=0;j<M;j++)
{
if(ScreenArray[j]==1)
{
Canvas->Brush->Color=clGreen;// sqColor;
Canvas->Pen->Color=clGreen;// sqColor;
Canvas->Rectangle(5+j*15,5+i*15,5+(j+1)*15,5+(i+1)*15);
}
}
}
//---------------------------得到删除的行数值--------------------------------
int Screens::getcount()
{
return count;
}
void Screens::setcount()
{
count=0;
}
//---------------------------得到删除的行数值并计算分数--------------------------------