Commit 6fdb987b authored by unknown's avatar unknown

准备做输入键盘

parent 0efd036f
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
"_prefab": null, "_prefab": null,
"autoReleaseAssets": false, "autoReleaseAssets": false,
"_globals": { "_globals": {
"__id__": 268 "__id__": 270
}, },
"_id": "7ba0cc5b-1464-4e01-8985-4f5a35e49ee1" "_id": "7ba0cc5b-1464-4e01-8985-4f5a35e49ee1"
}, },
...@@ -212,13 +212,16 @@ ...@@ -212,13 +212,16 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 262 "__id__": 263
},
{
"__id__": 265
}, },
{ {
"__id__": 264 "__id__": 267
}, },
{ {
"__id__": 266 "__id__": 269
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -529,6 +532,9 @@ ...@@ -529,6 +532,9 @@
}, },
{ {
"__id__": 261 "__id__": 261
},
{
"__id__": 262
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -6388,6 +6394,20 @@ ...@@ -6388,6 +6394,20 @@
"_lockFlags": 0, "_lockFlags": 0,
"_id": "a3mglBU75JoLlL+yYrmZ3x" "_id": "a3mglBU75JoLlL+yYrmZ3x"
}, },
{
"__type__": "3ef97wNcrZEGp+9oJZU8d4F",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 16
},
"_enabled": true,
"__prefab": null,
"itemArrNode": {
"__id__": 16
},
"_id": "acdFKhDLFNCqt0edrUJWVz"
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
...@@ -6397,7 +6417,7 @@ ...@@ -6397,7 +6417,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 263 "__id__": 264
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
...@@ -6424,7 +6444,7 @@ ...@@ -6424,7 +6444,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 265 "__id__": 266
}, },
"_cameraComponent": { "_cameraComponent": {
"__id__": 9 "__id__": 9
...@@ -6445,7 +6465,7 @@ ...@@ -6445,7 +6465,7 @@
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 267 "__id__": 268
}, },
"_alignFlags": 45, "_alignFlags": 45,
"_target": null, "_target": null,
...@@ -6471,19 +6491,33 @@ ...@@ -6471,19 +6491,33 @@
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "e8a+bU/8dPDbbJguUzLdoF" "fileId": "e8a+bU/8dPDbbJguUzLdoF"
}, },
{
"__type__": "ef93cR0ympO9asx+oI55eKA",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 7
},
"_enabled": true,
"__prefab": null,
"circle": {
"__id__": 262
},
"_id": "a3b0bpXKVKi6G7Xsut/FHS"
},
{ {
"__type__": "cc.SceneGlobals", "__type__": "cc.SceneGlobals",
"ambient": { "ambient": {
"__id__": 269 "__id__": 271
}, },
"shadows": { "shadows": {
"__id__": 270 "__id__": 272
}, },
"_skybox": { "_skybox": {
"__id__": 271 "__id__": 273
}, },
"fog": { "fog": {
"__id__": 272 "__id__": 274
} }
}, },
{ {
......
import { _decorator, Component, Node } from 'cc';
import { RS_ITEM_TYPE } from './RingSumItem';
const { ccclass, property } = _decorator;
export interface RingSumCfg {
result: number,
numStrArr: string[][],
fixCtrArr: RS_ITEM_TYPE[][]
}
export const RS_LV_1 = {
result: 15,
numStrArr: [
["2", "9", "4"],
["7", "5", "3"],
["6", "1", "8"]
],
fixCtrArr: [
[RS_ITEM_TYPE.FIX, RS_ITEM_TYPE.FIX, RS_ITEM_TYPE.FIX],
[RS_ITEM_TYPE.NOR, RS_ITEM_TYPE.FIX, RS_ITEM_TYPE.FIX],
[RS_ITEM_TYPE.FIX, RS_ITEM_TYPE.FIX, RS_ITEM_TYPE.NOR]
]
}
\ No newline at end of file
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "b2c2a706-641d-4d85-8c52-41d530e4fedb",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Node } from 'cc';
import { RingSumItem, RS_ITEM_TYPE } from './RingSumItem';
const { ccclass, property } = _decorator;
@ccclass('RingSumCircle')
export class RingSumCircle extends Component {
@property(Node)
itemArrNode: Node = null!;
private itemArr: RingSumItem[][] = [];
onLoad(){
let items = this.itemArrNode.getComponentsInChildren(RingSumItem);
this.itemArr = [
[items[0], items[1], items[2]],
[items[3], items[4], items[5]],
[items[6], items[7], items[8]]
];
}
start () {
// [3]
}
setAllText(texts: string[][]){
for(let i = 0; i < texts.length; ++ i){
for(let j = 0; j < texts[i].length; ++ j){
this.itemArr[i][j].setText(texts[i][j]);
}
}
}
getAllText(){
return [
[this.itemArr[0][0].getText(), this.itemArr[0][1].getText(), this.itemArr[0][2].getText()],
[this.itemArr[1][0].getText(), this.itemArr[1][1].getText(), this.itemArr[1][2].getText()],
[this.itemArr[2][0].getText(), this.itemArr[2][1].getText(), this.itemArr[2][2].getText()]
];
}
setAllItemType(itemTypes: RS_ITEM_TYPE[][]){
for(let i = 0; i < itemTypes.length; ++ i){
for(let j = 0; j < itemTypes[i].length; ++ j){
this.itemArr[i][j].setItemType(itemTypes[i][j]);
}
}
}
getAllItemType(){
return [
[this.itemArr[0][0].getItemType(), this.itemArr[0][1].getItemType(), this.itemArr[0][2].getItemType()],
[this.itemArr[1][0].getItemType(), this.itemArr[1][1].getItemType(), this.itemArr[1][2].getItemType()],
[this.itemArr[2][0].getItemType(), this.itemArr[2][1].getItemType(), this.itemArr[2][2].getItemType()]
];
}
hideAllNorItemText(){
for(let i = 0; i < this.itemArr.length; ++ i){
for(let j = 0; j < this.itemArr[i].length; ++ j){
if(this.itemArr[i][j].getItemType() == RS_ITEM_TYPE.NOR) this.itemArr[i][j].setText("");
}
}
}
checkRepeat(){
let isRepeat = false;
let countMap: Map<string, RingSumItem[]> = new Map<string, RingSumItem[]>();
for(let i = 0; i < this.itemArr.length; ++ i){
for(let j = 0; i < this.itemArr[i].length; ++ j){
this.itemArr[i][j].setNoRepLabColor();
if(countMap.get(this.itemArr[i][j].getText())){
countMap.get(this.itemArr[i][j].getText())?.push(this.itemArr[i][j]);
}
else{
countMap.set(this.itemArr[i][j].getText(), [this.itemArr[i][j]]);
}
}
}
countMap.forEach((value, key) => {
if(value.length > 1){
isRepeat = true;
if(key != ""){
for(let i = 0; i < value.length; ++ i){
value[i].setRepLabColor();
}
}
}
});
return isRepeat;
}
// update (deltaTime: number) {
// // [4]
// }
}
{
"ver": "4.0.22",
"importer": "typescript",
"imported": true,
"uuid": "3ef97c0d-72b6-441a-9fbd-a09654f1de05",
"files": [],
"subMetas": {},
"userData": {}
}
import { _decorator, Component, Node } from 'cc'; import { _decorator, Component, Node } from 'cc';
import { RingSumCfg, RS_LV_1 } from './RingSumCfg';
import { RingSumCircle } from './RingSumCircle';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('RingSumCtr') @ccclass('RingSumCtr')
export class RingSumCtr extends Component { export class RingSumCtr extends Component {
// [1]
// dummy = '';
// [2] @property(RingSumCircle)
// @property circle: RingSumCircle = null!;
// serializableDummy = 0;
private level = 2;
private levelData: RingSumCfg = null!;
start () { start () {
// [3] // [3]
this.gameStart();
}
gameStart(){
this.loadLevelData();
this.circle.setAllText(this.levelData.numStrArr);
this.circle.setAllItemType(this.levelData.fixCtrArr);
this.circle.hideAllNorItemText();
}
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(`传入的算式不符合规则1`);
}
if (operatorIdx == -1) {
if (numStrArr.length == 1) return Number(numStrArr[0]);
else throw new Error(`传入的算式不符合规则2`);
}
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);
}
loadLevelData() {
switch (this.level) {
case 1:
this.levelData = RS_LV_1;
break;
case 2:
this.levelData = RS_LV_1;
break;
default:
this.levelData = RS_LV_1;
break;
}
}
checkWin() {
let texts = this.circle.getAllText();
return false;
} }
// update (deltaTime: number) { // update (deltaTime: number) {
// // [4] // // [4]
// } // }
} }
/**
* [1] Class member could be defined like this.
* [2] Use `property` decorator if your want the member to be serializable.
* [3] Your initialization goes here.
* [4] Your update function goes here.
*
* Learn more about scripting: https://docs.cocos.com/creator/3.0/manual/en/scripting/
* Learn more about CCClass: https://docs.cocos.com/creator/3.0/manual/en/scripting/ccclass.html
* Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.0/manual/en/scripting/life-cycle-callbacks.html
*/
import { _decorator, Component, Node, Sprite, LabelComponent, Label } from 'cc'; import { _decorator, Component, Node, Sprite, LabelComponent, Label, Color } from 'cc';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
export enum RS_ITEM_TYPE {
NOR = 10,
FIX = 20
}
@ccclass('RingSumItem') @ccclass('RingSumItem')
export class RingSumItem extends Component { export class RingSumItem extends Component {
@property(Sprite) @property(Sprite)
selSpr: Sprite = null!; selSpr: Sprite = null!;
...@@ -14,10 +19,41 @@ export class RingSumItem extends Component { ...@@ -14,10 +19,41 @@ export class RingSumItem extends Component {
@property(Node) @property(Node)
clickNode: Node = null!; clickNode: Node = null!;
start () { private _itemType = RS_ITEM_TYPE.NOR;
start() {
// [3] // [3]
} }
setText(text: string) {
this.numLab.string = text;
}
getText() {
return this.numLab.string == "" ? "+" : this.numLab.string; //直接在这里处理一下没填入的数字免得麻烦;
}
setItemType(type: RS_ITEM_TYPE) {
this._itemType = type;
if (this._itemType == RS_ITEM_TYPE.NOR) {
this.numLab.color = new Color(255, 255, 255, 255);
}
else {
this.numLab.color = new Color(31, 168, 142, 255);
}
}
getItemType() {
return this._itemType;
}
setRepLabColor(){
this.numLab.color = new Color(255, 0, 0, 255);
}
setNoRepLabColor(){
this.setItemType(this.getItemType());
}
// update (deltaTime: number) { // update (deltaTime: number) {
// // [4] // // [4]
// } // }
......
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