Commit d717f845 authored by Jyrki's avatar Jyrki 🐾

added wheatTimer

parent 113958b6
......@@ -17,7 +17,7 @@ initItem = (defaultCount, consumable) ->
# items
window.gameVars = {
cattleGrids: initItem 1, false
cattleGrid: initItem 1, false
fields: initItem 1, false
gold: 200
people: {
......@@ -46,19 +46,29 @@ window.gameVars = {
# update all the counters and stop everything if the game was lost
updateCounters = ->
# left panel
$('span#valuables-gold').html window.gameVars.gold
$('span#goods-wheat').html window.gameVars.wheat.count
$('span#valuables-gold').html window.gameVars.gold
$('span#goods-wheat').html window.gameVars.wheat.count
$('span#goods-livestock').html window.gameVars.liveStock.count
$('span#people-home').html window.gameVars.people.home
$('span#people-war').html window.gameVars.people.war
$('span#people-shelter').html window.gameVars.people.shelter
$('span#people-all').html window.gameVars.people.home + window.gameVars.people.war + window.gameVars.people.shelter
$('span#builds-fields').html window.gameVars.fields.count
$('span#builds-cattle').html window.gameVars.cattleGrids.count
$('span#people-home').html window.gameVars.people.home
$('span#people-war').html window.gameVars.people.war
$('span#people-shelter').html window.gameVars.people.shelter
$('span#people-all').html window.gameVars.people.home + window.gameVars.people.war + window.gameVars.people.shelter
$('span#builds-fields').html window.gameVars.fields.count
$('span#builds-cattle').html window.gameVars.cattleGrid.count
# statistics
$('td#stats-wheat-produced').html window.gameVars.wheat.produced
$('td#stats-wheat-consumed').html window.gameVars.wheat.consumed
$('td#stats-wheat-produced').html window.gameVars.wheat.produced
$('td#stats-wheat-consumed').html window.gameVars.wheat.consumed
$('td#stats-wheat-bought').html window.gameVars.wheat.bought
$('td#stats-wheat-sold').html window.gameVars.wheat.sold
$('td#stats-livestock-consumed').html window.gameVars.liveStock.produced
$('td#stats-livestock-consumed').html window.gameVars.liveStock.consumed
$('td#stats-livestock-bought').html window.gameVars.liveStock.bought
$('td#stats-livestock-sold').html window.gameVars.liveStock.sold
$('td#stats-fields-bought').html window.gameVars.fields.bought
$('td#stats-fields-sold').html window.gameVars.fields.sold
$('td#stats-cattle-bought').html window.gameVars.cattleGrid.bought
$('td#stats-cattle-sold').html window.gameVars.cattleGrid.sold
$('span#valuables-gold').html 0 if window.gameVars.gold < 0
$('span#goods-wheat').html 0 if window.gameVars.wheat.count < 0
......@@ -66,6 +76,7 @@ updateCounters = ->
if window.gameVars.wheat.count <= 0
window.clearInterval evtim
window.clearInterval fitim
window.clearInterval whtim
$('#game-over-modal').modal 'show'
# Field Timer
......@@ -74,6 +85,17 @@ fieldTimer = ->
window.gameVars.wheat.produced += window.gameVars.fields.count
updateCounters()
# Wheat Timer
wheatTimer = ->
if window.gameVars.liveStock.count <= 0
c = (window.gameVars.people.home + window.gameVars.people.shelter) * 2
else
c = window.gameVars.people.home + window.gameVars.people.shelter
window.gameVars.wheat.count -= c
window.gameVars.wheat.consumed += c
updateCounters()
#Krieg
warTimer = ->
die = Math.floor((Math.random() * 10000000) % 2) == 0
......@@ -174,5 +196,6 @@ eventTimer = ->
evtim = window.setInterval eventTimer, 30000
fitim = window.setInterval fieldTimer, 100
whtim = window.setInterval wheatTimer, 100
$(document).ready -> updateCounters()
// Generated by CoffeeScript 1.7.1
(function() {
var eventTimer, evtim, fieldTimer, fitim, initItem, updateCounters, warTimer;
var eventTimer, evtim, fieldTimer, fitim, initItem, updateCounters, warTimer, wheatTimer, whtim;
initItem = function(defaultCount, consumable) {
var retobj;
......@@ -17,7 +17,7 @@
};
window.gameVars = {
cattleGrids: initItem(1, false),
cattleGrid: initItem(1, false),
fields: initItem(1, false),
gold: 200,
people: {
......@@ -52,9 +52,19 @@
$('span#people-shelter').html(window.gameVars.people.shelter);
$('span#people-all').html(window.gameVars.people.home + window.gameVars.people.war + window.gameVars.people.shelter);
$('span#builds-fields').html(window.gameVars.fields.count);
$('span#builds-cattle').html(window.gameVars.cattleGrids.count);
$('span#builds-cattle').html(window.gameVars.cattleGrid.count);
$('td#stats-wheat-produced').html(window.gameVars.wheat.produced);
$('td#stats-wheat-consumed').html(window.gameVars.wheat.consumed);
$('td#stats-wheat-bought').html(window.gameVars.wheat.bought);
$('td#stats-wheat-sold').html(window.gameVars.wheat.sold);
$('td#stats-livestock-consumed').html(window.gameVars.liveStock.produced);
$('td#stats-livestock-consumed').html(window.gameVars.liveStock.consumed);
$('td#stats-livestock-bought').html(window.gameVars.liveStock.bought);
$('td#stats-livestock-sold').html(window.gameVars.liveStock.sold);
$('td#stats-fields-bought').html(window.gameVars.fields.bought);
$('td#stats-fields-sold').html(window.gameVars.fields.sold);
$('td#stats-cattle-bought').html(window.gameVars.cattleGrid.bought);
$('td#stats-cattle-sold').html(window.gameVars.cattleGrid.sold);
if (window.gameVars.gold < 0) {
$('span#valuables-gold').html(0);
}
......@@ -64,6 +74,7 @@
if (window.gameVars.wheat.count <= 0) {
window.clearInterval(evtim);
window.clearInterval(fitim);
window.clearInterval(whtim);
return $('#game-over-modal').modal('show');
}
};
......@@ -74,6 +85,18 @@
return updateCounters();
};
wheatTimer = function() {
var c;
if (window.gameVars.liveStock.count <= 0) {
c = (window.gameVars.people.home + window.gameVars.people.shelter) * 2;
} else {
c = window.gameVars.people.home + window.gameVars.people.shelter;
}
window.gameVars.wheat.count -= c;
window.gameVars.wheat.consumed += c;
return updateCounters();
};
warTimer = function() {
var die, g, message, title;
die = Math.floor((Math.random() * 10000000) % 2) === 0;
......@@ -188,6 +211,8 @@
fitim = window.setInterval(fieldTimer, 100);
whtim = window.setInterval(wheatTimer, 100);
$(document).ready(function() {
return updateCounters();
});
......
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