Commit a1720fd6 authored by unknown's avatar unknown

食物派对数量加了限制

parent 93b5e5b9
......@@ -65,7 +65,10 @@ export class FoodForThePartyCtr extends Component {
succScore: number = 0;
@property(CCInteger)
foodCount: number = 0;
foodVarCount: number = 0;
@property(CCInteger)
foodNumCount: number = 0;
@property(CCFloat)
totalTime: number = 10;
......@@ -93,9 +96,14 @@ export class FoodForThePartyCtr extends Component {
this.totalTime = resData.totalTime;
}
//@ts-ignore
if (resData.foodCount) {
if (resData.foodVarCount) {
//@ts-ignore
this.foodVarCount = resData.foodVarCount;
}
//@ts-ignore
if (resData.foodNumCount) {
//@ts-ignore
this.foodCount = resData.foodCount;
this.foodNumCount = resData.foodNumCount;
}
//@ts-ignore
if (resData.succScore) {
......@@ -268,7 +276,7 @@ export class FoodForThePartyCtr extends Component {
this.clearPips();
for (let i = 0; i < this.pips.length; ++i) {
// let maxCount = Math.floor(Math.random() * 5) + 1;
let maxCount = this.foodCount;
let maxCount = this.foodVarCount;
let names: string[] = [];
while (names.length < maxCount) {
let name = foodNameArr[Math.floor(Math.random() * foodNameArr.length)];
......@@ -276,12 +284,35 @@ export class FoodForThePartyCtr extends Component {
}
names = this.randomCopyNameToNameArr(names);
names = this.disorderArr(names);
names = this.excludeMoreFood(names);
console.log(`${this.pips[i].getPipName()}管道的物品`);
console.log(names);
this.pips[i].setFoodsImgNames(this.imgHead, names);
}
}
excludeMoreFood(names: string[]): string[] {
if (this.foodVarCount >= this.foodNumCount) {
throw new Error("食物种类大于食物数量限制");
}
let outCount = 0;
while (names.length > this.foodNumCount && outCount < 10000) {
let foodName = names[Math.floor(Math.random() * names.length)];
let nameIdxs: number[] = [];
for (let i = 0; i < names.length; ++i) {
if (names[i] == foodName) nameIdxs.push(i);
}
if (nameIdxs.length > 1) {
names.splice(nameIdxs[Math.floor(Math.random() * nameIdxs.length)], 1);
}
outCount += 1;
}
if(outCount >= 10000){
console.log(`食物数量限制可能发生死循环`);
}
return names;
}
disorderArr<T>(arr: T[]) {
for (let i = 0; i < arr.length; ++i) {
let idx = Math.floor(Math.random() * arr.length);
......
......@@ -24,7 +24,7 @@
"__id__": 7
},
{
"__id__": 70
"__id__": 75
}
],
"_active": true,
......@@ -32,7 +32,7 @@
"_prefab": null,
"autoReleaseAssets": false,
"_globals": {
"__id__": 73
"__id__": 78
},
"_id": "31b6bf24-7062-4edc-ba09-5fd282192579"
},
......@@ -1737,23 +1737,51 @@
"countdownLab": {
"__id__": 52
},
"imageNameArr": [
"索命咒",
"夺魂咒",
"遗忘咒",
"护卫咒",
"昏迷咒"
],
"mgcNameArr": [
"啊啊啊",
"哒哒哒",
"溜溜溜",
"哈哈哈",
"呀呀呀"
],
"quesIfoCount": 5,
"quesIfoPool": [
{
"__id__": 70
},
{
"__id__": 71
},
{
"__id__": 72
},
{
"__id__": 73
},
{
"__id__": 74
}
],
"_id": "78ClK1kytPYZ7ZnlrSEX1M"
},
{
"__type__": "MgcItemItf",
"imgName": "夺魂咒",
"mgcName": "依帕力欧"
},
{
"__type__": "MgcItemItf",
"imgName": "护卫咒",
"mgcName": "一克斯派替欧"
},
{
"__type__": "MgcItemItf",
"imgName": "昏迷咒",
"mgcName": "思丢普录"
},
{
"__type__": "MgcItemItf",
"imgName": "索命咒",
"mgcName": "阿瓦达索命"
},
{
"__type__": "MgcItemItf",
"imgName": "遗忘咒",
"mgcName": "欧不力维特"
},
{
"__type__": "cc.Node",
"_name": "Audio",
......@@ -1765,10 +1793,10 @@
"_active": true,
"_components": [
{
"__id__": 71
"__id__": 76
},
{
"__id__": 72
"__id__": 77
}
],
"_prefab": null,
......@@ -1805,7 +1833,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 70
"__id__": 75
},
"_enabled": true,
"__prefab": null,
......@@ -1820,28 +1848,28 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 70
"__id__": 75
},
"_enabled": true,
"__prefab": null,
"audioSource": {
"__id__": 71
"__id__": 76
},
"_id": "acebgi7bZMsYJe6NAYG6Ez"
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 74
"__id__": 79
},
"shadows": {
"__id__": 75
"__id__": 80
},
"_skybox": {
"__id__": 76
"__id__": 81
},
"fog": {
"__id__": 77
"__id__": 82
}
},
{
......
......@@ -15,9 +15,13 @@ import { MgcSpAswTwoView } from './MgcSpAswTwoView';
import { MgcSpQueView } from './MgcSpQueView';
const { ccclass, property } = _decorator;
export interface MgcItemItf {
imgName: string,
mgcName: string
@ccclass('MgcItemItf')
class MgcItemItf {
@property(CCString)
imgName: string = "";
@property(CCString)
mgcName: string = "";
}
enum GAME_STATE {
......@@ -51,18 +55,15 @@ export class MagicSpellsCtr extends Component {
@property(Label)
countdownLab: Label = null!;
@property([CCString])
imageNameArr: string[] = [];
@property([CCString])
mgcNameArr: string[] = [];
@property(CCInteger)
quesIfoCount: number = 0;
@property(MgcItemItf)
private quesIfoPool: MgcItemItf[] = [];
private gameState: GAME_STATE = GAME_STATE.READY;
private quesIfos: MgcItemItf[] = [];
private rightIfo: MgcItemItf | null = null;
private quesIfos: MgcItemItf[] = [];
private curScore = 0;
private costTime = 0;
......@@ -102,6 +103,7 @@ export class MagicSpellsCtr extends Component {
director.off("quesone_asw", this.onAswOneCall, this);
director.off("questwo_asw", this.onAswTwoCall, this);
director.off("go_answer", this.aswOneStart, this);
director.off("begin_countdown_end");
}
gameStart() {
......@@ -261,11 +263,8 @@ export class MagicSpellsCtr extends Component {
this.countdownLab.string = Utils.formatTime(Math.floor((this.totalTime - this.costTime) * 1000));
}
creRandomItemIfo(): MgcItemItf {
return {
imgName: this.imageNameArr[Math.floor(Math.random() * this.imageNameArr.length)],
mgcName: this.mgcNameArr[Math.floor(Math.random() * this.mgcNameArr.length)]
}
getRandomItemIfo(): MgcItemItf {
return this.quesIfoPool[Math.floor(Math.random() * this.quesIfoPool.length)];
}
isSameItemIfo(a: MgcItemItf, b: MgcItemItf) {
......@@ -273,12 +272,12 @@ export class MagicSpellsCtr extends Component {
}
creQuesIfos() {
if (this.imageNameArr.length < this.quesIfoCount || this.mgcNameArr.length < this.quesIfoCount) {
if (this.quesIfoPool.length < this.quesIfoCount) {
throw new Error("咒语数量少于展示咒语数量");
}
this.quesIfos = [];
while (this.quesIfos.length < this.quesIfoCount) {
let tempIfo = this.creRandomItemIfo();
let tempIfo = this.getRandomItemIfo();
let isOnly = true;
for (let i = 0; i < this.quesIfos.length; ++i) {
if (this.isSameItemIfo(tempIfo, this.quesIfos[i])) {
......
......@@ -676,9 +676,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 1,
resData: {
totalTime: 90,
foodCount: 2,
foodVarCount: 2,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 6
}
}
, {
......@@ -688,9 +689,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 2,
resData: {
totalTime: 120,
foodCount: 3,
foodVarCount: 3,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 7
}
}
, {
......@@ -700,9 +702,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 3,
resData: {
totalTime: 100,
foodCount: 3,
foodVarCount: 3,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 7
}
}
, {
......@@ -712,9 +715,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 4,
resData: {
totalTime: 150,
foodCount: 4,
foodVarCount: 4,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 8
}
}
, {
......@@ -724,9 +728,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 5,
resData: {
totalTime: 180,
foodCount: 4,
foodVarCount: 4,
succScore: 6,
oneScore: 1
oneScore: 1,
foodNumCount: 9
}
}
]
......@@ -742,9 +747,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 1,
resData: {
totalTime: 90,
foodCount: 1,
foodVarCount: 1,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 3
}
}
, {
......@@ -754,9 +760,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 2,
resData: {
totalTime: 120,
foodCount: 2,
foodVarCount: 2,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 6
}
}
, {
......@@ -766,9 +773,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 3,
resData: {
totalTime: 100,
foodCount: 2,
foodVarCount: 2,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 6
}
}
, {
......@@ -778,9 +786,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 4,
resData: {
totalTime: 90,
foodCount: 2,
foodVarCount: 2,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 7
}
}
, {
......@@ -790,9 +799,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 5,
resData: {
totalTime: 150,
foodCount: 3,
foodVarCount: 3,
succScore: 5,
oneScore: 1
oneScore: 1,
foodNumCount: 8
}
}
, {
......@@ -802,9 +812,10 @@ export const levelCfg: OneVarLevelItf[] = [
level: 6,
resData: {
totalTime: 180,
foodCount: 3,
foodVarCount: 3,
succScore: 6,
oneScore: 1
oneScore: 1,
foodNumCount: 10
}
}
]
......
......@@ -23,7 +23,7 @@ export class LevelHomeCtr extends Component {
// [3]
if (!levelMgr.loadedOutData) {
levelMgr.loadedOutData = true;
levelMgr.gameIdHead = 30;
levelMgr.gameIdHead = 101;
levelMgr.unLockCount = 10;
if(Utils.getValueFromHref("gameIdHead")){
levelMgr.gameIdHead = Number(Utils.getValueFromHref("gameIdHead"));
......
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