From 1855e0c673b06399ca89aa0c705d30b1a9ea3b97 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Wed, 13 May 2020 10:53:44 -0500 Subject: Add sim and paperflight games --- src/sim/static/items.js | 21 ++++++++++++++ src/sim/static/styles.css | 4 +++ src/sim/static/tiles.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 src/sim/static/items.js create mode 100644 src/sim/static/styles.css create mode 100644 src/sim/static/tiles.js (limited to 'src/sim/static') diff --git a/src/sim/static/items.js b/src/sim/static/items.js new file mode 100644 index 0000000..40f73f1 --- /dev/null +++ b/src/sim/static/items.js @@ -0,0 +1,21 @@ +tileMap = { + 0: Mountain, + 1: Forest, + 2: Town, +} + +function getScout() { + return { + id: 1, + text: "scout", + cost: 2, + callback: function () { + 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 + } + } + } +} \ No newline at end of file diff --git a/src/sim/static/styles.css b/src/sim/static/styles.css new file mode 100644 index 0000000..febe7a0 --- /dev/null +++ b/src/sim/static/styles.css @@ -0,0 +1,4 @@ +button { + background-color: lavender; + padding: 10px 20px; +} \ No newline at end of file diff --git a/src/sim/static/tiles.js b/src/sim/static/tiles.js new file mode 100644 index 0000000..5b31d19 --- /dev/null +++ b/src/sim/static/tiles.js @@ -0,0 +1,73 @@ +function Mountain() { + this.name = "mountain" +} +Mountain.prototype.draw = function (x, y, size) { + ctx.fillStyle = "gray" + ctx.beginPath(); + ctx.moveTo(x * size + size / 2, y * size); + ctx.lineTo(x * size, (1 + y) * (size)); + ctx.lineTo((1 + x) * (size), (1 + 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 + } +} + +function Forest() { + this.name = "forest" +} +Forest.prototype.draw = function (x, y, size) { + ctx.fillStyle = "green" + ctx.beginPath(); + ctx.moveTo(x * size + size / 2, y * size); + ctx.lineTo(x * size, (1 + y) * (size)); + ctx.lineTo((1 + x) * (size), (1 + y) * (size)); + ctx.stroke(); + ctx.fill(); +} +Forest.prototype.update = function () { + 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 + } +} + +function Town() { + this.name = "town" +} +Town.prototype.draw = function (x, y, size) { + ctx.fillStyle = "brown" + ctx.stokeStyle = "brown" + ctx.beginPath(); + ctx.moveTo(x * size + size / 2, y * size); + ctx.lineTo(x * size, (1 + y) * (size)); + ctx.lineTo((1 + x) * (size), (1 + y) * (size)); + ctx.stroke(); + 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 + } +} -- cgit v1.2.3