-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoderClicker.js
More file actions
136 lines (118 loc) · 3.81 KB
/
CoderClicker.js
File metadata and controls
136 lines (118 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
if (Meteor.isClient) {
Accounts.ui.config({
passwordSignupFields: 'USERNAME_ONLY'
});
Meteor.subscribe('userData');
Template.hello.user = function(){
return Meteor.user();
};
Template.hello.items=function(){
return [{name:"Buy Online Courses",cost:1000,icon:"graduation-cap",kw:"courses",dps:2},
{name:"Hire Junior Programmer",cost:2000,icon:"user-plus",kw:"jprog",dps:4},
{name:"Hire Marketing Professional",cost:4000,icon:"shopping-cart",kw:"market",dps:8},
{name:"Hire Lawyer",cost:8000,icon:"legal",kw:"law",dps:16},
{name:"Hire Team",cost:25000,icon:"group",kw:"team",dps:50},
{name:"your product",cost:30000,icon:"trademark",kw:"tm",dps:60},
{name:"Invest in ads",cost:60000,icon:"tv",kw:"ad",dps:120},
{name:"Rent an incubator",cost:100000, icon:"home",kw:"inc",dps:200},
{name:"Create Reliable Servers",cost:300000,icon:"server",kw:"serv",dps:600},
{name:"Buy HQ",cost:1000000,icon:"institution",kw:"hq",dps:2000},
{name:"Buy Company",cost:5000000,icon:"money",kw:"comp",dps:10000}];
};
Template.hello.events({
'click button.code' : function(){
Meteor.call('click');
}
});
Template.hello.events({
'click button.buy' :function(event){
Meteor.call('buy', event.target.id,event.target.name);
}
});
Template.hello.events({
'click #ldb' :function(event){
$("table").toggle();
return false;
}
});
Template.hello.players = function () {
return Meteor.users.find({},{sort:{'money' : -1}});
};
UI.registerHelper('formatCurrency',function(context,options){
return numeral(context).format('0.0a');
});
Template.nav.events({
'click #facebook-login': function(event) {
Meteor.loginWithFacebook({}, function(err){
if (err) {
throw new Meteor.Error("Facebook login failed");
}
});
},
'click #logout': function(event) {
Meteor.logout(function(err){
if (err) {
throw new Meteor.Error("Logout failed");
}
})
}
});
Meteor.startup(function(){
$('html').bind('keypress',function(e){
if(e.keyCode == 13 || e.keyCode==32)
{return false;}
});
});
}
if (Meteor.isServer) {
Meteor.startup(function(){
Meteor.setInterval(function(){
Meteor.users.find({}).map(function(user){
Meteor.users.update({_id:user._id}, {$inc:{'money' : user.rate}})
});
},1000);
});
Accounts.onCreateUser(function(options,user){
user.money=0;
user.rate=0;
user.lines=0;
user.jprog=0;
user.courses=0;
user.market=0;
user.law=0;
user.team=0;
user.tm=0;
user.ad=0;
user.inc=0;
user.serv=0;
user.hq=0;
user.comp=0;
return user;
});
Meteor.publish("userData",function(){
return Meteor.users.find({},{sort:{'money' : -1}});
});
}
Meteor.methods({
click : function() {
Meteor.users.update({_id:this.userId}, {$inc: {'money' : 50 , 'lines' : 1}});
var btn = $('.code');
btn.prop('disabled',true);
window.setTimeout(function(){
btn.prop('disabled',false);
},50);
},
buy : function(amount,qty) {
if(Meteor.user().money >= amount && amount>0){
Meteor.users.update({_id:this.userId}, {$inc:{'rate' : (Math.floor(amount/500)), 'money':(0-amount)}});
var q=qty,doc={};
doc[q]=1;
Meteor.users.update({_id:this.userId}, {$inc:doc});
var btn = $('.buy');
btn.prop('disabled',true);
window.setTimeout(function(){
btn.prop('disabled',false);
},100);
}
},
})