Commit 2b156c67 authored by unknown's avatar unknown

数独基本完成

parent d593838e
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "42cbbdac-76da-4e12-831e-13910dc3835d",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "42cbbdac-76da-4e12-831e-13910dc3835d@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": "42cbbdac-76da-4e12-831e-13910dc3835d"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "42cbbdac-76da-4e12-831e-13910dc3835d@f9941",
"displayName": "得分框",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 196,
"height": 63,
"rawWidth": 196,
"rawHeight": 63,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"isUuid": true,
"imageUuidOrDatabaseUri": "42cbbdac-76da-4e12-831e-13910dc3835d@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "42cbbdac-76da-4e12-831e-13910dc3835d@f9941"
}
}
{
"ver": "1.0.21",
"importer": "image",
"imported": true,
"uuid": "36092018-5dae-44cd-8603-c86a799139b1",
"files": [
".png",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "36092018-5dae-44cd-8603-c86a799139b1@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": "36092018-5dae-44cd-8603-c86a799139b1"
},
"ver": "1.0.21",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "36092018-5dae-44cd-8603-c86a799139b1@f9941",
"displayName": "目标分数框",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 196,
"height": 63,
"rawWidth": 196,
"rawHeight": 63,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"isUuid": true,
"imageUuidOrDatabaseUri": "36092018-5dae-44cd-8603-c86a799139b1@6c48a",
"atlasUuid": ""
},
"ver": "1.0.9",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"hasAlpha": true,
"type": "sprite-frame",
"redirect": "36092018-5dae-44cd-8603-c86a799139b1@f9941"
}
}
import { _decorator, Component, Node, instantiate, Button, Toggle, Label, director } from 'cc';
import { _decorator, Component, Node, instantiate, Button, Toggle, Label, director, CCFloat } from 'cc';
import { countdownMus, failMus, succMus } from '../../../../startFolder/script/common/AudioDef';
import { AudioMgr } from '../../../../startFolder/script/common/AudioMgr';
import { Utils } from '../../../../startFolder/script/common/Utils';
import { VIEW_DEF } from '../../../../startFolder/script/common/ViewDef';
import { viewMgr } from '../../../../startFolder/script/common/ViewMgr';
import { viewMgr, VIEW_INDEX } from '../../../../startFolder/script/common/ViewMgr';
import { BeginCountdownView } from '../../commonView/script/BeginCountdownView';
import { ChallengeFailView } from '../../commonView/script/ChallengeFailView';
import { ChallengeSuccView } from '../../commonView/script/ChallengeSuccView';
import { SK_LV_1, SK_LV_2, SK_LV_3, SK_LV_4 } from './SudokuCfg';
import { SudokuItemCtr } from './SudokuItemCtr';
import { SudokuLevelViewCtr } from './SudokuLevelCtr';
......@@ -20,23 +26,56 @@ export class SudokuCtr extends Component {
@property(Node)
numOptsNode: Node = null!;
@property(Label)
countdownLab: Label = null!;
@property(Label)
remainLab: Label = null!;
@property(CCFloat)
totalTime: number = 0;
private gameState = GAME_STATE.READY;
private fillNum = 1;
private sqr = 5;;
private sqr = 5;
private level = 1;
private costTime = 0;
private isPlayCountdownMus = false;
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;
}
}
start() {
// [3]
director.on("sk_item_click", this.onItemClick, this);
director.on("begin_countdown_end", () => {
//引导
this.gameState = GAME_STATE.FILL;
}, this);
this.gameStart();
}
onDestroy() {
director.off("sk_item_click", this.onItemClick, this);
director.off("begin_countdown_end");
}
onItemClick(item: SudokuItemCtr) {
if (this.gameState == GAME_STATE.FILL) {
item.setNumStr(this.fillNum.toString());
this.remainLab.string = "剩余" + viewMgr.getView(VIEW_DEF.SudokuLevelView).getComponent(SudokuLevelViewCtr)?.getWrongItemCount() + "个";
if (this.checkWin()) {
console.log(`游戏成功`);
this.gameEnd(true);
......@@ -53,15 +92,18 @@ export class SudokuCtr extends Component {
gameStart() {
this.gameState = GAME_STATE.READY;
this.countdownLab.string = Utils.formatTime(Math.floor(this.totalTime * 1000));
this.fillNum = 1;
let level = 4;
let cfg = this.getLevelCfg(level)[Math.floor(Math.random() * this.getLevelCfg(level).length)];
let cfg = this.getLevelCfg(this.level)[Math.floor(Math.random() * this.getLevelCfg(this.level).length)];
this.sqr = cfg.sqr;
viewMgr.openView(VIEW_DEF.SudokuLevelView, (node) => {
node.getComponent(SudokuLevelViewCtr)?.setItemIfos(cfg);
this.remainLab.string = "剩余" + node.getComponent(SudokuLevelViewCtr)?.getWrongItemCount() + "个";
});
this.setNumTogs();
this.gameState = GAME_STATE.FILL;
viewMgr.openView(VIEW_DEF.BeginCountdownView, (node) => {
node.getComponent(BeginCountdownView)?.init();
}, VIEW_INDEX.UPPER);
}
setNumTogs() {
......@@ -73,14 +115,46 @@ export class SudokuCtr extends Component {
this.numOptsNode.children[i].getComponent(Toggle)!.clickEvents[0].customEventData = (i + 1) + "";
this.numOptsNode.children[i].getComponentInChildren(Label)!.string = (i + 1) + "";
}
this.numOptsNode.children[0].getComponent(Toggle)!.isChecked = true;
}
gameEnd(isWin: boolean) {
this.gameState = GAME_STATE.END;
if (isWin) {
viewMgr.openView(VIEW_DEF.ChallengeSuccView, (node) => {
AudioMgr.playOneShot(succMus);
node?.getComponent(ChallengeSuccView)?.init();
}, VIEW_INDEX.TOP);
}
else {
viewMgr.openView(VIEW_DEF.ChallengeFailView, (node) => {
AudioMgr.playOneShot(failMus);
node?.getComponent(ChallengeFailView);
}, VIEW_INDEX.TOP);
}
}
update(deltaTime: number) {
// [4]
this.countdownTime(deltaTime);
}
//倒计时
countdownTime(dt: number) {
if (this.gameState == GAME_STATE.READY || this.gameState == GAME_STATE.END) {
return;
}
this.costTime += dt;
if (!this.isPlayCountdownMus && this.totalTime - this.costTime < 3.5) {
this.isPlayCountdownMus = true;
AudioMgr.playOneShot(countdownMus);
}
if (this.totalTime - this.costTime <= 0) {
// console.log(`游戏时间到`);
this.gameEnd(false);
return;
}
this.countdownLab.string = Utils.formatTime(Math.floor((this.totalTime - this.costTime) * 1000));
}
onFillNumClick(err: any, numStr: string) {
......
......@@ -89,6 +89,14 @@ export class SudokuLevelViewCtr extends Component {
this.bgSprNode.getComponent(UITransform)!.height = minHeight + 20;
}
getWrongItemCount(){
let count = 0;
for(let i = 0; i < this.itemPosIfoArr.length; ++ i){
if(!this.itemPosIfoArr[i].target.getComponent(SudokuItemCtr)?.isRight()) count += 1;
}
return count;
}
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) {
......
......@@ -456,7 +456,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
, {
, {
gameId: 3003,
sceneUnitIfo: SCENE_DEF.Classify_3,
comName: "ClassifyCtr",
......@@ -467,7 +467,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
, {
, {
gameId: 3004,
sceneUnitIfo: SCENE_DEF.Classify_4,
comName: "ClassifyCtr",
......@@ -478,7 +478,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
, {
, {
gameId: 3005,
sceneUnitIfo: SCENE_DEF.Classify_5,
comName: "ClassifyCtr",
......@@ -489,7 +489,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
, {
, {
gameId: 3006,
sceneUnitIfo: SCENE_DEF.Classify_6,
comName: "ClassifyCtr",
......@@ -539,7 +539,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
, {
, {
gameId: 3104,
sceneUnitIfo: SCENE_DEF.Classify_star4,
comName: "ClassifyCtr_1",
......@@ -550,7 +550,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
, {
, {
gameId: 3105,
sceneUnitIfo: SCENE_DEF.Classify_star5,
comName: "ClassifyCtr_1",
......@@ -561,7 +561,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
, {
, {
gameId: 3106,
sceneUnitIfo: SCENE_DEF.Classify_star6,
comName: "ClassifyCtr_1",
......@@ -779,7 +779,7 @@ export const levelCfg: OneVarLevelItf[] = [
foodNumCount: 6
}
}
, {
, {
gameId: 10104,
sceneUnitIfo: SCENE_DEF.FoodForTheParty_2,
comName: "FoodForThePartyCtr",
......@@ -835,7 +835,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
,{
, {
gameId: 11002,
sceneUnitIfo: SCENE_DEF.QuickQuiz_1,
comName: "QuickQuizCtr",
......@@ -846,7 +846,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
,{
, {
gameId: 11003,
sceneUnitIfo: SCENE_DEF.QuickQuiz_1,
comName: "QuickQuizCtr",
......@@ -857,7 +857,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
,{
, {
gameId: 11004,
sceneUnitIfo: SCENE_DEF.QuickQuiz_1,
comName: "QuickQuizCtr",
......@@ -868,7 +868,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
,{
, {
gameId: 11005,
sceneUnitIfo: SCENE_DEF.QuickQuiz_1,
comName: "QuickQuizCtr",
......@@ -879,7 +879,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
,{
, {
gameId: 11006,
sceneUnitIfo: SCENE_DEF.QuickQuiz_1,
comName: "QuickQuizCtr",
......@@ -890,7 +890,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
,{
, {
gameId: 11007,
sceneUnitIfo: SCENE_DEF.QuickQuiz_1,
comName: "QuickQuizCtr",
......@@ -901,7 +901,7 @@ export const levelCfg: OneVarLevelItf[] = [
oneScore: 1
}
}
,{
, {
gameId: 11008,
sceneUnitIfo: SCENE_DEF.QuickQuiz_1,
comName: "QuickQuizCtr",
......@@ -931,4 +931,50 @@ export const levelCfg: OneVarLevelItf[] = [
}
]
}
, {
gameIdHead: 130,
title: "锯形数独",
desc: "锯形数独,第一个版本",
levelArr: [{
gameId: 13001,
sceneUnitIfo: SCENE_DEF.Sudoku_1,
comName: "SudokuCtr",
level: 1,
resData: {
totalTime: 60,
level: 1
}
}
, {
gameId: 13002,
sceneUnitIfo: SCENE_DEF.Sudoku_1,
comName: "SudokuCtr",
level: 2,
resData: {
totalTime: 120,
level: 2
}
}
, {
gameId: 13003,
sceneUnitIfo: SCENE_DEF.Sudoku_1,
comName: "SudokuCtr",
level: 3,
resData: {
totalTime: 150,
level: 3
}
}
, {
gameId: 13004,
sceneUnitIfo: SCENE_DEF.Sudoku_1,
comName: "SudokuCtr",
level: 4,
resData: {
totalTime: 150,
level: 4
}
}
]
}
];
\ No newline at end of file
......@@ -23,7 +23,7 @@ export class LevelHomeCtr extends Component {
// [3]
if (!levelMgr.loadedOutData) {
levelMgr.loadedOutData = true;
levelMgr.gameIdHead = 101;
levelMgr.gameIdHead = 130;
levelMgr.unLockCount = 10;
if(Utils.getValueFromHref("gameIdHead")){
levelMgr.gameIdHead = Number(Utils.getValueFromHref("gameIdHead"));
......
......@@ -93,6 +93,8 @@ interface ScenePathItf {
QuickQuiz_1: ScenePathUnitItf,
//魔法咒语
MagicSpells_1: ScenePathUnitItf,
//锯形数独
Sudoku_1: ScenePathUnitItf,
}
export const SCENE_DEF: ScenePathItf = {
TestScene: {
......@@ -410,6 +412,11 @@ export const SCENE_DEF: ScenePathItf = {
sceneName: "MagicSpells_1",
desc: "魔法咒语,第一个版本"
},
Sudoku_1: {
bundleName: "sceneBundle",
sceneName: "Sudoku_1",
desc: "锯形数独,第一个版本"
},
}
/**
* [1] Class member could be defined like this.
......
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