package com.tyj.onepiece;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class CtrlView extends GameView {
public final int GAMETIME = 300;
public final int UPTIME = 1;
public int PROCESS_VALUE = 300;
public static boolean CURRENT_CH = false;
public int CURRENT_TYPE = 0;
private Point C_POINT;
private Point P_POINT;
LinkedList<Line> li;
public CtrlView(Context context, AttributeSet attrs) {
super(context, attrs);
initType();
initGrid();
much = (row - 2) * (col - 2);
}
public CtrlView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initType();
initGrid();
much = (row - 2) * (col - 2);
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN)
return super.onTouchEvent(event);
int selX = (int) (event.getX() / width);
int selY = (int) (event.getY() / height);
if (grid[selX][selY] == 0)
return true;
else {
if (CURRENT_CH == false) {
select(selX, selY);
CURRENT_CH = true;
P_POINT = new Point(selX, selY);
} else {
C_POINT = new Point(selX, selY);
lineType = 0;
if (checkLink(P_POINT, C_POINT)) {
isLine = true;
much = much - 2;
if (0 < PROCESS_VALUE
&& (PROCESS_VALUE + UPTIME) < GAMETIME) {
PROCESS_VALUE = PROCESS_VALUE + UPTIME;
}
invalidate();
mRedrawHandler.sleep(300);
}
CURRENT_CH = false;
}
}
return true;
}
public void reset() {
CURRENT_CH = false;
CURRENT_TYPE = 0;
C_POINT = null;
P_POINT = null;
lineType = 0;
isLine = false;
Point[] p = null;
initType();
initGrid();
much = (row - 2) * (col - 2);
invalidate();
}
public void rearrange() {
CURRENT_CH = false;
CURRENT_TYPE = 0;
C_POINT = null;
P_POINT = null;
lineType = 0;
isLine = false;
Point[] p = null;
List<Integer> temp = new ArrayList<Integer>();
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (grid[i][j] != 0) {
temp.add(grid[i][j]);
}
}
}
type.clear();
Random ad = new Random();
for (int i = 0; i < temp.size(); i++) {
type.add(temp.get(i));
}
temp.clear();
temp = null;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (grid[i][j] != 0) {
int index = ad.nextInt(type.size());
grid[i][j] = type.get(index);
type.remove(index);
}
}
}
invalidate();
}
private RefreshHandler mRedrawHandler = new RefreshHandler();
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
isLine = false;
grid[P_POINT.x][P_POINT.y] = 0;
grid[C_POINT.x][C_POINT.y] = 0;
CtrlView.this.invalidate();
}
public void sleep(long delayMillis) {
this.removeMessages(0);// 移除信息队列中最顶部的信息(从顶部取出信息)
sendMessageDelayed(obtainMessage(0), delayMillis);// 获得顶部信息并延时发送
}
};
public class Point {
public int x;
public int y;
public Point(int newx, int newy) {
this.x = newx;
this.y = newy;
}
public boolean equals(Point p) {
if (p.x == x && p.y == y)
return true;
else
return false;
}
}
private boolean horizon(Point a, Point b) {
if (a.x == b.x && a.y == b.y)
return false;
int x_start = a.y <= b.y ? a.y : b.y;
int x_end = a.y <= b.y ? b.y : a.y;
for (int x = x_start + 1; x < x_end; x++)
if (grid[a.x][x] != 0) {
return false;
}
p = new Point[] { a, b };
lineType = H_LINE;
return true;
}
private boolean vertical(Point a, Point b) {
if (a.x == b.x && a.y == b.y)
return false;
int y_start = a.x <= b.x ? a.x : b.x;
int y_end = a.x <= b.x ? b.x : a.x;
for (int y = y_start + 1; y < y_end; y++)
if (grid[y][a.y] != 0)
return false;
p = new Point[] { a, b };
lineType = V_LINE;
return true;
}
private boolean oneCorner(Point a, Point b) {
Point c = new Point(a.x, b.y);
Point d = new Point(b.x, a.y);
if (grid[c.x][c.y] == 0) {
boolean method1 = horizon(a, c) && vertical(b, c);
p = new Point[] { a, new Point(c.x, c.y), b };
lineType = ONE_C_LINE;
return method1;
}
if (grid[d.x][d.y] == 0) {
boolean method2 = vertical(a, d) && horizon(b, d);
p = new Point[] { a, new Point(d.x, d.y), b };
lineType = ONE_C_LINE;
return method2;
} else {
return false;
}
}
class Line {
public Point a;
public Point b;
public int direct;
public Line() {
}
public Line(int direct, Point a, Point b) {
this.direct = direct;
this.a = a;
this.b = b;
}
}
private LinkedList<Line> scan(Point a, Point b) {
li = new LinkedList<Line>();
for (int y = a.y; y >= 0; y--)
if (grid[a.x][y] == 0 && grid[b.x][y] == 0
&& vertical(new Point(a.x, y), new Point(b.x, y)))
li.add(new Line(0, new Point(a.x, y), new Point(b.x, y)));
for (int y = a.y; y < row; y++)
if (grid[a.x][y] == 0 && grid[b.x][y] == 0
&& vertical(new Point(a.x, y), new Point(b.x, y)))
li.add(new Line(0, new Point(a.x, y), new Point(b.x, y)));
for (int x = a.x; x >= 0; x--)
if (grid[x][a.y] == 0 && grid[x][b.y] == 0
&& horizon(new Point(x, a.y), new Point(x, b.y)))
li.add(new Line(1, new Point(x, a.y), new Point(x, b.y)));
for (int x = a.x; x < col; x++)
if (grid[x][a.y] == 0 && grid[x][b.y] == 0
&& horizon(new Point(x, a.y), new Point(x, b.y)))
li.add(new Line(1, new Point(x, a.y), new Point(x, b.y)));
return li;
}
private boolean twoCorner(Point a, Point b) {
li = scan(a, b);
if (li.isEmpty())
return false;
for (int index = 0; index < li.size(); index++) {
Line line = (Line) li.get(index);
if (line.direct == 1) {
if (vertical(a, line.a) && vertical(b, line.b)) {
p = new Point[] { a, line.a, line.b, b };
lineType = TWO_C_LINE;
return true;
}
} else if (horizon(a, line.a) && horizon(b, line.b)) {
p = new Point[] { a, line.a, line.b, b };
lineType = TWO_C_LINE;
return true;
}
}
return false;
}
public boolean checkLink(Point a, Point b) {
if (grid[a.x][a.y] != grid[b.x][b.y])// 如果图案不同,直接为false
return false;
if (a.x == b.x && horizon(a, b))
return true;
if (a.y == b.y && vertical(a, b))
return true;
if (oneCorner(a, b))
return true;
else
return twoCorner(a, b);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android应用源码之简单的海贼王连连看源码.zip项目安卓应用源码下载
共52个文件
class:18个
png:17个
xml:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 82 浏览量
2022-03-08
16:15:43
上传
评论
收藏 1.28MB ZIP 举报
温馨提示
Android应用源码之简单的海贼王连连看源码.zip项目安卓应用源码下载Android应用源码之简单的海贼王连连看源码.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码之简单的海贼王连连看源码.zip (52个子文件)
Android应用源码之简单的海贼王连连看源码
Android应用源码之简单的海贼王连连看源码
海贼王连连看示例图片1.jpg 48KB
海贼王连连看示例图片2.jpg 48KB
OnePieceGame
.project 848B
default.properties 364B
bin
OnePieceGame.apk 339KB
com
tyj
onepiece
OnePieceGame$1.class 1023B
R$string.class 681B
R$layout.class 388B
OnePieceGame$2.class 887B
R$drawable.class 810B
OnePieceGame.class 5KB
R.class 563B
OnePieceGame$3.class 884B
OnePieceGame$4.class 954B
CtrlView$RefreshHandler.class 1KB
R$color.class 642B
CtrlView.class 7KB
R$attr.class 334B
OnePieceGame$RefreshHandler.class 1KB
CtrlView$Point.class 743B
GameView.class 7KB
CtrlView$Line.class 853B
R$id.class 439B
resources.ap_ 327KB
classes.dex 20KB
AndroidManifest.xml 681B
src
com
tyj
onepiece
OnePieceGame.java 5KB
CtrlView.java 7KB
GameView.java 6KB
res
values
color.xml 421B
strings.xml 670B
layout
main.xml 1KB
drawable
kk.png 22KB
dd.png 23KB
hh.png 20KB
nn.png 20KB
oo.png 20KB
ll.png 23KB
cc.png 23KB
pp.png 21KB
aa.png 15KB
ii.png 21KB
ff.png 23KB
Thumbs.db 217KB
ee.png 21KB
bb.png 17KB
mm.png 21KB
icon.png 25KB
jj.png 21KB
gg.png 23KB
.classpath 280B
gen
com
tyj
onepiece
R.java 2KB
共 52 条
- 1
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功