aboutsummaryrefslogtreecommitdiff
path: root/src/sim/static
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2020-05-23 20:52:57 -0500
committerMark Powers <markppowers0@gmail.com>2020-05-23 20:52:57 -0500
commitb6d40fa3776b33a03f8f40636a35a967873fc97b (patch)
tree9d777e363363c150290733dbf5613df4306e7c21 /src/sim/static
parentb5de6d44e0f291f6fcbe035f4a15edcab1491aad (diff)
Make sim an idle game
Diffstat (limited to 'src/sim/static')
-rw-r--r--src/sim/static/items.js14
-rw-r--r--src/sim/static/tiles.js34
2 files changed, 14 insertions, 34 deletions
diff --git a/src/sim/static/items.js b/src/sim/static/items.js
index 40f73f1..a3e3eca 100644
--- a/src/sim/static/items.js
+++ b/src/sim/static/items.js
@@ -9,13 +9,17 @@ function getScout() {
id: 1,
text: "scout",
cost: 2,
- callback: function () {
+ callback: function (game) {
var type = tileMap[Math.floor(Math.random() * 3)]
var tile = new type()
- status = `Your scout found a ${tile.name}. Click to place it.`
- return {
- tile: tile
- }
+ messages.push(`Your scout found a ${tile.name}.`)
+
+ var randX, randY
+ do {
+ randX = Math.floor(width * Math.random())
+ randY = Math.floor(height * Math.random())
+ } while(game.level[randX][randY] != undefined)
+ game.level[randX][randY] = tile
}
}
} \ No newline at end of file
diff --git a/src/sim/static/tiles.js b/src/sim/static/tiles.js
index 5b31d19..203acb4 100644
--- a/src/sim/static/tiles.js
+++ b/src/sim/static/tiles.js
@@ -10,17 +10,8 @@ Mountain.prototype.draw = function (x, y, size) {
ctx.stroke();
ctx.fill();
}
-Mountain.prototype.update = function () {
- var event = undefined
- if(Math.random() < 0.1){
- event = function(){
-
- }
- }
- return {
- gold: 1,
- event: event
- }
+Mountain.prototype.update = function (game) {
+ game.gold += 1
}
function Forest() {
@@ -35,15 +26,9 @@ Forest.prototype.draw = function (x, y, size) {
ctx.stroke();
ctx.fill();
}
-Forest.prototype.update = function () {
+Forest.prototype.update = function (game) {
var event = {}
- if(Math.random() < 0.1){
- event.status = "A tree monster taks half of your"
- }
- return {
- resources: Math.floor(Math.random() * 5),
- event: event
- }
+ game.resources += Math.floor(Math.random() * 5)
}
function Town() {
@@ -60,14 +45,5 @@ Town.prototype.draw = function (x, y, size) {
ctx.fill();
}
Town.prototype.update = function () {
- var event = undefined
- if(Math.random() < 0.1){
- event = function(){
-
- }
- }
- return {
- population: Math.floor(Math.random() * 4) - 1,
- event: event
- }
+ game.population += Math.floor(Math.random() * 4) - 1
}