In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
小编给大家分享一下Android如何自定义View实现五子棋小游戏,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
具体内容如下
代码:
package com.example.fiveson;import java.util.LinkedList;import java.util.List;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;public class FiveSon extends View { public FiveSon(Context context) { super(context); // TODO Auto-generated constructor stub init(context, null); } public FiveSon(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub init(context, attrs); } public FiveSon(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // TODO Auto-generated constructor stub init(context, attrs); } private Paint paint = new Paint(); private Paint circlePaint = new Paint(); // 旗子: 信息 代表 第几行 第几列? private List chesses = new LinkedList(); private void init(Context context, AttributeSet attrs) { chesses.add(new int[]{3,5}); chesses.add(new int[]{3,6}); } int spacing = 100; @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); int width = getWidth(); int height = getHeight(); //1 绘制 X 坐标 int num = width / spacing; paint.setColor(Color.BLACK); for(int i=0;i0) { boolean has = false; for(int i = len-1;i>=0;i--) { int[] chs = chesses.get(i); if(rowNum == chs[0] && colNum == chs[1]) { has = true; break; } } if(!has) { chesses.add(new int[]{rowNum,colNum}); invalidate(); } }else { chesses.add(new int[]{rowNum,colNum}); invalidate(); } isComsumed = true; }else { isComsumed = super.onTouchEvent(event); } return super.onTouchEvent(event); }}以上是"Android如何自定义View实现五子棋小游戏"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.