Commit bce34096 authored by unknown's avatar unknown

数式接龙暂存

parent 400e77fe
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "376f17d3-d5da-42e8-9fd9-9939ade42c4c",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "3c103e9f-7884-42dd-babb-1953fdcb22dc",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "27f9e1c5-9a40-47ab-8f5c-721bb5d34eb5",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "27f9e1c5-9a40-47ab-8f5c-721bb5d34eb5@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": "27f9e1c5-9a40-47ab-8f5c-721bb5d34eb5"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "27f9e1c5-9a40-47ab-8f5c-721bb5d34eb5@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": "27f9e1c5-9a40-47ab-8f5c-721bb5d34eb5@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "27f9e1c5-9a40-47ab-8f5c-721bb5d34eb5@f9941"
}
}
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "0717846d-497e-4b51-9454-a40465268107",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "0717846d-497e-4b51-9454-a40465268107@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": "0717846d-497e-4b51-9454-a40465268107"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "0717846d-497e-4b51-9454-a40465268107@f9941",
"displayName": "图标_橡皮",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0.5,
"offsetY": 1.5,
"trimX": 3,
"trimY": 1,
"width": 55,
"height": 55,
"rawWidth": 60,
"rawHeight": 60,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"isUuid": true,
"imageUuidOrDatabaseUri": "0717846d-497e-4b51-9454-a40465268107@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "0717846d-497e-4b51-9454-a40465268107@f9941"
}
}
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "dd599e9d-2831-453b-8841-48148d964a86",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "dd599e9d-2831-453b-8841-48148d964a86@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": "dd599e9d-2831-453b-8841-48148d964a86"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "dd599e9d-2831-453b-8841-48148d964a86@f9941",
"displayName": "图标_铅笔 ",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": -1.5,
"offsetY": 1,
"trimX": 0,
"trimY": 0,
"width": 50,
"height": 51,
"rawWidth": 53,
"rawHeight": 53,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"isUuid": true,
"imageUuidOrDatabaseUri": "dd599e9d-2831-453b-8841-48148d964a86@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "dd599e9d-2831-453b-8841-48148d964a86@f9941"
}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "064fe36d-e3e0-485e-b248-780121d3546d",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.1.27",
"importer": "prefab",
"imported": true,
"uuid": "691c3ce4-04d8-44e6-8399-93ef7ce3a485",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "FormulaSolitaireItem"
}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "d7150472-9b68-4732-9e61-71b7d740d5ad",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
{
"ver": "1.1.27",
"importer": "scene",
"imported": true,
"uuid": "1cd9e018-8b35-4525-bca9-8418f7439cca",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "26d057f4-bf07-43a3-a9fc-85f4614c489e",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}
import { _decorator, Component, Node, Sprite, Vec3, Prefab, Label, CCFloat, instantiate, UITransform, v3, director } from 'cc';
import { VIEW_DEF } from '../../../../startFolder/script/common/ViewDef';
import { viewMgr } from '../../../../startFolder/script/common/ViewMgr';
import { GameDescView } from '../../commonView/script/GameDescView';
import { FS_ITEM_STATE } from './FormulaSolitaireItem';
const { ccclass, property } = _decorator;
export interface ItemPosIfo {
id: number, //唯一标识
pos: Vec3, //位置
xIdx: number, //列
yIdx: number, //行
target: Node //占有这个节点的对象
}
enum GAME_STATE {
READY = 10,
RUN = 20,
END = 30,
PAUSE = 40,
}
@ccclass('FormulaSolitaireCtr')
export class FormulaSolitaireCtr extends Component {
@property(Node)
posArrNode: Node = null!;
@property(Node)
bottomSprNode: Node = null!;
@property(Prefab)
itemPre: Prefab = null!;
@property(Label)
countdownLab: Label = null!;
@property(CCFloat)
totalTime: number = 0;
private itemWidth = 100;
private itemHeight = 100;
private itemSpaceX = 2;
private itemSpaceY = 2;
private itemPosIfoArr: ItemPosIfo[] = [];
private row = 4;
private column = 4;
private gameState = GAME_STATE.READY;
private costTime = 0;
private isPlayCountdownMus = false;
private isShowGameDescViewOnce = false;
showGameDescView() {
this.isShowGameDescViewOnce = true;
viewMgr.openView(VIEW_DEF.GameDescView, (node) => {
node.getComponent(GameDescView)?.setDesc("选择数字填入空格使横着的和竖着的算式都要成立。\n注意:不论从左到右还是从上到下都要符合四则运算优先级。");
});
}
onCloseGameDescView() {
this.gameState = GAME_STATE.RUN;
}
setGameData(resData: object) {
//@ts-ignore
if (resData.totalTime) {
//@ts-ignore
this.totalTime = resData.totalTime;
}
//@ts-ignore
if (resData.level) {
//@ts-ignore
this.level = resData.level;
}
//@ts-ignore
if (resData.isShowGuide) {
//@ts-ignore
this.isShowGameDescViewOnce = false;
}
else {
this.isShowGameDescViewOnce = true;
}
}
start () {
// [3]
this.gameStart();
}
gameStart(){
this.creAllItem();
this.setBgSprSize();
}
creAllItem() {
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.posArrNode.addChild(node);
node.setPosition(this.itemPosIfoArr[i].pos);
this.itemPosIfoArr[i].target = node;
}
}
setBgSprSize() {
let minWidth = this.column * this.itemWidth + (this.column - 1) * this.itemSpaceX;
let minHeight = this.row * this.itemHeight + (this.row - 1) * this.itemSpaceY;
this.bottomSprNode.getComponent(UITransform)!.width = minWidth + 20;
this.bottomSprNode.getComponent(UITransform)!.height = minHeight + 20;
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;
}
calculator(numStrArr: string[]): number {
let operatorIdx = -1;
for (let i = 0; i < numStrArr.length; ++i) {
if (numStrArr[i] == "+" || numStrArr[i] == "-" || numStrArr[i] == "÷" || numStrArr[i] == "×") {
operatorIdx = i;
break;
}
}
for (let i = 0; i < numStrArr.length; ++i) {
if (numStrArr[i] == "÷" || numStrArr[i] == "×") {
operatorIdx = i;
break;
}
}
if (operatorIdx == 0 || operatorIdx == numStrArr.length - 1) {
throw new Error(`传入的算式不符合规则`);
}
if (operatorIdx == -1) return Number(numStrArr[0]);
let num_1 = Number(numStrArr[operatorIdx - 1]);
let num_2 = Number(numStrArr[operatorIdx + 1]);
let num_ret = 0;
switch (numStrArr[operatorIdx]) {
case "+":
num_ret = num_1 + num_2;
break;
case "-":
num_ret = num_1 - num_2;
break;
case "÷":
if (num_2 == 0) throw new Error(`除数为零`);
num_ret = num_1 / num_2;
break;
case "×":
num_ret = num_1 * num_2;
break;
default:
break;
}
numStrArr[operatorIdx - 1] = num_ret.toString();
numStrArr.splice(operatorIdx, 2);
return this.calculator(numStrArr);
}
getItemsDirArr(itemPosIfos: ItemPosIfo[]){
let dirArr: FS_ITEM_STATE[] = [];
for(let i = 0; i < itemPosIfos.length - 1; ++ i){
if(itemPosIfos[i +1].pos.x - itemPosIfos[i].pos.x < 0){
dirArr.push(FS_ITEM_STATE.LEFT);
}
else if(itemPosIfos[i +1].pos.x - itemPosIfos[i].pos.x > 0){
dirArr.push(FS_ITEM_STATE.RIGHT);
}
else if(itemPosIfos[i +1].pos.y - itemPosIfos[i].pos.y < 0){
dirArr.push(FS_ITEM_STATE.BOTTOM);
}
else if(itemPosIfos[i +1].pos.y - itemPosIfos[i].pos.y > 0){
dirArr.push(FS_ITEM_STATE.TOP);
}
}
if(itemPosIfos.length > 0) dirArr.push(FS_ITEM_STATE.CENTER);
return dirArr;
}
// update (deltaTime: number) {
// // [4]
// }
}
\ No newline at end of file
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "2a0e24cb-d4e2-40a0-8493-9f45c80035d1",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Node, Sprite, Label, math, Color, director, UITransform } from 'cc';
const { ccclass, property } = _decorator;
export enum FS_ITEM_STATE {
CENTER = 10,
TOP = 20,
BOTTOM = 30,
LEFT = 40,
RIGHT = 50
}
@ccclass('FormulaSolitaireItem')
export class FormulaSolitaireItem extends Component {
@property(Sprite)
bgSpr: Sprite = null!;
@property(Sprite)
topSpr: Sprite = null!;
@property(Sprite)
bottomSpr: Sprite = null!;
@property(Sprite)
leftSpr: Sprite = null!;
@property(Sprite)
rightSpr: Sprite = null!;
@property(Label)
textLab: Label = null!;
@property(Node)
clickNode: Node = null!;
private _itemState = FS_ITEM_STATE.CENTER;
private _text = "";
start () {
// [3]
}
setItemState(state: FS_ITEM_STATE){
this._itemState = state;
this.topSpr.node.active = this._itemState == FS_ITEM_STATE.TOP;
this.bottomSpr.node.active = this._itemState == FS_ITEM_STATE.BOTTOM;
this.leftSpr.node.active = this._itemState == FS_ITEM_STATE.LEFT;
this.rightSpr.node.active = this._itemState == FS_ITEM_STATE.RIGHT;
}
getItemState(state: FS_ITEM_STATE){
return this._itemState;
}
setText(text: string){
this.textLab.string = text;
this.textLab.string = text;
}
getText(){
return this._text;
}
setColor(color: math.IColorLike){
this.bgSpr.color = new Color(color.r, color.g, color.b, color.a);
this.topSpr.color = new Color(color.r, color.g, color.b, color.a);
this.bottomSpr.color = new Color(color.r, color.g, color.b, color.a);
this.leftSpr.color = new Color(color.r, color.g, color.b, color.a);
this.rightSpr.color = new Color(color.r, color.g, color.b, color.a);
}
getWorldAABB(){
return this.clickNode.getComponent(UITransform)!.getBoundingBoxToWorld();
}
// update (deltaTime: number) {
// // [4]
// }
}
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "88952260-aac4-4526-b241-c8470d9c0717",
"files": [],
"subMetas": {},
"userData": {}
}
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