关于麻将发牌

  终于可以继续进展 项目 了,今天做到发牌功能,有点绕,在这里叙述一下,顺便理理思绪。
背景:
1、三人麻将 左User(Name:A、Index:0), 我"猪脚"(Name:B、Index:1),右User(Name:C、Index:2) 、、、 突然想起深圳的猪脚饭 真香啊
2、骰子数(骰子数%3)为 庄  例子: 骰子数 9%3 == 0 ; Index = 0;  A庄      注:两个骰子
3、发牌一次为    4张、4 、4 、  二次为 4 、4 、4 、 三次为 4 、4 、4   四次为(A 庄) 2 、1 、1    总共发出40张牌到user
4、A、C都为其他User 所以看不到他们的牌也就好弄些,搞两张背面的背景图片,一个背右(A).一个背左(C),然后Draw画到位置,但是这个发牌的动作时要加点效果的,假如这次发往A 那就弄四张背右图 然后组合在一个Bitmap上从中间往A的位置发出,开始图为最小慢慢变大直到A点(PS:因为不是一次发完所以第一次发到A点为左上定点0,0点,但是第二次给A发的时候就不是0,0点了,要知道到上次发到哪里了,第几次,假如是最后一次还要判断是不是庄,因为你最后组合的这张图是庄的话是发两张 else 一张),这个效果有点蛋疼,先不说,C效仿A的方法发.
5、现在说另外一个蛋疼的问题就是给B发牌(猪脚),他大爷的,策划搞得,给B发牌要显示出来牌,也就是说这个时候你是知道你的牌的,所以说发的时候要先定义一个数组拿到你的牌的值 然后把值装变成Bitmap麻将然后从里面取出四张组合在一起然后从中间发到B的位置,第二次从上次发到数组的最后位置开始拿出牌拼成bitmap发出去,最后一次 一样也是要判断是否是庄然后看发一张还是两张.
6、假设A庄 
( 480*320)
 发牌为顺时针 
 注:ABC代表不同用户   、4代表4张牌 、width 牌的宽度   height 牌的高度      &20,20&  20为此bitmap的大小width height
那么:
第一轮     A4 (0.0)             & Awidth,4 *  Aheight &              
 ->   C4 (480-widthC,0)      &   Cwidth,4 *   Cheight &           
->    B4 (0,320- height B)         &   Bwidth,4 *B height &  
第二轮     A4 (0. heightA*4  ) &   Awidth,4 *   Aheight &     
  ->  C4 (480-widthC,heightC*4)   &   Cwidth,4 *   Cheight &     
