Commit 1f3b15f3 authored by unknown's avatar unknown

数字谜图主题逻辑好了

parent ebe5c962
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "060f8d06-56ea-423b-a9dc-56f72cbd2d95",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "8ef618b5-8762-4ba5-8d01-8d0588823f98",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "fc011fdb-3450-4798-b156-71ed9c079579",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "fc011fdb-3450-4798-b156-71ed9c079579@6c48a",
"displayName": "名称框",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0,
"isUuid": true,
"imageUuidOrDatabaseUri": "fc011fdb-3450-4798-b156-71ed9c079579"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "fc011fdb-3450-4798-b156-71ed9c079579@f9941",
"displayName": "名称框",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 262,
"height": 69,
"rawWidth": 262,
"rawHeight": 69,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"isUuid": true,
"imageUuidOrDatabaseUri": "fc011fdb-3450-4798-b156-71ed9c079579@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "fc011fdb-3450-4798-b156-71ed9c079579@f9941"
}
}
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "209c0aae-9fc7-4b2f-af41-ccf192271c27",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "209c0aae-9fc7-4b2f-af41-ccf192271c27@6c48a",
"displayName": "图标-选择",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0,
"isUuid": true,
"imageUuidOrDatabaseUri": "209c0aae-9fc7-4b2f-af41-ccf192271c27"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "209c0aae-9fc7-4b2f-af41-ccf192271c27@f9941",
"displayName": "图标-选择",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 54,
"height": 54,
"rawWidth": 54,
"rawHeight": 54,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"isUuid": true,
"imageUuidOrDatabaseUri": "209c0aae-9fc7-4b2f-af41-ccf192271c27@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "209c0aae-9fc7-4b2f-af41-ccf192271c27@f9941"
}
}
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "383d0a0c-60e1-4148-812a-5998bf1c2670",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "383d0a0c-60e1-4148-812a-5998bf1c2670@6c48a",
"displayName": "图标-锁定",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0,
"isUuid": true,
"imageUuidOrDatabaseUri": "383d0a0c-60e1-4148-812a-5998bf1c2670"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "383d0a0c-60e1-4148-812a-5998bf1c2670@f9941",
"displayName": "图标-锁定",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 47,
"height": 50,
"rawWidth": 47,
"rawHeight": 50,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"isUuid": true,
"imageUuidOrDatabaseUri": "383d0a0c-60e1-4148-812a-5998bf1c2670@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "383d0a0c-60e1-4148-812a-5998bf1c2670@f9941"
}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "11868b2b-d491-40ab-91e2-b6f9a4e23bca",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.1.27",
"importer": "prefab",
"imported": true,
"uuid": "2dda252c-2189-467f-a6ca-6aebe2047062",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "DMF_Head"
}
}
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false
},
{
"__type__": "cc.Node",
"_name": "DMF_Item",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 6
},
{
"__id__": 12
}
],
"_active": true,
"_components": [
{
"__id__": 18
},
{
"__id__": 20
}
],
"_prefab": {
"__id__": 22
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "clickNode",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
}
],
"_prefab": {
"__id__": 5
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 4
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "83b0lRIlVPB5G5QCzWQgvO"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "d9wiuk92NKSr/FYywsFBUW"
},
{
"__type__": "cc.Node",
"_name": "bgSpr",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 7
},
{
"__id__": 9
}
],
"_prefab": {
"__id__": 11
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 6
},
"_enabled": true,
"__prefab": {
"__id__": 8
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "55pCbtzR5GbojKMArZkfim"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 6
},
"_enabled": true,
"__prefab": {
"__id__": 10
},
"_visFlags": 0,
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 197,
"g": 176,
"b": 161,
"a": 255
},
"_spriteFrame": {
"__uuid__": "7d8f9b89-4fd1-4c9f-a3ab-38ec7cded7ca@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "20UGQn4U9GUoln0NJQTkbG"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "a97Y6tPChFTL8Wc/4QEZlk"
},
{
"__type__": "cc.Node",
"_name": "banSpr",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 13
},
{
"__id__": 15
}
],
"_prefab": {
"__id__": 17
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.3826834323650898,
"w": 0.9238795325112867
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -45
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 12
},
"_enabled": true,
"__prefab": {
"__id__": 14
},
"_contentSize": {
"__type__": "cc.Size",
"width": 80,
"height": 15
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "55pCbtzR5GbojKMArZkfim"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 12
},
"_enabled": true,
"__prefab": {
"__id__": 16
},
"_visFlags": 0,
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 0,
"b": 0,
"a": 255
},
"_spriteFrame": {
"__uuid__": "7d8f9b89-4fd1-4c9f-a3ab-38ec7cded7ca@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "20UGQn4U9GUoln0NJQTkbG"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "77x4GgcE9Bh6ac9qAh3oQ4"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 19
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "e7brYNQnxN9JtRM/bybI74"
},
{
"__type__": "d389bn+Fd9P2pggEvDk34wr",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 21
},
"bgSpr": {
"__id__": 9
},
"banSpr": {
"__id__": 15
},
"clickNode": {
"__id__": 2
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "14RnzEzL1IMq1A3qlvi33z"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "f3/g+6dJRFbJPuqVJvaUZj"
}
]
\ No newline at end of file
{
"ver": "1.1.27",
"importer": "prefab",
"imported": true,
"uuid": "85b7f0cd-2d4a-4d0d-b996-3441064f19dd",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "DMF_Item"
}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "bce4af6b-2907-4d56-b6cc-385765913122",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.1.27",
"importer": "scene",
"imported": true,
"uuid": "1fed1ae5-e2f4-473e-8d5d-96d866a62bf2",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "6e049a5a-8c10-4fd2-9e35-2e7e924c76de",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
export interface DmfLevelIfo {
scale: number,
row: number,
column: number,
rowHeadArr: number[][],
columnHeadArr: number[][]
}
export const DMF_LV_1: DmfLevelIfo = {
scale: 0.8,
row: 5,
column: 5,
rowHeadArr: [[4], [2, 2], [1, 1], [2, 1], [3, 1]],
columnHeadArr: [[1, 2], [2, 2], [1, 1, 1], [2, 1], [3, 1]]
}
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "dd99f3fd-3fa5-4b88-9997-d0f484725202",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Node, Vec3, v3, Prefab, UITransform, instantiate, director } from 'cc';
import { DmfLevelIfo, DMF_LV_1 } from './DmfCfg';
import { DmfHead } from './DmfHead';
import { DmfItem } from './DmfItem';
const { ccclass, property } = _decorator;
export interface ItemPosIfo {
id: number, //唯一标识
pos: Vec3, //位置
xIdx: number, //列
yIdx: number, //行
target: Node //占有这个节点的对象
}
enum GAME_STATE {
READY = 10,
PAUSE = 20,
END = 30,
NOR_SEL = 40, //普通选择
BAN_SEL = 50, //禁止选择
}
interface HeadIfo {
headTarg: DmfHead,
idx: number,
}
@ccclass('DmfCtr')
export class DmfCtr extends Component {
@property(Node)
posArrNode: Node = null!;
@property(Prefab)
itemPre: Prefab = null!;
@property(Prefab)
headPre: Prefab = null!;
private itemPosIfoArr: ItemPosIfo[] = [];
private row = 5;
private column = 5;
private itemWidth = 100;
private itemHeight = 100;
private itemSpaceX = 6;
private itemSpaceY = 6;
private gameState = GAME_STATE.READY;
private level = 1;
private levelData: DmfLevelIfo = null!;
private rowHeadArr: HeadIfo[] = [];
private columnHeadArr: HeadIfo[] = [];
start() {
// [3]
director.on("dmf_item_click", this.onItemClick, this);
this.gameStart();
}
onDestroy() {
director.off("dmf_item_click", this.onItemClick, this);
}
gameStart() {
this.gameState = GAME_STATE.READY;
this.creAllItem();
this.gameState = GAME_STATE.NOR_SEL;
}
onItemClick(item: DmfItem) {
if (this.gameState != GAME_STATE.NOR_SEL && this.gameState != GAME_STATE.BAN_SEL) return;
switch (this.gameState) {
case GAME_STATE.NOR_SEL:
if (!item.isLocked) item.isSelected = !item.isSelected;
if (this.checkWin()) {
console.log(`游戏成功`);
}
else {
console.log(`游戏没有成功`);
}
break;
case GAME_STATE.BAN_SEL:
item.isLocked = !item.isLocked;
break;
}
}
onEditClick(err: any, flag: string) {
if (this.gameState != GAME_STATE.NOR_SEL && this.gameState != GAME_STATE.BAN_SEL) return;
switch (flag) {
case "nor":
this.gameState = GAME_STATE.NOR_SEL;
break;
case "ban":
this.gameState = GAME_STATE.BAN_SEL;
break;
}
}
creAllItem() {
this.itemPosIfoArr = [];
this.rowHeadArr = [];
this.columnHeadArr = [];
this.loadLevelData();
this.itemPosIfoArr = this.getSqPosIfoArr(this.row, this.column, this.itemWidth, this.itemHeight, this.itemSpaceX, this.itemSpaceY);
for (let i = 0; i < this.itemPosIfoArr.length; ++i) {
let node = instantiate(this.itemPre);
this.itemPosIfoArr[i].target = node;
this.posArrNode.addChild(node);
node.setPosition(this.itemPosIfoArr[i].pos);
let com = node.getComponent(DmfItem)!;
com.isLocked = false;
com.isSelected = false;
}
//行头
for (let yIdx = 0; yIdx < this.row; ++yIdx) {
let posIfo = this.getItemPosIfo(0, yIdx)!;
let node = instantiate(this.headPre);
this.posArrNode.addChild(node);
node.setPosition(v3(posIfo.pos.x - (this.itemWidth / 2 + 200 + this.itemSpaceX), posIfo.pos.y));
let com = node.getComponent(DmfHead)!;
com.isOk = false;
this.rowHeadArr.push({
idx: yIdx,
headTarg: com
});
com.setNums(this.levelData.rowHeadArr[yIdx].reverse());
this.levelData.rowHeadArr[yIdx].reverse()
}
//列头
for (let xIdx = 0; xIdx < this.row; ++xIdx) {
let posIfo = this.getItemPosIfo(xIdx, 0)!;
let node = instantiate(this.headPre);
this.posArrNode.addChild(node);
node.setPosition(v3(posIfo.pos.x, posIfo.pos.y + (this.itemHeight / 2 + 200 + this.itemSpaceY)));
let com = node.getComponent(DmfHead)!;
com.isOk = false;
node.getComponent(DmfHead)?.setVertical();
this.columnHeadArr.push({
idx: xIdx,
headTarg: com
});
com.setNums(this.levelData.columnHeadArr[xIdx].reverse());
this.levelData.columnHeadArr[xIdx].reverse()
}
this.posArrNode.scale = v3(0.8, 0.8, 1);
}
setBgSprSize() {
let minWidth = this.column * this.itemWidth + (this.column - 1) * this.itemSpaceX;
let minHeight = this.row * this.itemHeight + (this.row - 1) * this.itemSpaceY;
this.posArrNode.getComponent(UITransform)!.width = minWidth;
this.posArrNode.getComponent(UITransform)!.height = minHeight;
}
getSqPosIfoArr(row: number, column: number, s_width: number, s_height: number, spacingX: number, spacingY: number): ItemPosIfo[] {
let x_arr: number[] = [];
for (let c = 1; c <= column; ++c) {
let x = s_width * (c - 1 + 0.5) + (c - 1) * spacingX - (column * s_width + (column - 1) * spacingX) / 2;
x_arr.push(x);
}
let y_arr: number[] = [];
for (let r = 1; r <= row; ++r) {
let y = s_height * (r - 1 + 0.5) + (r - 1) * spacingY - (row * s_height + (row - 1) * spacingY) / 2;
y_arr.push(y);
y_arr.sort((a, b) => {
return b - a;
});
}
let pos_arr: ItemPosIfo[] = [];
for (let r = 0; r < y_arr.length; ++r) {
for (let c = 0; c < x_arr.length; ++c) {
pos_arr.push({
pos: v3(x_arr[c], y_arr[r], 0)
, xIdx: c
, yIdx: r
, id: pos_arr.length
, target: null!
});
}
}
return pos_arr;
}
/**
* 获取一个item
* @param xIdx 列
* @param yIdx 行
*/
getItemPosIfo(xIdx: number, yIdx: number) {
for (let i = 0; i < this.itemPosIfoArr.length; ++i) {
if (this.itemPosIfoArr[i].xIdx == xIdx && this.itemPosIfoArr[i].yIdx == yIdx) return this.itemPosIfoArr[i];
}
return null;
}
/**
* 获取一行或一列的item
* @param xIdx
* @param yIdx
* @returns
*/
getItemPosIfos(idx: number, isRow: boolean) {
let items: ItemPosIfo[] = [];
for (let i = 0; i < this.itemPosIfoArr.length; ++i) {
if (isRow && this.itemPosIfoArr[i].yIdx == idx) {
items.push(this.itemPosIfoArr[i]);
}
else if (!isRow && this.itemPosIfoArr[i].xIdx == idx) {
items.push(this.itemPosIfoArr[i]);
}
}
items.sort((a, b) => {
return a.xIdx - b.xIdx;
});
items.sort((a, b) => {
return a.yIdx - b.yIdx;
});
return items;
}
loadLevelData() {
switch (this.level) {
case 1:
this.levelData = DMF_LV_1;
break;
default:
this.levelData = DMF_LV_1;
break;
}
}
//获取一行或列的相连空格数量
getSelCount(items: ItemPosIfo[]) {
let numArr: number[] = [];
let count = 0;
for (let i = 0; i < items.length; ++i) {
if (items[i].target.getComponent(DmfItem)!.isSelected) {
count += 1;
}
else {
if (count != 0) {
numArr.push(count);
count = 0;
}
}
if (i == items.length - 1 && count != 0) {
numArr.push(count);
count = 0;
}
}
return numArr;
}
checkNumArrIsEqual(numArr_1: number[], numArr_2: number[]) {
if (numArr_1.length != numArr_2.length) return false;
for (let i = 0; i < numArr_1.length; ++i) {
if (numArr_1[i] != numArr_2[i]) return false;
}
return true;
}
checkWin() {
let isWin = true;
for (let i = 0; i < this.rowHeadArr.length; ++i) {
console.log(`打印一行`);
let items = this.getItemPosIfos(this.rowHeadArr[i].idx, true);
let numArr_1 = this.getSelCount(items);
let numArr_2 = this.levelData.rowHeadArr[this.rowHeadArr[i].idx];
this.rowHeadArr[i].headTarg.isOk = this.checkNumArrIsEqual(numArr_1, numArr_2);
if (!this.rowHeadArr[i].headTarg.isOk) isWin = this.rowHeadArr[i].headTarg.isOk;
console.log(numArr_1);
console.log(numArr_2);
}
for (let i = 0; i < this.columnHeadArr.length; ++i) {
console.log(`打印一列`);
let items = this.getItemPosIfos(this.columnHeadArr[i].idx, false);
let numArr_1 = this.getSelCount(items);
let numArr_2 = this.levelData.columnHeadArr[this.columnHeadArr[i].idx];
this.columnHeadArr[i].headTarg.isOk = this.checkNumArrIsEqual(numArr_1, numArr_2);
if (!this.columnHeadArr[i].headTarg.isOk) isWin = this.columnHeadArr[i].headTarg.isOk;
console.log(numArr_1);
console.log(numArr_2);
}
return isWin;
}
// update (deltaTime: number) {
// // [4]
// }
}
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "78c8ab93-b935-4cb8-8581-5c4cc32823bf",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Node, SpriteFrame, Sprite, Label, Color } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('DmfHead')
export class DmfHead extends Component {
@property(Sprite)
bgSpr: Sprite = null!;
@property([Label])
numLabArr: Label[] = [];
private _isOk = false;
public set isOk(value: boolean) {
this._isOk = value;
this.bgSpr.color = this._isOk ? new Color(255, 180, 0, 255) : new Color(0, 0, 0, 120);
}
public get isOk() {
return this._isOk;
}
start() {
// [3]
}
setVertical() {
this.node.angle = -90;
for (let i = 0; i < this.numLabArr.length; ++i) {
this.numLabArr[i].node.angle = 90;
}
}
setNums(nums: number[]) {
for (let i = 0; i < this.numLabArr.length; ++i) {
if (i < nums.length) {
this.numLabArr[i].node.active = true;
this.numLabArr[i].string = nums[i].toString()
}
else {
this.numLabArr[i].node.active = false;
}
}
}
// update (deltaTime: number) {
// // [4]
// }
}
\ No newline at end of file
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "d689ae67-bc03-4306-9d9d-cac8d31b03d3",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Node, SpriteFrame, Sprite, director, Color } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('DmfItem')
export class DmfItem extends Component {
@property(Sprite)
bgSpr: Sprite = null!;
@property(Sprite)
banSpr: Sprite = null!;
@property(Node)
clickNode: Node = null!;
private _isLocked = false;
public set isLocked(value: boolean) {
this._isLocked = value;
this.banSpr.node.active = this._isLocked;
}
public get isLocked() {
return this._isLocked;
}
private _isSelected = false;
public set isSelected(value: boolean) {
this._isSelected = value;
this.bgSpr.color = this._isSelected ? new Color(0, 0, 0, 120) : new Color(197, 176, 161, 255);
}
public get isSelected() {
return this._isSelected;
}
start() {
// [3]
this.clickNode.on(Node.EventType.TOUCH_END, () => {
director.emit("dmf_item_click", this);
});
}
// update (deltaTime: number) {
// // [4]
// }
}
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "d389b9fe-15df-4fda-9820-12f0e4df8c2b",
"files": [],
"subMetas": {},
"userData": {}
}
...@@ -318,7 +318,7 @@ ...@@ -318,7 +318,7 @@
"_priority": 1073741824, "_priority": 1073741824,
"_fov": 45, "_fov": 45,
"_fovAxis": 0, "_fovAxis": 0,
"_orthoHeight": 414.4124472573839, "_orthoHeight": 418.6192468619247,
"_near": 1, "_near": 1,
"_far": 2000, "_far": 2000,
"_color": { "_color": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment