资源描述
. .
安卓课程设计报告
设计题目:五子棋
目录
一.需求分析3
二.功能模块3
三. 界面设计4
四. 分工说明6
五. 所遇到的问题6
六.代码注释7
一.需求分析
网络技术的日新月异让世界惊叹,高速开展的网络技术和日渐成熟的3G网络,让越来越多的用户沉浸在手机的世界而无限欢快。不管是逛街、乘地铁,还是吃饭,排队,跟随潮流的时尚一群都利用拇指掌控着周围的一切,似乎只有手机才能让他们真正体验娱乐的极致。手机已然成为本世纪最有作为、最受欢送的创造。而手机的流行更成就了相关应用和,让他们在移动互联网大放异彩的当下备受用户关注。
二.功能模块
主界面
游戏开场界面
开场游戏
认输
推出
三.界面设计
3.1开场界面
3.2游戏界面
3.3点击认输界面
四. 分工说明
X哲:编辑main代码
X凯:获取 MainAct
丁章华:写报告
黄思淳:程序注释
叶浩:编辑MyView代码
五. 所遇到的问题
1 登录界面的局部功能没有实现。
2 界面的布局没有很清晰。
3 局部代码不够简洁。
六.代码注释
public MyView(Context context,float width,float height) {
super(context);
// TODO Auto-generated constructor stub
this.width=(float) (width);
this.height=(float) (height);
flag=true;
holder=this.getHolder();
this.setFocusable(true);
holder.addCallback(this);
bitmap=BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.chess_2));
chess=new int[9][9];
msg="点击开场";
}
public void myDraw()
{
//获得画布
Canvas canvas=holder.lockCanvas();
//获得画笔
Paint paint=new Paint();
//绘画
paint.setAntiAlias(true);
Matrix matrix=new Matrix();
int ww = bitmap.getWidth();//获取资源位图的宽
int hh = bitmap.getHeight();//获取资源位图的高
float w = (width/(float)ww);
float h = (float) ((height/(float)hh)/1.1);
matrix.postScale(w, h);//获取缩放比例
Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, ww, hh, matrix, true);//根据缩放比例获取新的位图
canvas.drawBitmap(bmp, 0, 0, paint); //在屏幕上画出位图
int sx=(int) width;
int sy=(int) (height/1.1);
paint.setColor(Color.BLACK);
//适应屏幕画横线竖线
tempy=(float) ((0.6*sy-(0.6*sy)%8-16)/8);
ax=(sx-tempy*8)/2;
ay=(float) (((0.6*sy)%8)/2)+8;
bx=sx-(sx-tempy*8)/2;
cy=(float) (0.6*sy-((0.6*sy)%8)/2-8);
// System.out.println("MyView:==========="+tempy);
for(int i=0;i<9;i++)
{
canvas.drawLine(ax, ay+tempy*i, bx, ay+tempy*i, paint);
canvas.drawLine(ax+tempy*i, ay, ax+tempy*i, cy, paint);
}
//画棋盘下方现实信息
paint.setColor(Color.BLACK);
paint.setTextSize(30);
// float tx=3*sx/8;
// float ty=(float) (0.75*sy);
canvas.drawText(msg, 3*sx/8-25, (float) (0.72*sy), paint);
canvas.drawText("开场", (float) (0.175*sx), (float) (0.92*sy), paint);
canvas.drawText("认输", (float) (0.425*sx), (float) (0.92*sy), paint);
canvas.drawText("退出", (float) (0.675*sx), (float) (0.92*sy), paint);
//画棋子
int qx,qy;
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
//画黑棋
if(chess[i][j]==1)
{
qx=(int) (ax+i*tempy);
qy=(int) (ay+j*tempy);
paint.setColor(Color.BLACK);
canvas.drawCircle(qx, qy, tempy/3, paint);
}
//画白棋
else if(chess[i][j]==2)
{
qx=(int) (ax+i*tempy);
qy=(int) (ay+j*tempy);
paint.setColor(Color.WHITE);
canvas.drawCircle(qx, qy, tempy/3, paint);
}
}
}
if(canvas!=null)
{
holder.unlockCanvasAndPost(canvas);
}
}
Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
super.onTouchEvent(event);
x=(int) event.getX();
y=(int) event.getY();
float xx=event.getX();
float yy=event.getY();
System.out.println("点击的坐标:"+xx+":"+yy);
int sx=(int) width;
int sy=(int) (height/1.1);
//点击开场
if(x>=0.125*sx&&x<=0.375*sx&&y>=0.86*sy&&y<=0.98*sy)
{
game_start=true;
msg="黑方落子";
myDraw();
}
//点击认输
if(x>0.375*sx&&x<=0.625*sx&&y>=0.86*sy&&y<=0.98*sy)
{
game_start=false;
if(isBlack)
msg="黑方认输";
else if(!isBlack)
msg="白方认输";
myDraw();
}
//点击退出
if(x>0.625*sx&&x<=0.875*sx&&y>=0.86*sy&&y<=0.98*sy)
{
System.exit(0);
}
else if(game_start)
{
if(x>=ax&&y>=ay&&(x<=bx+tempy)&&y<=(cy+tempy))
{
x=(int) ((x-ax)/tempy);
y=(int) ((y-ay)/tempy);
System.out.println("变换成下标后xy的值:"+x+":"+y);
if(chess[x][y]==0)
{
//黑方下棋
if(isBlack)
{
chess[x][y]=1;
isBlack=false;
msg="白方落子";
}
//白方下棋
else
{
chess[x][y]=2;
isBlack=true;
msg="黑方落子";
}
boolean isWin=checkWin(x,y);
if(isWin)
{
if(isBlack==false)
{
msg="黑方获胜";
game_start=false;
}
else if(isBlack==true)
{
msg="白方获胜";
game_start=false;
}
}
}
myDraw();
}
}
return true;
}
. .word..
展开阅读全文