10 JYMZHIDUO

尚未进行身份认证

我要认证

暂无相关简介

等级
TA的下载次数 53

软件设计师考试真题(2004-2011)

2004-2011年软件设计师考试真题以及答案

2012-05-22

用vc++编写的俄罗斯方块游戏

int CIBrick::shiftLeft (CBin*bin) { unsigned int posX; posX=getPosX(); posX=posX-1; setPosX(posX); if(checkCollision(bin)==0) { setPosX(posX+1); return 0; } return 1; } int CIBrick::shiftDown (CBin*bin) { unsigned int posY; posY=getPosY(); posY=posY+1; setPosY(posY); if (checkCollision(bin)==0) { setPosY(posY-1); return 0; } return 1; } int CIBrick::shiftRight (CBin*bin) { unsigned int posX; posX =getPosX(); posX=posX+1; setPosX(posX); if(checkCollision(bin)==0) { setPosX(posX-1); return 0; } return 1; } int CIBrick::rotateClockwise(CBin*bin) { unsigned int orientation,oldOrientation; orientation=getOrientation(); oldOrientation=orientation; if (orientation==3) orientation=0; else orientation=orientation+1; setOrientation(orientation); if(checkCollision(bin)==0) { setOrientation(oldOrientation); return 0; } return 1; } int CIBrick::checkCollision(CBin*bin) { unsigned int width; unsigned int height; unsigned char**image; unsigned int orientation; unsigned int posX; unsigned int posY; width=bin->getWidth(); height=bin->getHeight(); image=new unsigned char* [height]; for(unsigned int i=0;i<height;i++) { image[i]=new unsigned char[width]; } bin->getImage(image); orientation=getOrientation(); posX=getPosX(); posY=getPosY(); if (orientation==0) { if((posX+1<1)||(posX>width-1)||(posY<1)||(posY+2>height-1)) return 0; if((image[posY-1][posX]!=0)||(image[posY][posX]!=0)||(image[posY+1][posX]!=0)||(image[posY+2][posX]!=0)) return 0; } if(orientation==1) { if ((posX<2)||(posX+1>width-1)||(posY+1)<1||(posY>height-1)) return 0; if ((image[posY][posX-2]!=0)||(image[posY][posX-1]!=0)||(image[posY][posX]!=0)||(image[posY][posX+1]!=0)) return 0; } if (orientation==2) { if((posX+1<1)||(posX>width-1)||(posY<2)||(posY+1>height-1)) return 0; if ((image[posY-2][posX]!=0)||(image[posY-1][posX]!=0)||(image[posY][posX]!=0)||(image[posY+1][posX]!=0)) return 0; } if (orientation==3) { if ((posX<1)||(posX+2>width-1)||(posY+1<1)||(posY>height-1)) return 0; if ((image[posY][posX-1]!=0)||(image[posY][posX]!=0)||(image[posY][posX+1]!=0)||(image[posY][posX+2]!=0)) return 0; } return 1; } void CIBrick::operator>>(unsigned char** binImage) { unsigned int orientation ; unsigned int posX; unsigned int posY; unsigned char colour; posX=getPosX(); posY=getPosY(); orientation=getOrientation(); colour=getColour(); if(orientation==0) { binImage[posY-1][posX]=colour; binImage[posY][posX]=colour; binImage[posY+1][posX]=colour; binImage[posY+2][posX]=colour; } if(orientation==1) { binImage[posY][posX-2]=colour; binImage[posY][posX-1]=colour; binImage[posY][posX]=colour; binImage[posY][posX+1]=colour; } if (orientation==2) { binImage[posY-2][posX]=colour; binImage[posY-1][posX]=colour; binImage[posY][posX]=colour; binImage[posY+1][posX]=colour; } if (orientation==3) { binImage[posY][posX-1]=colour; binImage[posY][posX]=colour; binImage[posY][posX+1]=colour; binImage[posY][posX+2]=colour; } } void CIBrick::putAtTop(unsigned int newOrient,unsigned int newPosX) { setPosX(newPosX); setOrientation(newOrient); switch (newOrient) { case 0: setPosY(1);break; case 1: setPosY(0);break; case 2: setPosY(2);break; case 3: setPosY(0);break; } } int CLBrick::shiftLeft (CBin*bin) { unsigned int posX; posX=getPosX(); posX=posX-1; setPosX(posX);

2011-04-13
勋章 我的勋章
    暂无奖章