android 水果老虎机 文档一

运用andrid最基础的sufaceView制作小时候的最爱,水果老虎机过程文档

先来张初始效果图,图片全部来在网络扣图,那个累呀.........

 

整个图型的画法,和转灯的画法

 

// 自定义画法
	private void drawView() {
		try {
			if (sh != null) {
				iCanvas = sh.lockCanvas();// 获取画布
				// 设置画笔和位图没有锯齿
				iCanvas.setDrawFilter(new PaintFlagsDrawFilter(0,
						Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
				// 背景bg
				iCanvas.drawBitmap(bitmap_bg, null, new RectF(0, 0,
						screenWidth, screenHeight), null);
				// 得分条-win
				iCanvas.drawBitmap(bitmap_score_win, null, new RectF(margin, 0,
						margin + checkWidth * 3, checkWidth), null);
				iCanvas.drawText("" + winOddsScore,
						margin + checkWidth * 3 - 5, checkWidth - checkWidth
								/ 7, iPaint_score);
				// 现在分数条-credit
				iCanvas.drawBitmap(bitmap_score_credit, null, new RectF(margin
						+ checkWidth * 4, 0, margin + checkWidth * 7,
						checkWidth), null);
				iCanvas.drawText("" + creditNum, margin + checkWidth * 7 - 5,
						checkWidth - checkWidth / 7, iPaint_score);

				//画top正方型
				for (int i = 0; i < 7; i++) {
					RectF rectTop = new RectF(margin + i * checkWidth,
							checkWidth, margin + checkWidth + i * checkWidth,
							checkWidth + checkWidth);
					iCanvas.drawBitmap(Content.getTopBitmaps()[i], null,
							rectTop, null);
				}

				// 画right正方型
				for (int i = 1; i < 6; i++) {
					RectF rectRight = new RectF(margin + checkWidth * 6, i
							* checkWidth + checkWidth, margin + checkWidth * 7,
							checkWidth + i * checkWidth + checkWidth);
					iCanvas.drawBitmap(Content.getRightBitmaps()[i - 1], null,
							rectRight, null);
				}

				// 画bottom正方型
				for (int i = 0; i < 7; i++) {
					RectF rectBottom = new RectF(margin + i * checkWidth,
							checkWidth * 6 + checkWidth, margin + checkWidth
									+ i * checkWidth, checkWidth * 7
									+ checkWidth);
					iCanvas.drawBitmap(Content.getBottomBitmaps()[i], null,
							rectBottom, null);
				}
				// 画left正方型
				for (int i = 1; i < 6; i++) {
					RectF rectLeft = new RectF(margin, i * checkWidth
							+ checkWidth, margin + checkWidth, checkWidth + i
							* checkWidth + checkWidth);
					iCanvas.drawBitmap(Content.getLeftBitmaps()[i - 1], null,
							rectLeft, null);
				}
				// 移动的发光图标
				if (isOk) {
					if (num < randomNum) {// 每次刷屏num+1;当比随机出来的转数小时,继续转,当大于等于时就停止
						if (num < (randomNum / 13)) {// 控件转灯的速度,由慢-快-慢
							sleepNum = 300;
						} else if (num < (randomNum * 2 / 13)) {
							sleepNum = 200;
						} else if (num < (randomNum * 3 / 13)) {
							sleepNum = 100;
						} else if (num < (randomNum * 4 / 13)) {
							sleepNum = 80;
						} else if (num < (randomNum * 5 / 13)) {
							sleepNum = 50;
						} else if (num < (randomNum * 6 / 13)) {
							sleepNum = 20;
						} else if (num < (randomNum * 7 / 13)) {
							sleepNum = 10;
						} else if (num < (randomNum * 8 / 13)) {
							sleepNum = 20;
						} else if (num < (randomNum * 9 / 13)) {
							sleepNum = 50;
						} else if (num < (randomNum * 10 / 13)) {
							sleepNum = 80;
						} else if (num < (randomNum * 11 / 13)) {
							sleepNum = 100;
						} else if (num < (randomNum * 12 / 13)) {
							sleepNum = 200;
						} else {
							sleepNum = 300;
						}
						if (num % 1 == 0) {
							if (num < randomNum - 1) {//最后一下声响(啪)的一声
								soundPool.play(dingSound, 1, 1, 1, 0, 1);
							} else if (isPaSound) {
								soundPool.play(paSound, 1, 1, 1, 0, 1);
								isPaSound = false;
							}
							if (countTop < 7) {
								rectSelect = new RectF(margin + countTop
										* checkWidth, checkWidth, margin
										+ checkWidth + countTop * checkWidth,
										checkWidth + checkWidth);
								iCanvas.drawBitmap(bitmap_sifangkuang, null,
										rectSelect, null);
								countTop++;
							} else if (countTop >= 7 && countRight < 6) {
								rectSelect = new RectF(margin + 6 * checkWidth,
										countRight * checkWidth + checkWidth,
										margin + checkWidth * 7, checkWidth
												+ countRight * checkWidth
												+ checkWidth);
								iCanvas.drawBitmap(bitmap_sifangkuang, null,
										rectSelect, null);
								countRight++;
							} else if (countRight >= 6 && countBottom >= 0) {
								rectSelect = new RectF(margin + countBottom
										* checkWidth, checkWidth * 6
										+ checkWidth, margin + checkWidth
										+ countBottom * checkWidth, checkWidth
										* 7 + checkWidth);
								iCanvas.drawBitmap(bitmap_sifangkuang, null,
										rectSelect, null);
								countBottom--;
							} else if (countBottom < 0 && countLeft > 0) {
								rectSelect = new RectF(margin, checkWidth
										* countLeft + checkWidth, margin
										+ checkWidth, checkWidth * countLeft
										+ checkWidth + checkWidth);
								iCanvas.drawBitmap(bitmap_sifangkuang, null,
										rectSelect, null);
								countLeft--;
							}
							if (countLeft == 0) {// 循环一圈,以左上角0,0为始点
								countTop = 0;
								countRight = 1;
								countLeft = 5;
								countBottom = 6;
							}
						}
						num++;//通过自加,接近随机出来的转运数值
					} else {
						//最后停的一下
						iCanvas.drawBitmap(bitmap_sifangkuang, null,
								rectSelect, null);
						float x = rectSelect.left;
						float y = rectSelect.top;
						// 赔率
						// intBar+intSeven+intStar+intXG+intLD+intMG+intOrange+intApple
						if (isScore) {
							//自定义方法,获取中奖分数
							winOddsScore = Content.getWinOdds(intBar, intSeven,
									intStar, intXG, intLD, intMG, intOrange,
									intApple, margin, checkWidth, x, y);
						}
						//System.out.println("中奖分数=" + winOddsScore);
						if (isStart) {// 按了go开始进入
							if (winOddsScore == 0) {//没中奖,清0
								cleanAllNum();
							}
						}
						isStart = false;
						sleepNum = 100;//运气run的sleep时间

					}
				}

				RectF rectBottom_1 = new RectF(margin, checkWidth * 7
						+ checkWidth, screenWidth - margin, checkWidth * 8
						+ checkWidth);
				iCanvas.drawBitmap(bitmap_bottom_1, null, rectBottom_1, null);

				RectF rectBottom_2 = new RectF(margin, checkWidth * 8
						+ checkWidth, screenWidth - margin, checkWidth * 8
						+ checkWidth / 2 + checkWidth);
				// iCanvas.drawBitmap(bitmap_bottom_2, null, rectBottom_2,
				// null);

				RectF rectBottom_3 = new RectF(margin, checkWidth * 9
						+ checkWidth / 2, screenWidth - margin, checkWidth * 11);
				iCanvas.drawBitmap(bitmap_bottom_3, null, rectBottom_3, null);

				iCanvas.drawText(stringBar, margin + chipNumWidth / 4,
						checkWidth * 8 + checkWidth * 2 / 5 + checkWidth,
						iPaint);
				iCanvas.drawText(stringSeven, margin + chipNumWidth
						+ chipNumWidth / 5, checkWidth * 8 + checkWidth * 2 / 5
						+ checkWidth, iPaint);
				iCanvas.drawText(stringStar, margin + chipNumWidth * 2
						+ chipNumWidth / 5, checkWidth * 8 + checkWidth * 2 / 5
						+ checkWidth, iPaint);
				iCanvas.drawText(stringXG, margin + chipNumWidth * 3
						+ chipNumWidth / 6, checkWidth * 8 + checkWidth * 2 / 5
						+ checkWidth, iPaint);
				iCanvas.drawText(stringLD, margin + chipNumWidth * 4
						+ chipNumWidth / 6, checkWidth * 8 + checkWidth * 2 / 5
						+ checkWidth, iPaint);
				iCanvas.drawText(stringMG, margin + chipNumWidth * 5
						+ chipNumWidth / 6, checkWidth * 8 + checkWidth * 2 / 5
						+ checkWidth, iPaint);
				iCanvas.drawText(stringOrange, margin + chipNumWidth * 6
						+ chipNumWidth / 7, checkWidth * 8 + checkWidth * 2 / 5
						+ checkWidth, iPaint);
				iCanvas.drawText(stringApple, margin + chipNumWidth * 7,
						checkWidth * 8 + checkWidth * 2 / 5 + checkWidth,
						iPaint);

			}
		} catch (Exception e) {
		} finally {
			if (iCanvas != null) {
				sh.unlockCanvasAndPost(iCanvas);// 解锁画布并提交
			}
		}

	}


 

自定义获取中奖分数的方法

//传进来中奖的坐标,返回中奖的赔率和中奖的水果
	public static int getWinOdds(int intBar,int intSeven,int intStar,int intXG,int intLD,int intMG,int intOrange,int intApple,float margin,float checkWidth,float x,float y){
//		System.out.println("intBar="+intBar);
//		System.out.println("intSeven="+intSeven);
		int winOdds[] = new int[2];
		int winOddsScroe = 0;
		
		if(y==checkWidth){//top
			switch ((int)((x-margin)/checkWidth)) {
			case 0:
				winOdds[0] = 10;
				winOdds[1] = 1;
				break;
			case 1:
				winOdds[0] = 20;
				winOdds[1] = 3;
				break;
			case 2:
				winOdds[0] = 25;
				winOdds[1] = 7;
				break;
			case 3:
				winOdds[0] = 50;
				winOdds[1] = 7;
				break;
			case 4:
				winOdds[0] = 5;
				winOdds[1] = 0;
				break;
			case 5:
				winOdds[0] = 2;
				winOdds[1] = 0;
				break;
			case 6:
				winOdds[0] = 15;
				winOdds[1] = 2;
				break;

			default:
				break;
			}
		}
		if((x-margin)/6==checkWidth){
			switch ((int)(y/checkWidth)) {
			case 2:
				winOdds[0] = 20;
				winOdds[1] = 4;
				break;
			case 3:
				winOdds[0] = 2;
				winOdds[1] = 4;
				break;
			case 4:
				winOdds[0] = -1;
				winOdds[1] = -1;
				break;
			case 5:
				winOdds[0] = 5;
				winOdds[1] = 0;
				break;
			case 6:
				winOdds[0] = 2;
				winOdds[1] = 1;
				break;

			default:
				break;
			}
		}
		if(y==checkWidth*7){
			switch ((int)((x-margin)/checkWidth)) {
			case 0:
				winOdds[0] = 15;
				winOdds[1] = 2;
				break;
			case 1:
				winOdds[0] = 2;
				winOdds[1] = 2;
				break;
			case 2:
				winOdds[0] = 5;
				winOdds[1] = 0;
				break;
			case 3:
				winOdds[0] = 40;
				winOdds[1] = 6;
				break;
			case 4:
				winOdds[0] = 2;
				winOdds[1] = 6;
				break;
			case 5:
				winOdds[0] = 20;
				winOdds[1] = 3;
				break;
			case 6:
				winOdds[0] = 10;
				winOdds[1] = 1;
				break;

			default:
				break;
			}
		}
		if(x==margin){
			switch ((int)(y/checkWidth)) {
			case 2:
				winOdds[0] = 2;
				winOdds[1] = 3;
				break;
			case 3:
				winOdds[0] = 5;
				winOdds[1] = 0;
				break;
			case 4:
				winOdds[0] = -2;
				winOdds[1] = -2;
				break;
			case 5:
				winOdds[0] = 2;
				winOdds[1] = 5;
				break;
			case 6:
				winOdds[0] = 30;
				winOdds[1] = 5;
				break;

			default:
				break;
			}
		}
		//intBar+intSeven+intStar+intXG+intLD+intMG+intOrange+intApple
		switch (winOdds[1]) {
		case 0:
			winOddsScroe = intApple * winOdds[0];
			break;
		case 1:
			winOddsScroe = intOrange * winOdds[0];
			break;
		case 2:
			winOddsScroe = intMG * winOdds[0];
			break;
		case 3:
			winOddsScroe = intLD * winOdds[0];
			break;
		case 4:
			winOddsScroe = intXG * winOdds[0];
			break;
		case 5:
			winOddsScroe = intStar * winOdds[0];
			break;
		case 6:
			winOddsScroe = intSeven * winOdds[0];
			break;
		case 7:
			winOddsScroe = intBar * winOdds[0];
			break;

		default:
			break;
		}
		
		return winOddsScroe;
		
	}


 

暂时做到这,实现了压注,开始游戏,中奖获取分数,暂时不能重复上次的压注,每运行一次,都会把压注和得分清0

还没有做赌大小等功能

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值