亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為何下完白棋再下黑棋時黑棋會把白棋覆蓋的?

aaaaaa

正在回答

3 回答

private void drawPieces(Canvas canvas) {

for(int i=0,n=mWhiteArray.size();i<n;i++)

{

Point whitePoint = mWhiteArray.get(i);

canvas.drawBitmap(mWhitePiece,

(whitePoint.x+(1-ratioPieceOfLineHeight)/2)*mLineHeight,

(whitePoint.y+(1-ratioPieceOfLineHeight)/2)*mLineHeight,null);

}

for(int i=0,n=mBlackArray.size();i<n;i++)

{

Point blackPoint = mWhiteArray.get(i);????????//這里應該是?Point blackPoint = mBlackArray.get(i);?????

canvas.drawBitmap(mBlackPiece,????????????????

(blackPoint.x+(1-ratioPieceOfLineHeight)/2)*mLineHeight,

(blackPoint.y+(1-ratioPieceOfLineHeight)/2)*mLineHeight,null);

}

}


0 回復 有任何疑惑可以回復我~

大神們幫忙看看哪里錯了?


0 回復 有任何疑惑可以回復我~

package com.example.wuziqipanel;


import java.util.ArrayList;

import java.util.List;


import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.Point;

import android.util.AttributeSet;

import android.view.MotionEvent;

import android.view.View;


public class WuziqiPanel extends View {


private int mPanelWidth;

private float mLineHeight;

private int MAX_LINE=10;

private Paint mPaint = new Paint();

private Bitmap mWhitePiece;

private Bitmap mBlackPiece;

private float ratioPieceOfLineHeight = 3*1.0f/4;

//白棋先手,當前輪到白棋

private boolean mIsWhite = true;

private List<Point> mWhiteArray = new ArrayList<Point>();

private List<Point> mBlackArray = new ArrayList<Point>();

private boolean mIsGameOver;

private boolean mIsWhiteWinner;

public WuziqiPanel(Context context, AttributeSet attrs) {

super(context, attrs);

setBackgroundColor(0x44ff0000);

init();

}


private void init() {

// TODO Auto-generated method stub

mPaint.setColor(0x88000000);

mPaint.setAntiAlias(true);

mPaint.setDither(true);

mPaint.setStyle(Paint.Style.STROKE);

mWhitePiece = BitmapFactory.decodeResource(getResources(), R.drawable.stone_w2);

mBlackPiece = BitmapFactory.decodeResource(getResources(), R.drawable.stone_b1);

}


@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int widthSize =MeasureSpec.getSize(widthMeasureSpec);

int widthMode =MeasureSpec.getSize(widthMeasureSpec);

int heidthSize =MeasureSpec.getSize(heightMeasureSpec);

int heidthMode =MeasureSpec.getSize(heightMeasureSpec);

int width = Math.min(widthSize,heidthSize);

if(widthMode == MeasureSpec.UNSPECIFIED)

{

width = heidthSize;

}else if(heidthMode == MeasureSpec.UNSPECIFIED)

{

width = widthSize;

}

setMeasuredDimension(width, width);

}

@Override

protected void onSizeChanged(int w, int h, int oldw, int oldh) {

// TODO Auto-generated method stub

super.onSizeChanged(w, h, oldw, oldh);

mPanelWidth = w;

mLineHeight = mPanelWidth *1.0f/MAX_LINE;

int pieceWidth=(int) (mLineHeight*ratioPieceOfLineHeight);

mWhitePiece = Bitmap.createScaledBitmap(mWhitePiece, pieceWidth, pieceWidth, false);

mBlackPiece = Bitmap.createScaledBitmap(mBlackPiece, pieceWidth, pieceWidth, false);

}

@Override

public boolean onTouchEvent(MotionEvent event) {

int action=event.getAction();

if(action==MotionEvent.ACTION_UP)

{

int x = (int) event.getX();

int y = (int) event.getY();

Point p = getValidPoint(x,y);

if(mWhiteArray.contains(p) || ?mBlackArray.contains(p))

{

return false;

}

if(mIsWhite){

mWhiteArray.add(p);

}else

{

mBlackArray.add(p);

}

invalidate();

mIsWhite = !mIsWhite;

}

return true;

}

private Point getValidPoint(int x, int y) {



return new Point((int)(x / mLineHeight),(int)(y / mLineHeight));

}


@Override

protected void onDraw(Canvas canvas) {

// TODO Auto-generated method stub

super.onDraw(canvas);

drawBoard(canvas);

drawPieces(canvas);

}


private void drawPieces(Canvas canvas) {

for(int i=0,n=mWhiteArray.size();i<n;i++)

{

Point whitePoint = mWhiteArray.get(i);

canvas.drawBitmap(mWhitePiece,

(whitePoint.x+(1-ratioPieceOfLineHeight)/2)*mLineHeight,

(whitePoint.y+(1-ratioPieceOfLineHeight)/2)*mLineHeight,null);

}

for(int i=0,n=mBlackArray.size();i<n;i++)

{

Point blackPoint = mWhiteArray.get(i);

canvas.drawBitmap(mBlackPiece,

(blackPoint.x+(1-ratioPieceOfLineHeight)/2)*mLineHeight,

(blackPoint.y+(1-ratioPieceOfLineHeight)/2)*mLineHeight,null);

}

}


private void drawBoard(Canvas canvas) {

// TODO Auto-generated method stub

int w = mPanelWidth;

float lineHeight = mLineHeight;

for(int i =0 ; i<MAX_LINE ; i++){

int startX = (int) (lineHeight/2);

int endX = (int) (w-lineHeight/2);

int y =(int) ((0.5+i)*lineHeight);

canvas.drawLine(startX, y, endX, y, mPaint);

canvas.drawLine(y, startX, y, endX, mPaint);

}

}

}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android-五子連珠
  • 參與學習       38999    人
  • 解答問題       174    個

Android游戲開發-五子連珠,本教程通過UI與邏輯實現雙人對戰

進入課程

為何下完白棋再下黑棋時黑棋會把白棋覆蓋的?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號