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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
小程序源码 简单的海贼王连连看源码.rar
共52个文件
class:18个
png:17个
xml:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 106 浏览量
2023-03-20
07:07:43
上传
评论
收藏 1.22MB RAR 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序源码 简单的海贼王连连看源码.rar (52个子文件)
海贼王连连看示例图片1.jpg 48KB
OnePieceGame
.classpath 280B
assets
src
com
tyj
onepiece
CtrlView.java 7KB
OnePieceGame.java 5KB
GameView.java 6KB
res
values
strings.xml 670B
color.xml 421B
layout
main.xml 1KB
drawable
aa.png 15KB
oo.png 20KB
Thumbs.db 217KB
bb.png 17KB
ff.png 23KB
hh.png 20KB
ii.png 21KB
ll.png 23KB
nn.png 20KB
mm.png 21KB
gg.png 23KB
dd.png 23KB
kk.png 22KB
cc.png 23KB
pp.png 21KB
jj.png 21KB
icon.png 25KB
ee.png 21KB
bin
resources.ap_ 327KB
OnePieceGame.apk 339KB
classes.dex 20KB
com
tyj
onepiece
OnePieceGame$3.class 884B
OnePieceGame.class 5KB
CtrlView$Line.class 853B
CtrlView$Point.class 743B
CtrlView$RefreshHandler.class 1KB
R$string.class 681B
CtrlView.class 7KB
OnePieceGame$4.class 954B
R$layout.class 388B
OnePieceGame$2.class 887B
R$id.class 439B
GameView.class 7KB
R$attr.class 334B
OnePieceGame$1.class 1023B
R$color.class 642B
R$drawable.class 810B
OnePieceGame$RefreshHandler.class 1KB
R.class 563B
default.properties 364B
.project 848B
AndroidManifest.xml 681B
gen
com
tyj
onepiece
R.java 2KB
海贼王连连看示例图片2.jpg 48KB
共 52 条
- 1
资源评论
荣华富贵8
- 粉丝: 124
- 资源: 7649
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功