/*
软件作者:https://xuhss.com/oxox/pro
*/
"ui";
/**
*作者QQ: 1811588980
*完成时间: 2019年4月13日 下午3:36:12
*测试机型: vivo PD1813D
*Auto.js版本: 4.1.0 Alpha5
*Android版本: 8.1.0
*屏幕: 1080*2280
*API: 27
*备注: 暂无备注
**/
ui.layout(
<vertical>
<canvas id="canvas" layout_weight="1"/>
</vertical>
);
//黑色画笔。
var paint = new Paint;
//paint.setTextAlign(Paint.Align.CENTER);
paint.setStrokeWidth(2);
//paint.setStyle(Paint.Style.STROKE);
paint.setStyle(Paint.Style.FILL);
paint.setARGB(255, 0, 0, 0);
//paint.setColor(colors.GRAY);
paint.setTextSize(75);
//写字用的红色画笔。
var paint1 = new Paint;
paint1.setTextAlign(Paint.Align.CENTER);
paint1.setStrokeWidth(5);
paint1.setStyle(Paint.Style.STROKE);
//paint1.setStyle(Paint.Style.FILL);
paint1.setARGB(255, 255, 0, 0);
paint1.setTextSize(75);
var mMatrix = new android.graphics.Matrix;
var ASX = new XYToMatrix(null, 3);
var gameWidth = 31,
gameHeight = 41,
blackEdge = 10;
var g_w = gameWidth,
g_h = gameHeight,
b_e = blackEdge;
var gameRect = new android.graphics.Rect(0, 0, g_w, g_h);
if (g_w < 3 || g_h < 3) {
throw "太小无法形成游戏";
};
var mBitmap = android.graphics.Bitmap.createBitmap(g_w * b_e, g_h * b_e, android.graphics.Bitmap.Config.ARGB_8888);
var mCanvas = new android.graphics.Canvas(mBitmap);
mCanvas.drawARGB(255, 127, 127, 127)
var gameAry = new Array(g_w * g_h);
var start;
var end;
var player;
var isLoading = true;
newGame();
function newGame() {
for (let iy = 0; iy < g_h; iy++) {
for (let ix = 0; ix < g_w; ix++) {
if (ix % 2 && iy % 2) {
gameAry[g_w * iy + ix] = 0;
} else {
gameAry[g_w * iy + ix] = 1;
};
};
};
//迷宫入口。
var start1 = {
x: 0,
y: random(0, (Math.floor(g_h / 2) - 1)) * 2 + 1
}; //左
//迷宫出口。
var start2 = {
x: random(0, (Math.floor(g_w / 2) - 1)) * 2 + 1,
y: g_h - 1
}; //下
start = start2;
//迷宫出口。
var end1 = {
x: g_w - 1,
y: random(0, (Math.floor(g_h / 2) - 1)) * 2 + 1
}; //右
//迷宫入口。
var end2 = {
x: random(0, (Math.floor(g_w / 2) - 1)) * 2 + 1,
y: 0
}; //上
end = end2;
gameAry[g_w * start.y + start.x] = 0;
gameAry[g_w * end.y + end.x] = 0;
player = {
x: start.x,
y: start.y,
paint: (function() {
let paint = new Paint;
//paint.setTextAlign(Paint.Align.CENTER);
//paint.setStrokeWidth(2);
//paint.setStyle(Paint.Style.STROKE);
paint.setStyle(Paint.Style.FILL);
paint.setARGB(255, 255, 0, 0);
//paint.setColor(colors.GRAY);
//paint.setTextSize(75);
return paint;
})(),
};
var ST = { //左下
x: start.x ? start.x : start.x + 1,
y: start.y == g_h - 1 ? g_h - 2 : start.y
};
var EN = { //右上
x: end.x == g_w - 1 ? g_w - 2 : end.x,
y: end.y ? end.y : end.y + 1
};
threads.start(function() {
paint.setStrokeWidth(2);
//paint.setStyle(Paint.Style.STROKE);
paint.setStyle(Paint.Style.FILL);
paint.setARGB(255, 0, 0, 0);
for (let iy = 0; iy < g_h; iy++) {
for (let ix = 0; ix < g_w; ix++) {
if (gameAry[g_w * iy + ix] > 0) {
mCanvas.drawRect(ix * b_e, iy * b_e, (ix + 1) * b_e, (iy + 1) * b_e, paint); //左
};
};
};
paint.setARGB(255, 0, 255, 0);
mCanvas.drawRect(start.x * b_e, start.y * b_e, (start.x + 1) * b_e, (start.y + 1) * b_e, paint); //左
mCanvas.drawRect(end.x * b_e, end.y * b_e, (end.x + 1) * b_e, (end.y + 1) * b_e, paint); //左
paint.setARGB(255, 127, 127, 127);
DFS(ST);
isLoading = false;
toastLog("新迷宫生成完成");
});
};
var canvasRect = new android.graphics.RectF;
var canvasMatrix = new android.graphics.Matrix;
ui.canvas.post(function() {
let v = ui.canvas;
//var rect=new android.graphics.Rect;
//ui.canvas.getBoundsOnScreen(canvasRect,false);
let w = v.getWidth(),
h = v.getHeight();
canvasRect.set(new android.graphics.RectF(0, 0, w, h));
canvasMatrix.setRectToRect(new android.graphics.RectF(-b_e, -b_e, mBitmap.getWidth() + b_e, mBitmap.getHeight()), new android.graphics.RectF(canvasRect), android.graphics.Matrix.ScaleToFit.START);
});
//ui.canvas.setOnTouchListener(ASX.touchListener);
var Xw, Yh, TX, TY, isTouch = false;
var direction = {
x: 0,
y: 0
};
ui.canvas.on("draw", function(canvas) {
var w = canvas.getWidth();
var h = canvas.getHeight();
canvas.drawARGB(255, 127, 127, 127)
let matrix = new android.graphics.Matrix;
matrix.setConcat(ASX.matrix, canvasMatrix);
//canvasMatrix.postConcat(ASX.matrix);
canvas.setMatrix(matrix);
canvas.drawBitmap(mBitmap, 0, 0, paint);
canvas.drawCircle(player.x * b_e + b_e / 2, player.y * b_e + b_e / 2, b_e*0.7, player.paint);
canvas.setMatrix(mMatrix);
if (isTouch) {
canvas.drawCircle(Xw, Yh, 25, paint1);
canvas.drawLine(Xw, Yh, TX, TY, paint1);
canvas.drawCircle(TX, TY, 100, paint1);
};
//canvas.drawText(Math.floor(ASX.getScaling() * 100) / 100, w / 2, h / 2, paint1);
//canvas.drawPath(path, paint1);
//canvas.drawCircle(x,y,5, paint2);
});
ui.canvas.setOnTouchListener(function(view, event) {
switch (event.getAction()) {
case event.ACTION_DOWN:
Xw = event.getX();
Yh = event.getY();
break;
case event.ACTION_MOVE:
TX = event.getX();
TY = event.getY();
// if (weiyi([event.getX() - Xw, event.getY() - Yh]) >= 25) {
isTouch = true;
if (Math.abs(event.getX() - Xw) <= Math.abs(event.getY() - Yh)) {
if (event.getY() - Yh > 0) {
direction.x = 0;
direction.y = 1;
} else {
direction.x = 0;
direction.y = -1;
};
} else {
if (event.getX() - Xw > 0) {
direction.x = 1;
direction.y = 0;
} else {
direction.x = -1;
direction.y = 0;
};
};
Xw = event.getX();
Yh = event.getY();
// } else {
// isTouch = false;
// };
break;
case event.ACTION_UP:
isTouch = false;
direction.x = 0;
direction.y = 0;
};
return true;
});
setInterval(() => {
if (isTouch) {
let x = player.x + direction.x,
y = player.y + direction.y;
if (gameAry[g_w * y + x] <= 0) {
player.x = x;
player.y = y;
};
};
if (player.x == end.x && player.y == end.y) {
isLoading = true;
newGame();
};
}, 50);
/*
1.将起点作为当前迷宫单元并标记为已访问
2.当还存在未标记的迷宫单元,进行循环
1.如果当前迷宫单元有未被访问过的的相邻的迷宫单元
1.随机选择一个未访问的相邻迷宫单元
2.将当前迷宫单元入栈
3.移除当前迷宫单元与相邻迷宫单元的墙
4.标记相邻迷宫单元并用它作为当前迷宫单元
2.如果当前迷宫单元不存在未访问的相邻迷宫单元,并且栈不空
1.栈顶的迷宫单元出栈
2.�
[虚幻私塾】
- 粉丝: 335
- 资源: 1558
最新资源
- Ashampoo WinOptimizer v27.00.05 阿香婆一款专业的垃圾清理、碎片整理启动项管理系统优化工具.rar
- misc设备驱动 正点原子阿尔法
- youleng-wms JAVA开发的WMS源码可以借签学习 数据库MYSQL
- 385大神asp.net三层设计停车场管理系统毕业课程源码设计+参考论文
- 数据集,训练数据集,深度学习
- 384大神asp.net基于三层汽车进销存销售管理系统毕业课程源码设计
- AutoSAR基础学习资源
- 383大神asp.net软件测试用例库管理系统毕业课程源码设计
- Open-Industry-Project-main C#
- C0858 手机之家(1页).Zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