Skip to content

Commit

Permalink
按照现阶段wiki设计完成了编码
Browse files Browse the repository at this point in the history
  • Loading branch information
crvz6182 committed Dec 6, 2017
1 parent c672246 commit ad9f988
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 1 deletion.
147 changes: 147 additions & 0 deletions assets/Script/firstscene/Bank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
var Loan=require('Loan');
cc.Class({
extends: cc.Component,

properties: {
loans_:{
default:[],
type:[cc.Prefab],
},

currentLoanNum_:0,
fixedLoanNum_:0,
maxFixedLoanNum_:1,

// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},

getLoans:function(){
return this.loans_;
},

getMaxLoanMoney:function(){
event=new cc.Event.EventCustom('GETCREDIT', true);
this.node.dispatchEvent(event);
return event.detail.back / 10.0 * 10000;
},

getOutMoney:function(){
var sum=0;
for(let i=0;i<this.loans_.length;i++){
sum += this.loans_[i].getOriginMoney();
}
return sum;
},


getProtectedLoanMoney:function(){
return this.fixedLoanNum_;
},

getCurrentLoanNum:function(){
return this.currentLoanNum_;
},

getRemainLoanMoney:function(){
var remain = this.getMaxLoanMoney() - this.getOutMoney();
return remain <= 0 ? 0 : remain;
},

increaseMaxLoanMoney:function(){

},

applyLoan:function(money,isfixed){
if(isfixed && this.fixedLoanNum_ >= this.maxFixedLoanNum_){
event=new cc.Event.EventCustom('MESSAGE', true);
event.detail.id = 'maxloannum';
this.node.dispatchEvent(event);
}
else{
var loan=new Loan;
loan.init(money, isfixed ? 240:180, isfixed ? 0.03: 0.05, isfixed);
this.loans_.push(loan);
if(isfixed){
this.fixedLoanNum_++;
}
else{
this.currentLoanNum_++;
}
event=new cc.Event.EventCustom('MONEYADD', true);
event.detail.money = money;
event.detail.record = "贷款";
this.node.dispatchEvent(event);
event=new cc.Event.EventCustom('MESSAGE', true);
event.detail.id='loansuccess';
this.node.dispatchEvent(event);
}
},

grow:function(){
for(let i=0;i<this.loans_.length;i++){
this.loans_[i].grow();
}
},

pause:function(){
this.unshedule(this.grow);
this.unshedule(this.demandLoans);
},

resume:function(time){
this.shedule(this.grow, time * 30);
this.schedule(this.demandLoans, time);
},

demandLoans:function(){
for(let i=0;i<this.loans_.length;i++){
if(this.isDue(this.loans_[i])){
this.repay(this.loans_[i],1);
this.loans_.splice(i,1);
i--;
}
}
},

isDue:function(loan){
event=new cc.Event.EventCustom('GETDATE', true);
this.node.dispatchEvent(event);
var date = event.detail.back;
return loan.isDue(date);
},

repay:function(loan,force){
event=new cc.Event.EventCustom('MONETCUT', true);
event.detail.force = force;
this.node.dispatchEvent(event);
var id;
if(event.detail.back){
id = 'backsuccess';
}
else{
id = 'backfail';
}
event=new cc.Event.EventCustom('MESSAGE', true);
event.detail.id = id;
this.node.dispatchEvent(event);
},

// use this for initialization
onLoad: function () {

},

// called every frame, uncomment this function to activate update callback
// update: function (dt) {

// },
});
65 changes: 65 additions & 0 deletions assets/Script/firstscene/Loan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cc.Class({
extends: cc.Component,

properties: {
originMoney_:0.,
interest_:0.,
deadline_:0,
initDay_:0,
currentMoney_:0.,
isFixed_:false,
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},

init:function(money, deadline, interest, isfixed){
event=new cc.Event.EventCustom('GETDATE', true);
this.node.dispatchEvent(event);
this.originMoney_ = money;
this.interest_ = interest;
this.deadline_ = deadline;
this.initDay = event.detail.back;
this.currentMoney_ = money;
this.isFixed_ = this.isfixed;
},

grow:function(){

},

isDue:function(nowday){
return (this.deadline_ + this.initDay_) <= nowday;
},


getOriginMoney:function(){
return this.originMoney_;
},
getInterest:function(){
return this.interest_;
},
getInitDay:function(){
return this.initDay_;
},
getCurrentMoney:function(){
return this.currentMoney_;
},

// use this for initialization
onLoad: function () {

},

// called every frame, uncomment this function to activate update callback
// update: function (dt) {

// },
});
67 changes: 67 additions & 0 deletions assets/Script/firstscene/Market.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
cc.Class({
extends: cc.Component,

properties: {
initDay_:0,
totalPeopleNum_:0.,
A_:0.,
currentPeopleNum_:0.,
a_:0.,

// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},

Update:function(){
var T=this.getTimeFromInit();
this.totalPeopleNum_=this.totalPeopleNum_*(1+0.01*this.A_);
var temp=(1+0.01*this.A_)*this.currentPeopleNum_;
if(temp>this.totalPeopleNum_){
this.currentPeopleNum_=temp;
}
else{
this.currentPeopleNum_=this.totalPeopleNum_;
}
},

getCurrentPeople:function(project){
var m=project.getM();
var m0=1000*Math.sqrt(this.getTimeFromInit());
return m/(m+m0)*this.currentPeopleNum_;
},

getTimeFromInit:function(){
event=new cc.Event.EventCustom('GETDATE', true);
this.node.dispatchEvent(event);
return event.detail.back-this.initDay_;
},

init:function(){

},

pause:function(){
this.unschedule(this.Update);
},

resume:function(time){
this.schedule(this.Update,time);
},
// use this for initialization
onLoad: function () {

},

// called every frame, uncomment this function to activate update callback
//update: function (dt) {

//},
});
3 changes: 2 additions & 1 deletion assets/Script/firstscene/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ cc.Class({
type:[Object],
},

reward_:0,
reward_:0.,
receiveDay_:0,
finishDay_:0,
content_:"",
name_:"",

// foo: {
// default: null, // The default value will be used only when the component attaching
Expand Down

0 comments on commit ad9f988

Please sign in to comment.