Skip to content

Instantly share code, notes, and snippets.

@thinkong
Created January 28, 2014 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkong/8660392 to your computer and use it in GitHub Desktop.
Save thinkong/8660392 to your computer and use it in GitHub Desktop.
<head>
<title>rpgtown</title>
</head>
<body>
{{> game}}
</body>
<template name="game">
<h1>Hello Stranger!</h1>
{{cnt}}
<div class="container">
<div class="header row">
<div style="float: right">
{{loginButtons align="right"}}
</div>
</div>
</div>
<br/>
{{#if currentUser}}
<h1>House : {{ housecnt}}</h1>
<h1>Money : {{ money}}</h1>
<input type="button" value="Add House" class="addhouse"/>
<input type="button" value="Click2" />
<input type="button" value="Click3" />
{{/if}}
</template>
lists = new Meteor.Collection('Lists');
GameObjects = new Meteor.Collection('GameInfo');
getCounter = function(){
return lists.findOne({name:"counter"}).cnt
};
icnt = 0;
if (Meteor.isClient) {
Template.game.cnt = function(){
if (lists.findOne({name:"counter"}))
return lists.findOne({name:"counter"}).cnt;
};
Template.game.housecnt = function(){
return GameObjects.findOne({owner:Meteor.userId()}).house;
};
Template.game.money = function(){
return GameObjects.findOne({owner:Meteor.userId()}).money;
};
Template.game.events({
'click .addhouse' : function () {
// template data, if any, is available in 'this'
icnt = getCounter();
if (typeof console !== 'undefined')
console.log("You pressed the button" + getCounter());
if (Meteor.user() !== null)
{
console.log("logged in");
GameObjects.upsert({_id:GameObjects.findOne({owner:Meteor.userId()})['_id']}, {$inc:{house:1}});
}
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
lists.insert({name:"counter", cnt:0});
Meteor.setInterval(function(){
lists.update({name:"counter"},{$inc:{cnt:1}});
GameObjects.find().forEach(function(u){
iAmount = u;
GameObjects.upsert({_id:u._id}, {$inc:{money:u.house}});
});
}, 1000);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment