package com.xiangqi;
import com.xiangqi.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.media.MediaPlayer;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class Game extends SurfaceView implements SurfaceHolder.Callback{
private TutorialThread thread;//刷帧线程
shijianThread timeThread ;
XIActivity activity;
Bitmap qiPan;//棋盘
Bitmap qibei;//棋子背景图
Bitmap win;//胜利图
Bitmap bai;//失败图
Bitmap ok;//确定按钮
Bitmap sheng;//黑方红方sheng的图
Bitmap right;//向右指针
Bitmap left;//向左指针
Bitmap current;//“当前”文字
Bitmap exit2;//退出图
Bitmap sound2;//声音图
Bitmap sound3;//是否播放声音
Bitmap time;//冒号
Bitmap redtime;//红冒号
Bitmap background;//背景图
MediaPlayer go;//下棋声
Paint paint;//画笔
boolean caiPan = true;//玩家走棋?
boolean de = false;//是否选中棋子
int selectqizi = 0; //现在选中的棋子
int startI, startJ;//当前棋子开始位置
int endI, endJ;//当前棋子目标位置
Bitmap[] heiZi = new Bitmap[7];//黑子图片数组
Bitmap[] hongZi = new Bitmap[7];//红子图片数组
Bitmap[] number = new Bitmap[10];//数字图片数组显示时间
Bitmap[] redNumber = new Bitmap[10];//红数字图片显示时间
GuiZe guiZe;//规则类
int status = 0;//戏状态,0游戏中,1胜利, 2失败
int heiTime = 0;//黑方思考时间
int hongTime = 0;//红方共思考时间
int[][] qizi = new int[][]{//棋盘
{2,3,6,5,1,5,6,3,2},
{0,0,0,0,0,0,0,0,0},
{0,4,0,0,0,0,0,4,0},
{7,0,7,0,7,0,7,0,7},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{14,0,14,0,14,0,14,0,14},
{0,11,0,0,0,0,0,11,0},
{0,0,0,0,0,0,0,0,0},
{9,10,13,12,8,12,13,10,9},
};
public Game(Context context,XIActivity activity) {//构造器
super(context);
this.activity = activity;//得到Activity的引用
getHolder().addCallback(this);
go = MediaPlayer.create(this.getContext(), R.raw.go);//下棋声音
this.thread = new TutorialThread(getHolder(), this);//刷帧线程初始化
this.timeThread = new shijianThread(this);//初始化思考时间的线程
init();//资源初始化
guiZe = new GuiZe();//规则类初始化
}
public void init(){//初始化
paint = new Paint();//画笔初始化
qiPan = BitmapFactory.decodeResource(getResources(), R.drawable.qipan);//棋盘图
qibei = BitmapFactory.decodeResource(getResources(), R.drawable.qizi);//棋子背景
win = BitmapFactory.decodeResource(getResources(), R.drawable.win);//胜利图
bai = BitmapFactory.decodeResource(getResources(), R.drawable.bai);//失败图
ok = BitmapFactory.decodeResource(getResources(), R.drawable.ok);//确定按钮图
sheng = BitmapFactory.decodeResource(getResources(), R.drawable.sheng);//胜利图
right = BitmapFactory.decodeResource(getResources(), R.drawable.right);//向右指针
left = BitmapFactory.decodeResource(getResources(), R.drawable.left);//向左指针
current = BitmapFactory.decodeResource(getResources(), R.drawable.current);
exit2 = BitmapFactory.decodeResource(getResources(), R.drawable.exit2);//退出图
sound2 = BitmapFactory.decodeResource(getResources(), R.drawable.sound2);//声音图
time = BitmapFactory.decodeResource(getResources(), R.drawable.time);//黑冒号
redtime = BitmapFactory.decodeResource(getResources(), R.drawable.redtime);//红冒号
sound3 = BitmapFactory.decodeResource(getResources(), R.drawable.sound3);
heiZi[0] = BitmapFactory.decodeResource(getResources(), R.drawable.heishuai);//黑帅
heiZi[1] = BitmapFactory.decodeResource(getResources(), R.drawable.heiju);//黑车
heiZi[2] = BitmapFactory.decodeResource(getResources(), R.drawable.heima);//黑马
heiZi[3] = BitmapFactory.decodeResource(getResources(), R.drawable.heipao);//黑炮
heiZi[4] = BitmapFactory.decodeResource(getResources(), R.drawable.heishi);//黑士
heiZi[5] = BitmapFactory.decodeResource(getResources(), R.drawable.heixiang);//黑象
heiZi[6] = BitmapFactory.decodeResource(getResources(), R.drawable.heibing);//黑兵
hongZi[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hongjiang);//红将
hongZi[1] = BitmapFactory.decodeResource(getResources(), R.drawable.hongju);//红车
hongZi[2] = BitmapFactory.decodeResource(getResources(), R.drawable.hongma);//红马
hongZi[3] = BitmapFactory.decodeResource(getResources(), R.drawable.hongpao);//红砲
hongZi[4] = BitmapFactory.decodeResource(getResources(), R.drawable.hongshi);//红仕
hongZi[5] = BitmapFactory.decodeResource(getResources(), R.drawable.hongxiang);//红相
hongZi[6] = BitmapFactory.decodeResource(getResources(), R.drawable.hongzu);//红卒
number[0] = BitmapFactory.decodeResource(getResources(), R.drawable.number0);//黑色数字0
number[1] = BitmapFactory.decodeResource(getResources(), R.drawable.number1);//黑色数字1
number[2] = BitmapFactory.decodeResource(getResources(), R.drawable.number2);//黑色数字2
number[3] = BitmapFactory.decodeResource(getResources(), R.drawable.number3);//黑色数字3
number[4] = BitmapFactory.decodeResource(getResources(), R.drawable.number4);//黑色数字4
number[5] = BitmapFactory.decodeResource(getResources(), R.drawable.number5);//黑色数字5
number[6] = BitmapFactory.decodeResource(getResources(), R.drawable.number6);//黑色数字6
number[7] = BitmapFactory.decodeResource(getResources(), R.drawable.number7);//黑色数字7
number[8] = BitmapFactory.decodeResource(getResources(), R.drawable.number8);//黑色数字8
number[9] = BitmapFactory.decodeResource(getResources(), R.drawable.number9);//黑色数字9
redNumber[0] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber0);//红色数字0
redNumber[1] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber1);//红色数字1
redNumber[2] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber2);//红色数字2
redNumber[3] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber3);//红色数字3
redNumber[4] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber4);//红色数字4
redNumber[5] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber5);//红色数字5
redNumber[6] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber6);//红色数字6
redNumber[7] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber7);//红色数字7
redNumber[8] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber8);//红色数字8
redNumber[9] = BitmapFactory.decodeResource(getResources(), R.drawable.rednumber9);//红色数字9
background = BitmapFactory.decodeResource(getResources(), R.drawable.bei);
}
public void onDraw(Canvas canvas){//根据数据绘制屏幕方法
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(background, 0,0, null);//清背景
canvas.drawBitmap(qiPan, 10, 10, null);//绘棋盘
for(int i=0; i<qizi.length; i++){
for(int j=0; j<qizi[i].length; j++){//绘棋子
if(qizi[i][j] != 0){
canvas.drawBitmap(qibei, 9+j*34, 10+i*35, null);//绘棋子背景
if(qizi[i][j] == 1){//黑帅时
canvas.drawBitmap(heiZi[0], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 2){//黑车时
canvas.drawBitmap(heiZi[1], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 3){//黑马时
canvas.drawBitmap(heiZi[2], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 4){//黑炮时
canvas.drawBitmap(heiZi[3], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 5){//黑士时
canvas.drawBitmap(heiZi[4], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 6){//黑象时
canvas.drawBitmap(heiZi[5], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 7){//黑兵时
canvas.drawBitmap(heiZi[6], 12+j*34, 13+i*35, paint);
}
else if(qizi[i][j] == 8){//为红将时
canvas.drawBitmap(hongZi[0], 12+j*34, 13+i*35, paint);
}
else if(qizi[i]
没有合适的资源?快使用搜索试试~ 我知道了~
中国象棋-Android源码
共111个文件
png:66个
class:20个
java:10个
需积分: 10 8 下载量 109 浏览量
2015-07-05
14:17:51
上传
评论 1
收藏 3.45MB 7Z 举报
温馨提示
中国象棋是一项智力和策略的游戏,以往都是人和人下棋,现在有了计算机我们可以和计算机竞技,人可以与计算机进行对弈。控制计算机的是人类,而人机会话综合性很强的一门边缘学科,它的中心任务是研究使计算机如何去做那些过去只能靠人的智力才能做的工作。因此,对游戏开发过程中的人工智能技术的研究自然也就成了业界的一个热门研究方向。
资源推荐
资源详情
资源评论
收起资源包目录
中国象棋-Android源码 (111个子文件)
resources.ap_ 1.49MB
xiangqi.apk 1.51MB
Game.class 10KB
GuiZe.class 6KB
huanying.class 4KB
caidan.class 4KB
Help.class 3KB
R$drawable.class 2KB
XIActivity.class 2KB
huanying$TutorialThread.class 2KB
caidan$TutorialThread.class 2KB
Help$TutorialThread.class 2KB
Game$TutorialThread.class 2KB
huanyingThread.class 1KB
shijianThread.class 898B
XIActivity$1.class 825B
Move.class 548B
R.class 484B
R$raw.class 426B
R$string.class 406B
R$layout.class 373B
R$attr.class 319B
.classpath 280B
Thumbs.db 472KB
Thumbs.db 7KB
Thumbs.db 4KB
classes.dex 27KB
Game.java 17KB
GuiZe.java 14KB
huanying.java 5KB
caidan.java 5KB
R.java 4KB
Help.java 3KB
XIActivity.java 2KB
huanyingThread.java 1KB
shijianThread.java 655B
Move.java 405B
yousheng.mp3 626KB
kaisheng.mp3 37KB
go.mp3 1KB
bei.png 279KB
helpbackground.png 129KB
huanying.png 129KB
biao2.png 50KB
qipan.png 32KB
boy.png 30KB
biao.png 26KB
bordbackground.png 26KB
oldboy.png 19KB
exit.png 19KB
kai.png 19KB
guan.png 18KB
da.png 18KB
help.png 17KB
win.png 8KB
bai.png 8KB
sheng.png 7KB
back.png 7KB
menu.png 7KB
ok.png 7KB
icon.png 4KB
exit2.png 3KB
sound2.png 3KB
icon.png 3KB
left.png 2KB
right.png 2KB
icon.png 2KB
qizi.png 1KB
sound3.png 1KB
current.png 714B
hongpao.png 493B
hongjiang.png 489B
heixiang.png 467B
heipao.png 466B
hongzu.png 425B
hongxiang.png 415B
hongma.png 409B
heishuai.png 408B
heima.png 402B
hongshi.png 388B
heibing.png 376B
hongju.png 372B
heiju.png 364B
rednumber6.png 285B
rednumber8.png 284B
rednumber9.png 284B
number8.png 280B
number9.png 278B
rednumber3.png 275B
rednumber2.png 273B
heishi.png 271B
number2.png 265B
number3.png 264B
rednumber0.png 264B
number6.png 263B
number0.png 257B
rednumber7.png 257B
rednumber5.png 256B
number5.png 245B
number7.png 244B
共 111 条
- 1
- 2
资源评论
管阁
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功