From 729b5a3f81b94afe25a00f8d4920dc6127f539e9 Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Sat, 31 Mar 2018 11:04:33 +0200 Subject: [PATCH] Added Cost --- css/main.css | 21 +++++++++++++++++++++ images/items/money.png | Bin 0 -> 572 bytes images/moneybg.png | Bin 0 -> 439 bytes index.html | 4 +++- js/baseclasses.js | 29 ++++++++++++++++++++++++++++- js/game.js | 23 ++++++++++++++++++++--- js/items.json | 2 +- js/tiles.js | 23 ++++++++++++++++++++++- js/userinterface.js | 8 ++++++-- lang/en.json | 5 +++-- 10 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 images/items/money.png create mode 100644 images/moneybg.png diff --git a/css/main.css b/css/main.css index 03dc56b..7ec1359 100644 --- a/css/main.css +++ b/css/main.css @@ -71,6 +71,27 @@ body { border-color: gray; } +#money { + position: fixed; + font-family: 'Electrolize', sans-serif; + font-size: 22px; + width: 1200; + height: 42px; + line-height: 42px; + text-align: center; + background-image: url(../images/moneybg.png); +} + +body { + -webkit-touch-callout: none; /* iOS Safari */ + -webkit-user-select: none; /* Safari */ + -khtml-user-select: none; /* Konqueror HTML */ + -moz-user-select: none; /* Firefox */ + -ms-user-select: none; /* Internet Explorer/Edge */ + user-select: none; /* Non-prefixed version, currently + supported by Chrome and Opera */ +} + .buildtile { width: 48; height: 48; diff --git a/images/items/money.png b/images/items/money.png new file mode 100644 index 0000000000000000000000000000000000000000..7e7365fe3730cf3ee324919d803ad111e76c1eba GIT binary patch literal 572 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSL74G){)!Z!pk#?_L`iUdT1k0gQ7S`0VrE{6US4X6f{C7i zo{`~4h0LiyQ`dO9IEG|6U!CUf#cU|k%H0(-MJ!kRa_<6#UE($k%Rg|uvz>Fi+eXp( z(`#?F$v>0tJ!(EV-LFFb?3T@i=RBR43WaDn;vlviIr??!?w8+eCE7nmAr)pyOL+7}8=Xq-q`*aR#!N20?J6f4e zw9m0KexYBqn?Fh;p$4=*8T^inB95BY)3p+0SLijc zE*JUW{^G-}xl<$7GJH<(VXWr$;@-e6aV98X#St0S8}FL`DSbD#64|iD;iTZ99jh1; z?mJ~Up1)ut@mXN`wOJttb_tlhkC(Se{-VA)qyNK@cZyqO@Rk{Mn2g V`R|#R*8wA!!PC{xWt~$(6994jPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;2FkAZe8V00AdSL_t(oN9~s}4gw(%MfbvXc9zE8-qOSa zcm!|YjU*ZKoxFtsU1Tjxo{7Srd9o0q)9tidh4sYe!=@wX9?)~ejbi(Xt>Wu(D=@D2 z)kRytGEcGZTcVV-aYL;oz?43I@o-5m{OssceZTCDL1Otdk{2u24mu>_S&D;bfT{pu zp3!?O{^DW$jCg(vE~L~jzhX<5YD)Mj4`N3BQKL%$3S<642a_Qz8v^-eU;F hJT~rdftAFk-2;I9aelWvu$uq?002ovPDHLkV1lKavxNWv literal 0 HcmV?d00001 diff --git a/index.html b/index.html index 8eae7bd..17bab15 100644 --- a/index.html +++ b/index.html @@ -32,9 +32,11 @@
- Example
+ + ??? Dollar + diff --git a/js/baseclasses.js b/js/baseclasses.js index 47b7517..899a45c 100644 --- a/js/baseclasses.js +++ b/js/baseclasses.js @@ -35,6 +35,32 @@ class Tile { } } + pay() { + var items = 0 + for (var i = 0; i < this.cost.length; i++) { + if (this.cost[i].id == 0) { + if (this.cost[i].count <= money) { + items++ + } + } else { + if (inventory.countOf(this.cost[i].id) >= this.cost[i].count) { + items++ + } + } + } + if (items == this.cost.length) { + for (var i = 0; i < this.cost.length; i++) { + if (this.cost[i].id == 0) { + money -= this.cost[i].count + } else { + inventory.take(this.cost[i].id, this.cost[i].count, null) + } + } + return true + } + return false + } + unloadImages() { this.images = { "0": [], @@ -99,7 +125,8 @@ class Inventory { for (var j = 0; j < count; j++) { for (var i = 0; i < this.items.length; i++) { if (this.items[i].id == id) { - factory.deleteItem(this.items[i]) + if (factory != null) + factory.deleteItem(this.items[i]) this.items.splice(i, 1) break; } diff --git a/js/game.js b/js/game.js index be0fea5..7357a34 100644 --- a/js/game.js +++ b/js/game.js @@ -1,5 +1,6 @@ var factorys = [] var inventory = {} +var money = 100 var items = [] @@ -163,6 +164,7 @@ function render() { } else { drawInventory(inventory, lang["player"]) } + $('#money').text(money + " " + lang.items[0]) } function getItemFormId(id) { @@ -259,11 +261,26 @@ function drawInfoBar() { $('#infoDesc h1').text("") $('#infoDesc p').text("") } - if(selectedTile.maxwork!=0){ + if (selectedTile.maxwork != 0 && mode != "selectbuilding" && mode != "building") { $('#infoDesc p').css("height", 154) infoCtx.fillStyle = "green"; - infoCtx.fillRect(0, 228, 432*(selectedTile.currentwork/selectedTile.maxwork), 12) - }else{ + infoCtx.fillRect(0, 228, 432 * (selectedTile.currentwork / selectedTile.maxwork), 12) + } else { $('#infoDesc p').css("height", 166) } + if (mode == "selectbuilding" || mode == "building") { + if (selectedTile != 0) { + infoCtx.textAlign = "center" + infoCtx.font = "18px Electrolize" + infoCtx.fillStyle = "black"; + infoCtx.fillText(lang.cost, 336, 66) + infoCtx.textAlign = "start" + for (var i = 0; i < selectedTile.cost.length; i++) { + if (selectedTile.cost[i].id == 0) + infoCtx.fillText(selectedTile.cost[i].count + " " + lang.items[selectedTile.cost[i].id], 246, 86 + 20 * i) + else + infoCtx.fillText(selectedTile.cost[i].count + "x " + lang.items[selectedTile.cost[i].id], 246, 86 + 20 * i) + } + } + } } diff --git a/js/items.json b/js/items.json index f74c481..a2e1603 100644 --- a/js/items.json +++ b/js/items.json @@ -1,7 +1,7 @@ { "items": [{ "id": 0, - "name": "coal" + "name": "money" },{ "id": 1, "name": "log" diff --git a/js/tiles.js b/js/tiles.js index c24676e..8b6bf60 100644 --- a/js/tiles.js +++ b/js/tiles.js @@ -7,6 +7,10 @@ class Conveyorbelt extends Tile { super(x, y, factory) this.name = "conveyorbelt" this.hasNoInventory = true + this.cost = [{ + "id": 0, + "count": 20 + }] this.texture = { "0": ["conveyorbelt00", "conveyorbelt01", "conveyorbelt02", "conveyorbelt03", "conveyorbelt04", "conveyorbelt05", "conveyorbelt06"], "1": [] @@ -23,6 +27,10 @@ class Treefarm extends Tile { this.currentwork = 0 this.name = "treefarm" this.hasNoInventory = true + this.cost = [{ + "id": 0, + "count": 30 + }] this.texture = { "0": [], "1": ["treefarm10", "treefarm10", "treefarm10", "treefarm11", "treefarm11", "treefarm11", "treefarm12", "treefarm12", "treefarm12", "treefarm13", "treefarm13", "treefarm13", "treefarm14", "treefarm14", "treefarm14", "treefarm15", "treefarm15", "treefarm15"] @@ -47,6 +55,15 @@ class Saw extends Tile { this.maxwork = 96 this.currentwork = 0 this.name = "saw" + this.cost = [{ + "id": 0, + "count": 50 + }, + { + "id": 1, + "count": 50 + } + ] this.texture = { "0": [], "1": ["saw10", "saw10", "saw10", "saw10", "saw11", "saw11", "saw11", "saw11", "saw12", "saw12", "saw12", "saw12", "saw13", "saw13", "saw13", "saw13"] @@ -59,7 +76,7 @@ class Saw extends Tile { var requieredCount = 5 if (this.input.countOf(1) >= requieredCount) { if (this.currentwork == 96) { - this.input.take(1, requieredCount,this.factory) + this.input.take(1, requieredCount, this.factory) var item = new Item(2, this.x * 48, this.y * 48) this.factory.items.push(item) item.setDFromDirection(this.direction) @@ -79,6 +96,10 @@ class Collector extends Tile { super(x, y, factory) this.name = "collector" this.hasNoInventory = true + this.cost = [{ + "id": 0, + "count": 50 + }] this.texture = { "0": [], "1": ["collector10"] diff --git a/js/userinterface.js b/js/userinterface.js index 08bf12c..e270405 100644 --- a/js/userinterface.js +++ b/js/userinterface.js @@ -27,6 +27,8 @@ function style() { $('#infoDesc').css('margin-left', infoMarginLeft + 5) $('#itemcount').css('margin-top', itemCountMarginTop) $('#itemcount').css('margin-left', screenMarginLeft) + $('#money').css('margin-top', itemCountMarginTop - 42) + $('#money').css('margin-left', screenMarginLeft + 3) screenleftpos = screenMarginLeft screentoppos = screenMarginTop infoleftpos = infoMarginLeft @@ -128,7 +130,8 @@ function onDocumentMouseMove(event) { } if (mousedown && mode == "build") { if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) { - factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory]) + if (new toBuild().pay()) + factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory]) } } } @@ -253,7 +256,8 @@ function buildEvents() { } if (mode == "build") { if (factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] == 0) { - factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory]) + if (new toBuild().pay()) + factorys[currentFactory].tiles[cursorScreenX][cursorScreenY] = new toBuild(cursorScreenX, cursorScreenY, factorys[currentFactory]) } } if ((mode == "none") && isCursorInScreen) { diff --git a/lang/en.json b/lang/en.json index ad7c71c..4986b61 100644 --- a/lang/en.json +++ b/lang/en.json @@ -17,9 +17,10 @@ "description": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." } }, - "items": ["Coal", "Log", "Planks"], + "items": ["Dollars", "Log", "Planks"], "more": "show more...", "inventory": "Inventory", "player": "Player", - "infotooltips": ["Build", "Move", "Rotate", "Delete!", "", "Upgrade", "Information", "", "Go To Space!!"] + "infotooltips": ["Build", "Move", "Rotate", "Delete!", "Upgrade", "Information", "Go To Space!!", "", ""], + "cost": "Cost" }