基于Android的五子棋的开发,供大家参考,具体内容如下
<强>需求分析强>
1棋盘和棋子绘制
2按照五子棋的规则制定游戏胜负规则,
3鼠标响应在对战中需要通过鼠标点击下棋进行游戏的基本操作
4日游戏模式双人对战两人交替落子双方孰先孰后随机决定
5棋子的形式和作用棋子分为黑白两种棋子双方各持一种棋子通过黑先白后的方式来进行对局
6通过棋子完成五连珠结束游戏
<>强流程图强>
<强> android stdio中的基本架构强>
CheckWinner.java
包com.example.wuziqi; 进口android.graphics.Point; 进口并不知道;/* * *由Linux> 包com.example.wuziqi; 进口android.content.Context; 进口android.graphics.Bitmap; 进口android.graphics.BitmapFactory; 进口android.graphics.Canvas; 进口android.graphics.Paint; 进口android.graphics.Point; 进口android.media.MediaPlayer; 进口android.os.Bundle; 进口android.os.Parcelable; 进口android.util.AttributeSet; 进口android.view.MotionEvent; 进口android.view.View; 进口android.widget.Toast; 进口java.util.ArrayList; 公开课ChessBoardView扩展视图{//棋盘的宽度,也是长度 私人int mViewWidth;//棋盘每格的长度 私人maxLineHeight浮动; 私人涂漆=new ();//定义黑白棋子的位图 私人位图mwhitePiece mblackPiece; 私人浮动ratioPieceOfLineHeight=3 * 1.0 f/4;//判断当前落下的棋子是否是白色的 私人布尔mIsWhite=true;//记录黑白棋子位置的列的表 私人ArrayList,mwhiteArray=new ArrayList<的在(); 私人ArrayList ,mblackArray=new ArrayList<的在();//游戏是否结束 私人布尔mIsGameOver;//游戏结束,是否是白色方胜利 私人布尔mIsWhiteWinner; 公共ChessBoardView(上下文语境,AttributeSet attrs) { 超级(上下文,attrs); init (); } 私人空间init () { paint.setColor (0 x88000000); paint.setAntiAlias(真正的); paint.setDither(真正的); paint.setStyle (Paint.Style.STROKE); mwhitePiece=BitmapFactory.decodeResource (getresource (), R.mipmap.stone_w2); mblackPiece=BitmapFactory.decodeResource (getresource (), R.mipmap.stone_b1); } @Override 保护空白> 包com.example.wuziqi;/* * *由Linux> 包com.example.wuziqi; 进口android.content.Intent; 进口android.os.Bundle; 进口android.view.Menu; 进口android.view.MenuItem; 进口android.view.View; 进口androidx.appcompat.app.AppCompatActivity; 公开课MainActivity延伸AppCompatActivity { 私人ChessBoardView ChessBoardView; @Override 保护空白> 包com.example.wuziqi; 进口android.app.Service; 进口android.content.Intent; 进口android.media.MediaPlayer; 进口android.os.IBinder; 进口android.util.Log; 公开课MusicServer延伸服务{ 私人媒体播放器议员; 公共内部> & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;清单xmlns: android=" http://schemas.android.com/apk/res/android " 包=癱om.example.wuziqi”比; & lt;应用程序 android: allowBackup=" true " android:图标=" @mipmap/ic_launcher” android: label=" @string/app_name” android: supportsRtl=" true " android:主题=癅style/AppTheme”比; & lt;活动android: name=?MainActivity”比; & lt; intent-filter> & lt;行动android: name=" android.intent.action.MAIN "/比; & lt;类别android: name=" android.intent.category.LAUNCHER "/比; & lt;/intent-filter> & lt;/activity> & lt;服务 android: name=" .MusicServer " android:启用=" true " android:出口=" true "祝辞& lt;/service> & lt;/application> & lt;/manifest>
activity_main.xml
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:工具=" http://schemas.android.com/tools " android: layout_width=" match_parent " android: layout_height=" match_parent " android:背景=" @mipmap/bg1” 工具:上下文=癱om.example.wuziqi.MainActivity”比; & lt; com.example.wuziqi.ChessBoardView android: id=癅 + id/boardView” android: layout_centerInParent=" true " android: layout_width=" match_parent " android: layout_height=" match_parent "/比; & lt;按钮 android: id=癅 + id/button1” android: layout_width=" wrap_content " android: layout_height=" wrap_content " android: layout_below=癅 + id/textView” android: layout_centerHorizontal=" true " android: layout_marginTop=" 16 dp " android: onClick=" doClick " android:文本="开启音乐”/比; & lt;按钮 android: id=癅 + id/button2” android: layout_width=" wrap_content " android: layout_height=" wrap_content " android: layout_below=癅 + id/button1” android: layout_alignStart=癅 + id/button1” android: layout_marginStart=" 94 dp” android: layout_marginTop=" -48 dp” android: onClick=" doClick " android:文本="停止音乐”/比; & lt;/RelativeLayout>基于android实现五子棋开发