前序:
正文:
先看游戏运行后是啥玩意请看图:
一句话概括就是两类一接口,没错,这就能实现五子棋的游戏了。老规矩请看截图:
核心代码:
privateBitmapCreatMatrixBitmap(intresourcesID, floatscr_width, floatres_height)
{
Bitmap bitMap =null;
bitMap = BitmapFactory.decodeResource(sResources,resourcesID);
intbitWidth = bitMap.getWidth();
intbitHeight = bitMap.getHeight();
floatscaleWidth = scr_width / (float) bitWidth;
floatscaleHeight = res_height / (float) bitHeight;
Matrix matrix =newMatrix();
matrix.postScale(scaleWidth,scaleHeight);
bitMap = Bitmap.createBitmap(bitMap,0,0,bitWidth,bitHeight,matrix, true);
returnbitMap;
}
private voidUpdateTouchEvent(intx, inty)
{
switch(mGameState)
{
caseGS_GAME:
if(x >0&& y >mTitleHeight)
{
mMapIndexX= (int) (x /mTitleSpace);
mMapIndexY= (int) ((y -mTitleHeight) /mTitleSpace);
if(mMapIndexX>mMapWidthLengh)
{
mMapIndexX=mMapWidthLengh;
}
if(mMapIndexX<0)
{
mMapIndexX=0;
}
if(mMapIndexY>mMapHeightLengh)
{
mMapIndexY=mMapHeightLengh;
}
if(mMapIndexY<0)
{
mMapIndexY=0;
}
if(mGameMap[mMapIndexY][mMapIndexX] ==CAMP_DEFAULT)
{
if(mCampTurn==CAMP_HERO)
{
mGameMap[mMapIndexY][mMapIndexX] =CAMP_HERO;
if(CheckPiecesMeet(CAMP_HERO))
{
mCampWinner= R.string.Role_black;
setGameState(GS_END);
}
else
{
mCampTurn=CAMP_ENEMY;
}
}
else
{
mGameMap[mMapIndexY][mMapIndexX] =CAMP_ENEMY;
if(CheckPiecesMeet(CAMP_ENEMY))
{
mCampWinner= R.string.Role_white;
setGameState(GS_END);
}else
{
mCampTurn=CAMP_HERO;
}
}
}
}
break;
caseGS_END:
setGameState(GS_GAME);
break;
}
}
分享经验:
反馈:
欢迎万能网友互相分享交流!
QQ: 2632545852 微信:xuchen2100