Commit 2aaf7c55 authored by Tt's avatar Tt

第一版

parent 9462ca1c
const Items = [ const ITEMS = [
{ {
id: 1001, id: 1001,
name: "西瓜" type: 1,//食物
name: "苹果",
icon: "icon_1",
growthValue: 10,
cost: 100,
discount: 0.8,
num: 3,
levelLimite: 1,
},
{
id: 1002,
type: 1,//食物
name: "香蕉",
icon: "icon_2",
growthValue: 15,
cost: 120,
discount: 1,
num: 5,
levelLimite: 2,
}, {
id: 1003,
type: 1,//食物
name: "面包",
icon: "icon_3",
growthValue: 20,
cost: 150,
discount: 1,
num: 8,
levelLimite: 1,
}, {
id: 1004,
type: 1,//食物
name: "胡萝卜",
icon: "icon_4",
growthValue: 30,
cost: 200,
discount: 1,
num: 9,
levelLimite: 1,
}, {
id: 1005,
type: 1,//食物
name: "奶酪",
icon: "icon_5",
growthValue: 40,
cost: 230,
discount: 1,
num: 13,
levelLimite: 1,
}, {
id: 1006,
type: 1,//食物
name: "橙子",
icon: "icon_6",
growthValue: 50,
cost: 270,
discount: 1,
num: 1,
levelLimite: 1,
}, {
id: 1007,
type: 1,//食物
name: "披萨",
icon: "icon_7",
growthValue: 90,
cost: 400,
discount: 1,
num: 0,
levelLimite: 1,
}, {
id: 1008,
type: 1,//食物
name: "西红柿",
icon: "icon_8",
growthValue: 100,
cost: 600,
discount: 1,
num: 0,
levelLimite: 1,
} }
] ]
const Shops = []; const LEVEL = {
const Kitchen = []; level_1: {
growth: 100,
},
level_2: {
growth: 300,
},
level_3: {
growth: 600,
},
level_4: {
growth: 1000,
},
level_5: {
growth: 1500,
},
level_6: {
growth: 2100,
}
}
const USER = { const USER = {
name: "小小香香", name: "小小香香",
coin: 100023, coin: 100023,
...@@ -19,4 +114,9 @@ const USER = { ...@@ -19,4 +114,9 @@ const USER = {
useClothes: [], useClothes: [],
mood: "开心" mood: "开心"
} }
export { USER } enum ITEM_TYPE {
\ No newline at end of file FOOD = 1,
HOUSE = 2,
CLOTHES = 3
}
export { USER, LEVEL, ITEMS, ITEM_TYPE }
\ No newline at end of file
class Item { class Item {
public id: number;//id
public type: number;//商品类型 public type: number;//商品类型
public name: string;//商品名称 public name: string;//商品名称
public icon: string;//商品图片--可用type生成 public icon: string;//商品图片--可用type生成
...@@ -8,12 +9,15 @@ class Item { ...@@ -8,12 +9,15 @@ class Item {
public num: number;//拥有数量 public num: number;//拥有数量
public levelLimite: number;//等级限制 public levelLimite: number;//等级限制
constructor(obj: any) { constructor(obj: any) {
this.id = obj.id;
this.type = obj.type; this.type = obj.type;
this.name = obj.name; this.name = obj.name;
this.icon = obj.icon; this.icon = obj.icon;
this.growthValue = obj.growthValue; this.growthValue = obj.growthValue;
this.cost = obj.cost; this.cost = obj.cost;
this.discount = obj.discount; this.discount = obj.discount;
this.num = obj.num;
this.levelLimite = obj.levelLimite;
} }
} }
......
import Item from "./item"
class Kitchen {
private _list: Array<Item>
constructor() {
this._list = [];
}
use(id) {
this._list = this._list.map(li => {
if (li.id == id) li.num -= 1;
return li;
})
}
buy(id) {
this._list = this._list.map(li => {
if (li.id == id) li.num += 1;
return li;
})
}
getListByType(type: number) {
return this._list.filter(li => li.type == type)
}
parse(list: any) {
if (!list) return;
this._list = list.map(li => { return new Item(li); })
}
get list() {
return this._list;
}
}
let kitchen = new Kitchen();
export default kitchen;
{
"ver": "1.0.8",
"uuid": "1ab727dc-af13-4539-a98a-4ec85d8981c9",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import { LEVEL } from "../config/config";
class User { class User {
public name: string; public name: string;
public coin: number; public coin: number;
public level: number; public level: number;
public growth: number; public growth: number;//当前成长值
public growthDaily: number; public growthDaily: number;
public growthDailyMax: number; public growthDailyMax: number;
public eatTime: number; public eatTime: number;
public useFurniture: Array<number>; public useFurniture: Array<number>;
public useClothes: Array<number>; public useClothes: Array<number>;
public mood: string; public mood: number;//0开心 1不开心
constructor() { constructor() {
} }
...@@ -23,6 +25,30 @@ class User { ...@@ -23,6 +25,30 @@ class User {
this.eatTime = data.eatTime; this.eatTime = data.eatTime;
this.useFurniture = data.useFurniture; this.useFurniture = data.useFurniture;
this.useClothes = data.useClothes; this.useClothes = data.useClothes;
this.mood = 1;
}
isDailyMax() {
return this.growthDailyMax >= this.growthDaily
}
addGrowth(val) {
this.growth += val;
this.growthDaily += val;
user.mood = 0;
}
useCoin(val) {
this.coin -= val;
}
//当前等级成长值最大值
public get growthLevel(): number {
let max = 1;
for (let i = 1; i < 100; i++) {
let val = LEVEL[`level_${i}`].growth;
if (this.growth < val) {
max = val
break;
}
}
return max
} }
} }
let user = new User(); let user = new User();
......
import pg from "../pg";
import { ITEMS, USER } from "../config/config"
import user from "../model/user";
import kitchen from "../model/kitchen";
//获取信息,购买物品,使用物品(吃东西),穿戴衣服/更换家具
class Api {
static askUser() {
return new Promise((resolve, reject) => {
pg.http.send("GET", "http://www.baidu.com", {}).then((data: any) => {
let userInfo = USER;
user.parse(userInfo);
let kitchenInfo = ITEMS;
kitchen.parse(kitchenInfo);
resolve('');
})
});
}
static askUseItem(data) {
return new Promise((resolve, reject) => {
pg.http.send("GET", "http://www.baidu.com", {}).then((data: any) => {
user.addGrowth(data.growthValue);
kitchen.use(data.id);
resolve('');
})
});
}
static askBuyItem(data) {
return new Promise((resolve, reject) => {
data.id;
data.type;
pg.http.send("GET", "http://www.baidu.com", {}).then((data: any) => {
user.useCoin(data.cost * data.discount);
kitchen.buy(data.id);
resolve('');
})
});
}
}
export default Api;
\ No newline at end of file
import pg from "../pg";
import { USER } from "../config/config"
import user from "../model/user";
//获取信息,购买物品,使用物品(吃东西),穿戴衣服/更换家具
class Api {
static askUser() {
return new Promise((resolve, reject) => {
pg.http.send("GET", "http://www.baidu.com", {}).then((data: any) => {
let info = USER;
user.parse(info);
resolve('');
})
});
}
}
export default Api;
\ No newline at end of file
...@@ -245,6 +245,15 @@ let pg = { ...@@ -245,6 +245,15 @@ let pg = {
skl.setAnimation(0, aniName, loop); skl.setAnimation(0, aniName, loop);
return skl; return skl;
}, },
playDBAnimation(item: any, aniName: string, loop?: number) {
if (!item || !cc.isValid(item)) return pg.logger.w("动画播放失败,传入了错误的item");
if (!aniName) return pg.logger.w("动画播放失败,传入了错误的aniName");
let node = item.node ? item.node : item;
if (!cc.isValid(node)) return pg.logger.w("节点已销毁");
let skl: dragonBones.ArmatureDisplay = node.getComponent(dragonBones.ArmatureDisplay);
skl.playAnimation(aniName, loop);
return skl;
},
}, },
load: { load: {
//资源加载 //资源加载
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
"rawHeight": 20, "rawHeight": 20,
"borderTop": 0, "borderTop": 0,
"borderBottom": 0, "borderBottom": 0,
"borderLeft": 0, "borderLeft": 6.5,
"borderRight": 0, "borderRight": 8.5,
"subMetas": {} "subMetas": {}
} }
} }
......
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