->   B4 ( width B * 4  , 320- height B) &   Bwidth,4 *B height &  
第三轮      A4 (0. heightA*8 ) &   Awidth,4 *   Aheight &   
->   C4 (480-widthC, heightC*8)   &   Cwidth,4 *   Cheight &      
->    B4  (   width B * 8    ,320- height B)     &   Bwidth,4 *B height &  
第四轮     A2 (0.   heightA*12 ) &   Awidth,2 *   Aheight &    
-> C1 (480-widthC, heightC*12)     &   Cwidth *   Cheight &  
-> B1 (   width B  * 12    ,320- height B)   &   Bwidth,4 *B height &  
就是这个样子. 
问题写好了 但是要怎么实现呢 关于麻将发牌 - Nialclk - Nialclk
/**
* 发牌 给左边用户发牌
* @param c 
* @param index  左 0 右 1 中间 2
*/
private void onFaPai(Canvas c,int index)
{
int indexCount[] = new int[3];   // 左 0  右 1 中间 2
for(int i = 0; i < 4 ; i ++)
{
FaPaiLeft(c,indexCount[0]++,  index == 0 ? true : false);
FaPaiRight(c,indexCount[1]++, index == 1 ? true : false);
FaPaiCenter(c,indexCount[2]++,index == 2 ? true : false);
}
}
private void FaPaiLeft(Canvas c,int count,boolean zhuang)
{
Canvas canvasTemp = null;          
Bitmap BTTemp = null;
Bitmap leftBM = mBitmapFactory.getFaPaiLeft();//左边的麻将
int leftSize[] = mBitmapFactory.getBitmapSize(leftBM);
Matrix leftMatrix =new Matrix();
if(count == 0)
leftMatrix.postTranslate(-30, 0);
else if(count == 3)
{
leftMatrix.postTranslate(-30, leftSize[1] * 12 - 12 * 30);
}else
{
leftMatrix.postTranslate(-30, leftSize[1] * count * 4 - count * 4 * 30 );
}
BTTemp = Bitmap.createBitmap(leftSize[0],(zhuang ? (count == 3 ? 2 : 4  ) : (count == 3 ? 1 : 4  ) ) *leftSize[1], Bitmap.Config.ARGB_8888);  
canvasTemp = new Canvas(BTTemp);
for(int i = 0; i < (zhuang ? (count == 3 ? 2 : 4  ) : (count == 3 ? 1 : 4  ) ); i++)
canvasTemp.drawBitmap(leftBM, 0,(leftSize[1] - 30 ) * i, null);
c.drawBitmap(BTTemp, leftMatrix, null);
BTTemp = null;
canvasTemp = null;
}
private void FaPaiCenter(Canvas c,int count,boolean zhuang)
{
short [][] AllMj = mViewMJ.Fapai(); // 0 左      1 中间      2 右
Canvas canvasTemp = null;          
Bitmap BTTemp = null;
Bitmap MyBM[] = mBitmapFactory.getMyMj(AllMj[1]); //获得属于我的麻将   中间的麻将
int mySize[] = mBitmapFactory.getBitmapSize(MyBM[0]);
Matrix MyMatrix =new Matrix();
int jigemajiang = (zhuang ? (count == 3 ? 2 : 4  ) : (count == 3 ? 1 : 4  ) ) ; //麻将的个数
//中间的麻将
BTTemp = Bitmap.createBitmap(jigemajiang * mySize[0],mySize[1], Bitmap.Config.ARGB_8888);  //创建一个4个麻将大小的空白的bitmap
canvasTemp = new Canvas(BTTemp);
int index = 0;
int geshu = 0;
if(count == 0)
{
MyMatrix.postTranslate(0,  mHeight - mySize[1]);
}
else if(count == 3)
{
MyMatrix.postTranslate(mySize[0] * 12,  mHeight - mySize[1]);
index = 12;
geshu = zhuang ?  14 : 13;
}else
{
MyMatrix.postTranslate(mySize[0] * count * 4,  mHeight - mySize[1]);
index = count * 4;
geshu = index + 4;
}
for( int i = 0; index< geshu ; index++)
canvasTemp.drawBitmap(MyBM[index], mySize[0] * i++, 0, null);
c.drawBitmap(BTTemp, MyMatrix, null);
BTTemp = null;
canvasTemp = null;
}
private void FaPaiRight(Canvas c,int count,boolean zhuang)
{
Canvas canvasTemp = null;          
Bitmap BTTemp = null;
Bitmap rightBM = mBitmapFactory.getFaPaiRight();//右边的麻将
int rightSize[] = mBitmapFactory.getBitmapSize(rightBM);
Matrix rightMatrix =new Matrix();
if(count == 0)
rightMatrix.postTranslate(mWidth - rightSize[0] + 32, 0);
else if(count == 3)
{
rightMatrix.postTranslate(mWidth - rightSize[0] + 32, rightSize[1] * 12 - 12 * 30);
}else
{
rightMatrix.postTranslate(mWidth - rightSize[0] + 32, rightSize[1] * count * 4 - count * 4 * 30);
}
BTTemp = Bitmap.createBitmap(rightSize[0],(zhuang ? (count == 3 ? 2 : 4  ) : (count == 3 ? 1 : 4  ) ) * rightSize[1], Bitmap.Config.ARGB_8888);  
canvasTemp = new Canvas(BTTemp);
for(int i = 0; i < (zhuang ? (count == 3 ? 2 : 4  ) : (count == 3 ? 1 : 4  ) ); i++)
canvasTemp.drawBitmap(rightBM, 0,(rightSize[1] - 30) * i, null);
c.drawBitmap(BTTemp, rightMatrix, null);
BTTemp = null;
canvasTemp = null;
}
一早上的时间 搞定了...但是少一个功能 就是动画的效果 今天一定要搞定噢
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值