Commit 55e29ff8 authored by Jyrki's avatar Jyrki 🐾

we now produce livestock

parent 45f532e9
......@@ -28,27 +28,30 @@ window.gameVars = {
prices: {
buy: {
wheat: 2
liveStock: 50
livestock: 50
fields: 400
cattleGrid: 400
}
sell: {
wheat: 1
liveStock: 25
livestock: 25
fields: 200
cattleGrid: 200
}
}
liveStock: initItem 1000, true
livestock: initItem 1000, true
wheat: initItem 1000, true
}
lstimEnabled = false
cgtimEnabled = false
# 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#goods-livestock').html window.gameVars.liveStock.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
......@@ -59,7 +62,7 @@ updateCounters = ->
# market sliders
$("span[name=market-#{x}-val]").html $("input[name=market-slider][data-type=#{x}]").val() for x in ['wheat', 'livestock', 'fields', 'cattle']
$("input[name=market-slider][data-type=wheat]").attr "max", window.gameVars.wheat.count
$("input[name=market-slider][data-type=livestock]").attr "max", window.gameVars.liveStock.count
$("input[name=market-slider][data-type=livestock]").attr "max", window.gameVars.livestock.count
$("input[name=market-slider][data-type=fields]").attr "max", window.gameVars.fields.count
$("input[name=market-slider][data-type=cattle]").attr "max", window.gameVars.cattleGrid.count
setPriceLabels("wheat")
......@@ -72,10 +75,10 @@ updateCounters = ->
$('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-produced').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-livestock-produced').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
......@@ -83,11 +86,14 @@ updateCounters = ->
$('span#valuables-gold').html 0 if window.gameVars.gold < 0
$('span#goods-wheat').html 0 if window.gameVars.wheat.count < 0
$('span#goods-livestock').html 0 if window.gameVars.livestock.count < 0
if window.gameVars.wheat.count <= 0
window.clearInterval evtim
window.clearInterval fitim
window.clearInterval whtim
window.clearInterval lstim
window.clearInterval cgtim
$('#game-over-modal').modal 'show'
# Field Timer
......@@ -98,7 +104,7 @@ fieldTimer = ->
# Wheat Timer
wheatTimer = ->
if window.gameVars.liveStock.count <= 0
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
......@@ -107,6 +113,26 @@ wheatTimer = ->
window.gameVars.wheat.consumed += c
updateCounters()
# Livestock Timer
livestockTimer = ->
lstimEnabled = true
people = window.gameVars.people.home + window.gameVars.people.shelter
window.gameVars.livestock.count -= people
window.gameVars.livestock.consumed += people
if window.gameVars.livestock.count <= 0
window.clearInterval lstim
window.clearInterval cgtim
lstimEnabled = false
cgtimEnabled = false
updateCounters()
# Cattlegrid Timer
cattleGridTimer = ->
cgtimEnabled = true
window.gameVars.livestock.count += window.gameVars.cattleGrid.count
window.gameVars.livestock.produced += window.gameVars.cattleGrid.count
updateCounters()
#Krieg
warTimer = ->
die = Math.floor((Math.random() * 10000000) % 2) == 0
......@@ -205,20 +231,14 @@ eventTimer = ->
message: message
}
evtim = window.setInterval eventTimer, 30000
fitim = window.setInterval fieldTimer, 100
whtim = window.setInterval wheatTimer, 100
$(document).ready -> updateCounters()
getPrice = (type) ->
switch type
when "wheat"
buyPrice = window.gameVars.prices.buy.wheat
sellPrice = window.gameVars.prices.sell.wheat
when "livestock"
buyPrice = window.gameVars.prices.buy.liveStock
sellPrice = window.gameVars.prices.sell.liveStock
buyPrice = window.gameVars.prices.buy.livestock
sellPrice = window.gameVars.prices.sell.livestock
when "fields"
buyPrice = window.gameVars.prices.buy.fields
sellPrice = window.gameVars.prices.sell.fields
......@@ -254,7 +274,7 @@ setPriceLabels = (type) ->
else
$(selectorSellButton).removeAttr "disabled"
when "livestock"
if Number($(selectorValue).html()) > window.gameVars.liveStock.count
if Number($(selectorValue).html()) > window.gameVars.livestock.count
$(selectorSellButton).attr "disabled", "disabled"
else
$(selectorSellButton).removeAttr "disabled"
......@@ -297,14 +317,20 @@ marketBuyItem = ->
window.gameVars.wheat.count += amount
window.gameVars.wheat.bought += amount
when "livestock"
window.gameVars.liveStock.count += amount
window.gameVars.liveStock.bought += amount
window.gameVars.livestock.count += amount
window.gameVars.livestock.bought += amount
if window.gameVars.livestock.Count > 0 || !lstimEnabled
lstim = window.setInterval livestockTimer, 1000
cgtim = window.setInterval cattleGridTimer, 1000
when "fields"
window.gameVars.fields.count += amount
window.gameVars.fields.bought += amount
when "cattle"
window.gameVars.cattleGrid.count += amount
window.gameVars.cattleGrid.bought += amount
if window.gameVars.livestock.Count > 0 || !lstimEnabled
lstim = window.setInterval livestockTimer, 1000
cgtim = window.setInterval cattleGridTimer, 1000
updateCounters()
......@@ -324,8 +350,8 @@ marketSellItem = ->
window.gameVars.wheat.count -= amount
window.gameVars.wheat.sold += amount
when "livestock"
window.gameVars.liveStock.count -= amount
window.gameVars.liveStock.sold += amount
window.gameVars.livestock.count -= amount
window.gameVars.livestock.sold += amount
when "fields"
window.gameVars.fields.count -= amount
window.gameVars.fields.sold += amount
......@@ -339,3 +365,11 @@ $(document).on "change", "input[name=market-slider]", marketSliderChange
$(document).on "mousemove", "input[name=market-slider]", marketSliderChange
$(document).on "click", "button[name=market-buy]", marketBuyItem
$(document).on "click", "button[name=market-sell]", marketSellItem
evtim = window.setInterval eventTimer, 30000
fitim = window.setInterval fieldTimer, 100
whtim = window.setInterval wheatTimer, 100
lstim = window.setInterval livestockTimer, 1000
cgtim = window.setInterval cattleGridTimer, 1000
$(document).ready -> updateCounters()
// Generated by CoffeeScript 1.7.1
(function() {
var eventTimer, evtim, fieldTimer, fitim, getPrice, initItem, marketBuyItem, marketSellItem, marketSliderChange, setPriceLabels, updateCounters, warTimer, wheatTimer, whtim;
var cattleGridTimer, cgtim, cgtimEnabled, eventTimer, evtim, fieldTimer, fitim, getPrice, initItem, livestockTimer, lstim, lstimEnabled, marketBuyItem, marketSellItem, marketSliderChange, setPriceLabels, updateCounters, warTimer, wheatTimer, whtim;
initItem = function(defaultCount, consumable) {
var retobj;
......@@ -28,26 +28,30 @@
prices: {
buy: {
wheat: 2,
liveStock: 50,
livestock: 50,
fields: 400,
cattleGrid: 400
},
sell: {
wheat: 1,
liveStock: 25,
livestock: 25,
fields: 200,
cattleGrid: 200
}
},
liveStock: initItem(1000, true),
livestock: initItem(1000, true),
wheat: initItem(1000, true)
};
lstimEnabled = false;
cgtimEnabled = false;
updateCounters = function() {
var x, _i, _len, _ref;
$('span#valuables-gold').html(window.gameVars.gold);
$('span#goods-wheat').html(window.gameVars.wheat.count);
$('span#goods-livestock').html(window.gameVars.liveStock.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);
......@@ -60,7 +64,7 @@
$("span[name=market-" + x + "-val]").html($("input[name=market-slider][data-type=" + x + "]").val());
}
$("input[name=market-slider][data-type=wheat]").attr("max", window.gameVars.wheat.count);
$("input[name=market-slider][data-type=livestock]").attr("max", window.gameVars.liveStock.count);
$("input[name=market-slider][data-type=livestock]").attr("max", window.gameVars.livestock.count);
$("input[name=market-slider][data-type=fields]").attr("max", window.gameVars.fields.count);
$("input[name=market-slider][data-type=cattle]").attr("max", window.gameVars.cattleGrid.count);
setPriceLabels("wheat");
......@@ -71,10 +75,10 @@
$('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-produced').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-livestock-produced').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);
......@@ -85,10 +89,15 @@
if (window.gameVars.wheat.count < 0) {
$('span#goods-wheat').html(0);
}
if (window.gameVars.livestock.count < 0) {
$('span#goods-livestock').html(0);
}
if (window.gameVars.wheat.count <= 0) {
window.clearInterval(evtim);
window.clearInterval(fitim);
window.clearInterval(whtim);
window.clearInterval(lstim);
window.clearInterval(cgtim);
return $('#game-over-modal').modal('show');
}
};
......@@ -101,7 +110,7 @@
wheatTimer = function() {
var c;
if (window.gameVars.liveStock.count <= 0) {
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;
......@@ -111,6 +120,28 @@
return updateCounters();
};
livestockTimer = function() {
var people;
lstimEnabled = true;
people = window.gameVars.people.home + window.gameVars.people.shelter;
window.gameVars.livestock.count -= people;
window.gameVars.livestock.consumed += people;
if (window.gameVars.livestock.count <= 0) {
window.clearInterval(lstim);
window.clearInterval(cgtim);
lstimEnabled = false;
cgtimEnabled = false;
}
return updateCounters();
};
cattleGridTimer = function() {
cgtimEnabled = true;
window.gameVars.livestock.count += window.gameVars.cattleGrid.count;
window.gameVars.livestock.produced += window.gameVars.cattleGrid.count;
return updateCounters();
};
warTimer = function() {
var die, g, message, title;
die = Math.floor((Math.random() * 10000000) % 2) === 0;
......@@ -221,16 +252,6 @@
});
};
evtim = window.setInterval(eventTimer, 30000);
fitim = window.setInterval(fieldTimer, 100);
whtim = window.setInterval(wheatTimer, 100);
$(document).ready(function() {
return updateCounters();
});
getPrice = function(type) {
var buyPrice, sellPrice;
switch (type) {
......@@ -239,8 +260,8 @@
sellPrice = window.gameVars.prices.sell.wheat;
break;
case "livestock":
buyPrice = window.gameVars.prices.buy.liveStock;
sellPrice = window.gameVars.prices.sell.liveStock;
buyPrice = window.gameVars.prices.buy.livestock;
sellPrice = window.gameVars.prices.sell.livestock;
break;
case "fields":
buyPrice = window.gameVars.prices.buy.fields;
......@@ -277,7 +298,7 @@
}
break;
case "livestock":
if (Number($(selectorValue).html()) > window.gameVars.liveStock.count) {
if (Number($(selectorValue).html()) > window.gameVars.livestock.count) {
$(selectorSellButton).attr("disabled", "disabled");
} else {
$(selectorSellButton).removeAttr("disabled");
......@@ -312,7 +333,7 @@
};
marketBuyItem = function() {
var amount, buyPrice, selector, self, sellPrice, _ref;
var amount, buyPrice, cgtim, lstim, selector, self, sellPrice, _ref;
self = $(this);
selector = "input[name=market-slider][data-type=" + self[0].dataset.type + "]";
amount = Number($(selector).val());
......@@ -325,8 +346,12 @@
window.gameVars.wheat.bought += amount;
break;
case "livestock":
window.gameVars.liveStock.count += amount;
window.gameVars.liveStock.bought += amount;
window.gameVars.livestock.count += amount;
window.gameVars.livestock.bought += amount;
if (window.gameVars.livestock.Count > 0 || !lstimEnabled) {
lstim = window.setInterval(livestockTimer, 1000);
cgtim = window.setInterval(cattleGridTimer, 1000);
}
break;
case "fields":
window.gameVars.fields.count += amount;
......@@ -335,6 +360,10 @@
case "cattle":
window.gameVars.cattleGrid.count += amount;
window.gameVars.cattleGrid.bought += amount;
if (window.gameVars.livestock.Count > 0 || !lstimEnabled) {
lstim = window.setInterval(livestockTimer, 1000);
cgtim = window.setInterval(cattleGridTimer, 1000);
}
}
return updateCounters();
};
......@@ -353,8 +382,8 @@
window.gameVars.wheat.sold += amount;
break;
case "livestock":
window.gameVars.liveStock.count -= amount;
window.gameVars.liveStock.sold += amount;
window.gameVars.livestock.count -= amount;
window.gameVars.livestock.sold += amount;
break;
case "fields":
window.gameVars.fields.count -= amount;
......@@ -375,4 +404,18 @@
$(document).on("click", "button[name=market-sell]", marketSellItem);
evtim = window.setInterval(eventTimer, 30000);
fitim = window.setInterval(fieldTimer, 100);
whtim = window.setInterval(wheatTimer, 100);
lstim = window.setInterval(livestockTimer, 1000);
cgtim = window.setInterval(cattleGridTimer, 1000);
$(document).ready(function() {
return updateCounters();
});
}).call(this);
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