User prompt
play victory sound at the end if profit > 0 and play failed sound if < 0
User prompt
play corresponding sounds when buying or selling
User prompt
increase and decrease should be played during the game not only on game preparation
User prompt
play increase and decrease sounds when value change
User prompt
play countdown sound during the initial countdown
User prompt
Migrate to the latest version of LK
Code edit (9 edits merged)
Please save this source code
User prompt
buyButton should be enabled only when mar = true (game running)
Code edit (2 edits merged)
Please save this source code
User prompt
Add a big 3 second countdown before starting game
User prompt
set the score to be the profit using LK.setScore()
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught LK.Game can only be initialized once' in or related to this line: 'var j = new LK.Game({});' Line Number: 301
Code edit (9 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'confetti.destroy();' Line Number: 353
Code edit (1 edits merged)
Please save this source code
User prompt
make confetti rotation random
Code edit (1 edits merged)
Please save this source code
User prompt
fix the conffetti colors not applying
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: game.getChildByName is not a function' in or related to this line: 'if (profit > 0 && !game.getChildByName('confetti')) {' Line Number: 333
User prompt
Confettiis called to much times
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: confettiColors is not defined' in or related to this line: 'var particle = self.addChild(LK.getAsset('segment', {' Line Number: 265
User prompt
in Confetti Change the ' Math.random() * 0xFFFFFF,' , use an array of colors instead
===================================================================
--- original.js
+++ change.js
@@ -1,170 +1,276 @@
/****
* Classes
****/
-var ConfettiParticle = Container.expand(function (t) {
- var self = Container.call(this);
- Container.call(this).attachAsset("confetti", {
- width: 40,
- height: 20,
- color: t,
- anchorX: .5,
- anchorY: .5
- }).rotation = Math.random() * Math.PI * 2;
- }),
- BalanceIcon = Container.expand(function () {
- Container.call(this).attachAsset("balanceIcon", {
- anchorX: .5,
- anchorY: .5
+var cp = Container.expand(function (color) {
+ var self = Container.call(this);
+ var confettiGraphics = self.attachAsset('confetti', {
+ width: 40,
+ height: 20,
+ color: color,
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ confettiGraphics.rotation = Math.random() * Math.PI * 2;
+});
+var bi = Container.expand(function () {
+ var self = Container.call(this);
+ var iconGraphics = self.attachAsset('balanceIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+var ti = Container.expand(function () {
+ var self = Container.call(this);
+ var iconGraphics = self.attachAsset('timerIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+var si = Container.expand(function () {
+ var self = Container.call(this);
+ var iconGraphics = self.attachAsset('stockIcon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+var al = Container.expand(function (value) {
+ var self = Container.call(this);
+ self.value = value;
+ var label = new Text2('$' + value, {
+ size: 70,
+ fill: "#ffffff"
+ });
+ label.anchor.set(0.5, 0.5);
+ self.addChild(label);
+ self.alpha = 0;
+ self.updatePosition = function (axisY) {
+ var newY = axisY - self.value * epx - alfs / 2;
+ if (newY > j.height * 0.82) {
+ self.value += (nbMarkers - 1) * 25;
+ label.setText('$' + self.value);
+ } else if (newY < j.height * 0.07) {
+ self.value -= (nbMarkers - 1) * 25;
+ label.setText('$' + self.value);
+ }
+ self.y = axisY - self.value * epx - alfs / 2;
+ };
+});
+var gs = Container.expand(function () {
+ var self = Container.call(this);
+ self.index1 = null;
+ self.stockValue1 = 0;
+ self.stockValue2 = 0;
+ self.x1 = 0;
+ self.y1 = 0;
+ self.x2 = 0;
+ self.y2 = 0;
+ self.isFinished = false;
+ var interpolationSpeed = .2;
+ self.updateSlide = function () {
+ if (ms) {
+ if (self.index1 == gi) {
+ var dynamicSlideAdjustment = Math.abs(self.x - j.width * 0.25) / (j.width * 0.5);
+ if (self.x < j.width * 0.35) {
+ sa = Math.max(1, sa * (1 - dynamicSlideAdjustment));
+ } else if (self.x > j.width * 0.65) {
+ sa = Math.min(15, sa * (1 + dynamicSlideAdjustment));
+ }
+ }
+ self.x -= sa * 1;
+ }
+ if (msv) {
+ var currentDelta = horizontalAxis.y - ll;
+ var targetY = ll - self.stockValue1 * epx + currentDelta;
+ var deltaY = (targetY - self.y) * interpolationSpeed;
+ self.y += deltaY;
+ if (Math.abs(deltaY) <= 1) {
+ self.y = targetY;
+ }
+ }
+ };
+ var segmentGraphics = self.attachAsset('segment', {
+ anchorY: 0.5
+ });
+});
+var ax = Container.expand(function (isVertical) {
+ var self = Container.call(this);
+ var interpolationSpeed = 0.02;
+ var lowerLimit = j.height * 0.75;
+ self.isVertical = isVertical;
+ self.yValue = 0;
+ self.updateSlide = function () {
+ var stockDelta = Math.max(0, svh[gi + 1] - 100);
+ var targetY = lowerLimit + stockDelta * epx;
+ if (!self.isVertical) {
+ var deltaY = (targetY - self.y) * interpolationSpeed;
+ self.y += deltaY;
+ if (Math.abs(deltaY) < 1) {
+ self.y = targetY;
+ }
+ if (msv && self.y <= lowerLimit) {
+ self.y = lowerLimit;
+ msv = 0;
+ }
+ self.alpha = self.y > j.height * 0.85 ? 0 : 1;
+ }
+ };
+ self.drawAxis = function () {
+ var axisGraphics = self.addChild(LK.getAsset('axis', {
+ height: 4
+ }));
+ };
+});
+var pr = Container.expand(function () {
+ var self = Container.call(this);
+ self.balance = 100;
+ self.stocks = 0;
+ self.orders = 0;
+ self.liquidate = function () {
+ while (self.stocks > 0) {
+ self.sellStock(1);
+ }
+ updateBalanceDisplay();
+ };
+ self.buyStock = function (quantity) {
+ var price = svh[gi];
+ var cost = price * quantity;
+ if (self.balance >= cost) {
+ self.balance -= cost;
+ self.stocks += quantity;
+ self.orders++;
+ sellButton.updateButtonState();
+ } else {
+ LK.effects.flashScreen(0xFF0000, 100);
+ }
+ };
+ self.sellStock = function (quantity) {
+ if (self.stocks > 0) {
+ var price = svh[gi];
+ self.balance += price * quantity;
+ self.stocks -= quantity;
+ self.orders++;
+ sellButton.updateButtonState();
+ }
+ };
+ self.getBalance = function () {
+ return self.balance;
+ };
+ self.getStockCount = function () {
+ return self.stocks;
+ };
+ self.getPortfolio = function () {
+ return self.stocks;
+ };
+});
+var bb = Container.expand(function () {
+ var self = Container.call(this);
+ self.currentText = "Buy";
+ self.updateButtonState = function () {
+ var stockPrice = svh[gi];
+ var canBuy = p.getBalance() >= stockPrice && stockPrice > 0;
+ this.alpha = canBuy ? 1 : 0.5;
+ this.interactive = canBuy;
+ };
+ self.setText = function (text, isPressed) {
+ self.currentText = text;
+ var buttonTextSize = isPressed ? 230 : 250;
+ var buttonText = new Text2(text, {
+ size: buttonTextSize,
+ fill: "#ffffff",
+ font: "'Arial-BoldMT', 'Arial', sans-serif"
});
- }),
- TimerIcon = Container.expand(function () {
- Container.call(this).attachAsset("timerIcon", {
- anchorX: .5,
- anchorY: .5
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ };
+ var buttonGraphics = self.attachAsset('bigButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0xFFA500
+ });
+ self.on('down', function () {
+ if (self.interactive) {
+ buttonGraphics = self.attachAsset('bigButtonPressed', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0xFFA500
+ });
+ LK.effects.flashScreen(0xFFA500, 100);
+ self.setText(self.currentText, true);
+ buyStock(1);
+ }
+ }).on('up', function () {
+ buttonGraphics = self.attachAsset('bigButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0xFFA500
});
- }),
- StockIcon = Container.expand(function () {
- Container.call(this).attachAsset("stockIcon", {
- anchorX: .5,
- anchorY: .5
+ self.setText(self.currentText);
+ self.updateButtonState();
+ });
+ self.updateButtonState();
+});
+var sb = Container.expand(function () {
+ var self = Container.call(this);
+ self.currentText = "ON";
+ self.setText = function (text, isPressed) {
+ self.currentText = text;
+ var buttonTextSize = isPressed ? 230 : 250;
+ var buttonText = new Text2(text, {
+ size: buttonTextSize,
+ fill: "#ffffff",
+ font: "'Arial-BoldMT', 'Arial', sans-serif"
});
- }),
- AxisLabel = Container.expand(function (t) {
- var a = Container.call(this);
- a.value = t;
- var n = new Text2("$" + t, {
- size: 70,
- fill: "#ffffff"
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ };
+ var buttonGraphics = self.attachAsset('bigButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0x008000
+ });
+ self.on('down', function () {
+ buttonGraphics = self.attachAsset('bigButtonPressed', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0x008000
});
- n.anchor.set(.5, .5), a.addChild(n), a.alpha = 0, a.updatePosition = function (t) {
- var e = t - a.value * dollarToYPixelRatio - axisLabelFontSize / 2;
- e > .82 * game.height ? (a.value += 25 * (nbMarkers - 1), n.setText("$" + a.value)) : e < .07 * game.height && (a.value -= 25 * (nbMarkers - 1), n.setText("$" + a.value)), a.y = t - a.value * dollarToYPixelRatio - axisLabelFontSize / 2;
- };
- }),
- GraphSegment = Container.expand(function () {
- var a = Container.call(this);
- a.index1 = null, a.stockValue1 = 0, a.stockValue2 = 0, a.x1 = 0, a.y1 = 0, a.x2 = 0, a.y2 = 0, a.isFinished = !1;
- a.updateSlide = function () {
- var t, e;
- moveSegments && (a.index1 == graphIndex && (t = Math.abs(a.x - .25 * game.width) / (.5 * game.width), a.x < .35 * game.width ? slideAmount = Math.max(1, slideAmount * (1 - t)) : a.x > .65 * game.width && (slideAmount = Math.min(15, slideAmount * (1 + t)))), a.x -= +slideAmount), moveSegmentsVertically && (e = horizontalAxis.y - lowerLimit, e = .2 * ((t = lowerLimit - a.stockValue1 * dollarToYPixelRatio + e) - a.y), a.y += e, Math.abs(e) <= 1 && (a.y = t));
- };
- a.attachAsset('segment', {
- anchorY: .5
+ LK.effects.flashScreen(0x008000, 100);
+ self.setText(self.currentText, true);
+ sellStock(1);
+ }).on('up', function () {
+ buttonGraphics = self.attachAsset('bigButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: 0x008000
});
- }),
- Axis = Container.expand(function (t) {
- var a = Container.call(this),
- n = .75 * game.height;
- a.isVertical = t, a.yValue = 0, a.updateSlide = function () {
- var t = Math.max(0, stockValuesHistory[graphIndex + 1] - 100),
- e = n + t * dollarToYPixelRatio;
- a.isVertical || (t = .02 * (e - a.y), a.y += t, Math.abs(t) < 1 && (a.y = e), moveSegmentsVertically && a.y <= n && (a.y = n, moveSegmentsVertically = 0), a.alpha = a.y > .85 * game.height ? 0 : 1);
- }, a.drawAxis = function () {
- a.addChild(LK.getAsset('axis', {
- height: 4
- }));
- };
- }),
- Player = Container.expand(function () {
- var a = Container.call(this);
- a.balance = 100, a.stocks = 0, a.orders = 0, a.liquidate = function () {
- for (; 0 < a.stocks;) {
- a.sellStock(1);
+ self.setText(self.currentText);
+ });
+});
+var cf = Container.expand(function () {
+ var self = Container.call(this);
+ self.particles = [];
+ var confettiColors = [0xFF0000, 0xFF7F00, 0xFFFF00, 0x00FF00, 0x0000FF, 0x4B0082, 0x9400D3];
+ for (var i = 0; i < 50; i++) {
+ var particle = self.addChild(new cp(confettiColors[i % confettiColors.length]));
+ particle.x = Math.random() * j.width;
+ particle.y = Math.random() * j.height;
+ particle.vx = (Math.random() - 0.5) * 10;
+ particle.vy = (Math.random() - 0.5) * 10;
+ self.particles.push(particle);
+ }
+ self.update = function () {
+ self.particles.forEach(function (particle) {
+ particle.x += particle.vx;
+ particle.y += particle.vy;
+ particle.vy += 0.2;
+ if (particle.y > j.height) {
+ particle.y = 0;
+ particle.vy = (Math.random() - 0.5) * 10;
}
- updateBalanceDisplay();
- }, a.buyStock = function (t) {
- var e = stockValuesHistory[graphIndex] * t;
- a.balance >= e ? (a.balance -= e, a.stocks += t, a.orders++, sellButton.updateButtonState()) : LK.effects.flashScreen(16711680, 100);
- }, a.sellStock = function (t) {
- var e;
- 0 < a.stocks && (e = stockValuesHistory[graphIndex], a.balance += e * t, a.stocks -= t, a.orders++, sellButton.updateButtonState());
- }, a.getBalance = function () {
- return a.balance;
- }, a.getStockCount = function () {
- return a.stocks;
- }, a.getPortfolio = function () {
- return a.stocks;
- };
- }),
- BuyButton = Container.expand(function () {
- var a = Container.call(this);
- a.currentText = "Buy", a.updateButtonState = function () {
- var t = stockValuesHistory[graphIndex],
- t = player.getBalance() >= t && 0 < t;
- this.alpha = t ? 1 : .5, this.interactive = t;
- }, a.setText = function (t, e) {
- a.currentText = t;
- e = new Text2(t, {
- size: e ? 230 : 250,
- fill: "#ffffff",
- font: "'Arial-BoldMT', 'Arial', sans-serif"
- });
- e.anchor.set(.5, .5), a.addChild(e);
- };
- a.attachAsset('bigButton', {
- anchorX: .5,
- anchorY: .5,
- tint: 16753920
});
- a.on("down", function () {
- a.interactive && (a.attachAsset('bigButtonPressed', {
- anchorX: .5,
- anchorY: .5,
- tint: 16753920
- }), LK.effects.flashScreen(16753920, 100), a.setText(a.currentText, !0), buyStock(1));
- }).on("up", function () {
- a.attachAsset('bigButton', {
- anchorX: .5,
- anchorY: .5,
- tint: 16753920
- }), a.setText(a.currentText), a.updateButtonState();
- }), a.updateButtonState();
- }),
- SellButton = Container.expand(function () {
- var a = Container.call(this);
- a.currentText = "ON", a.setText = function (t, e) {
- a.currentText = t;
- e = new Text2(t, {
- size: e ? 230 : 250,
- fill: "#ffffff",
- font: "'Arial-BoldMT', 'Arial', sans-serif"
- });
- e.anchor.set(.5, .5), a.addChild(e);
- };
- a.attachAsset('bigButton', {
- anchorX: .5,
- anchorY: .5,
- tint: 32768
- });
- a.on("down", function () {
- a.attachAsset('bigButtonPressed', {
- anchorX: .5,
- anchorY: .5,
- tint: 32768
- }), LK.effects.flashScreen(32768, 100), a.setText(a.currentText, !0), sellStock(1);
- }).on("up", function () {
- a.attachAsset('bigButton', {
- anchorX: .5,
- anchorY: .5,
- tint: 32768
- }), a.setText(a.currentText);
- });
- }),
- Confetti = Container.expand(function () {
- var t = Container.call(this);
- t.particles = [];
- for (var e = [16711680, 16744192, 16776960, 65280, 255, 4915330, 9699539], a = 0; a < 50; a++) {
- var n = t.addChild(new ConfettiParticle(e[a % e.length]));
- n.x = Math.random() * game.width, n.y = Math.random() * game.height, n.vx = 10 * (Math.random() - .5), n.vy = 10 * (Math.random() - .5), t.particles.push(n);
- }
- t.update = function () {
- t.particles.forEach(function (t) {
- t.x += t.vx, t.y += t.vy, t.vy += .2, t.y > game.height && (t.y = 0, t.vy = 10 * (Math.random() - .5));
- });
- };
- }),
- game = new LK.Game({});
+ };
+});
/****
* Initialize Game
****/
@@ -174,203 +280,331 @@
/****
* Game Code
****/
-function confettiExists() {
- return game.children.some(function (t) {
- return "confetti" === t.name;
+var j = game;
+function ce() {
+ return j.children.some(function (child) {
+ return child.name === 'confetti';
});
}
-function gameResult() {
- player.liquidate();
- var t = player.getBalance() - initialAmount,
- e = game.addChild(LK.getAsset('popup', {
- anchorX: .5,
- anchorY: .5
- }));
- e.x = game.width / 2, e.y = game.height / 2 - 300, resultText = "Initial:\t$" + initialAmount + "\r\nFinal:\t\t$" + player.getBalance().toFixed(0) + "\r\nProfit:";
- e = new Text2(resultText, {
+function gr() {
+ p.liquidate();
+ var profit = p.getBalance() - md;
+ var popup = j.addChild(LK.getAsset('popup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ popup.x = j.width / 2;
+ popup.y = j.height / 2 - 300;
+ resultText = 'Initial:\t$' + md + '\r\n' + 'Final:\t\t$' + p.getBalance().toFixed(0) + '\r\n' + 'Profit:';
+ var finalBalanceText = new Text2(resultText, {
size: 100,
fill: "#ffffff",
- anchorX: .5,
- anchorY: .5
+ anchorX: 0.5,
+ anchorY: 0.5
});
- e.x = game.width / 2 - 500, e.y = game.height / 2 - 900, game.addChild(e);
- var a,
- e = 0 < t ? "#00ff00" : t < 0 ? "#ff0000" : "#ffffff",
- e = new Text2("$" + t.toFixed(0), {
- size: 200,
- fill: e,
- anchorX: .5,
- anchorY: .5
+ finalBalanceText.x = j.width / 2 - 500;
+ finalBalanceText.y = j.height / 2 - 900;
+ j.addChild(finalBalanceText);
+ var profitTextColor = profit > 0 ? '#00ff00' : profit < 0 ? '#ff0000' : '#ffffff';
+ var profitText = new Text2('$' + profit.toFixed(0), {
+ size: 200,
+ fill: profitTextColor,
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ profitText.x = j.width / 2 - 220;
+ profitText.y = j.height / 2 - 700;
+ j.addChild(profitText);
+ if (profit > 0 && !ce()) {
+ var confetti = j.addChild(new cf());
+ confetti.name = 'confetti';
+ LK.on('tick', function () {
+ confetti.update();
});
- e.x = game.width / 2 - 220, e.y = game.height / 2 - 700, game.addChild(e), 0 < t && !confettiExists() && ((a = game.addChild(new Confetti())).name = "confetti", LK.on("tick", function () {
- a.update();
- })), LK.setTimeout(function () {
- LK.showGameOver(), 0 < t && confettiExists() && a.destroy();
- }, 3e3);
+ }
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ if (profit > 0 && ce()) {
+ confetti.destroy();
+ }
+ }, 3000);
}
-var debug = !1,
- slideAmount = 6.5,
- slideAmountVertical = .1,
- moveSegmentsVertically = 0,
- verticalSlideThreshold = 500,
- upperLimit = .5 * game.height,
- lowerLimit = .75 * game.height,
- axisLabelFontSize = 70,
- running = !1,
- moveSegments = !1,
- drawingInProgress = !1,
- player = new Player(),
- nbTotalValues = 180,
- stocks = [],
- stockValuesHistory = [50],
- graphIndex = 0,
- graphSegments = [],
- currentStock = null,
- graphPoints = [],
- graphWidth = game.width,
- segmentWidth = graphWidth / 5,
- dollarToYPixelRatio = .5 * game.height / 100,
- initialAmount = 100,
- beginingValueDelta = 10,
- maxValueDelta = 100,
- segmentDrawInterval = null,
- secondsPerSegment = 2,
- stockDisplay = [],
- farBackground = game.addChild(LK.getAsset('farBackground', {
- anchorX: .5,
- anchorY: .5,
- alpha: .25
- }));
-farBackground.x = game.width / 2, farBackground.y = game.height / 2;
-var boardBackground = game.addChild(LK.getAsset('board', {
- anchorX: .5,
- anchorY: .5
+var sa = 6.5;
+var sav = 0.10;
+var msv = 0;
+var vst = 500;
+var ul = j.height * 0.5;
+var ll = j.height * 0.75;
+var alfs = 70;
+var mar = false;
+var ms = false;
+var dip = false;
+var p = new pr();
+var ntv = 180;
+var ss = [];
+var svh = [50];
+var gi = 0;
+var gss = [];
+var cs = null;
+var gp = [];
+var jl = j.width;
+var sl = jl / 5;
+var epx = j.height * 0.5 / 100;
+var md = 100;
+var mde = 10;
+var dmx = 100;
+var sdi = null;
+var sps = 2.0;
+var sds = [];
+var farBackground = j.addChild(LK.getAsset('farBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.25
}));
-boardBackground.x = game.width / 2, boardBackground.y = .9 * game.height;
-var boardBorder = game.addChild(LK.getAsset('boardBorder', {
- anchorX: .5,
- anchorY: .5
+farBackground.x = j.width / 2;
+farBackground.y = j.height / 2;
+var boardBackground = j.addChild(LK.getAsset('board', {
+ anchorX: 0.5,
+ anchorY: 0.5
}));
-boardBorder.x = game.width / 2, boardBorder.y = .85 * game.height;
-var background = game.addChild(LK.getAsset('background', {
- anchorX: .5,
- anchorY: .5
+boardBackground.x = j.width / 2;
+boardBackground.y = j.height * 0.9;
+var boardBorder = j.addChild(LK.getAsset('boardBorder', {
+ anchorX: 0.5,
+ anchorY: 0.5
}));
-background.x = 1024, background.y = 2732 * .71;
-var horizontalAxis = game.addChild(new Axis(!1));
-horizontalAxis.yValue = .75 * game.height, horizontalAxis.drawAxis(), horizontalAxis.y = horizontalAxis.yValue, horizontalAxis.width = game.width, horizontalAxis.height = 10, horizontalAxis.x = 0;
-var verticalAxis = new Axis(!0);
-verticalAxis.drawAxis(), verticalAxis.rotation = Math.PI / 2, verticalAxis.x = 20, verticalAxis.width = game.height, verticalAxis.height = 10, verticalAxis.y = 0;
-for (var axisLabels = [], nbMarkers = 7, i = 0; i < nbMarkers; i++) {
- var axisLabel = new AxisLabel(25 * i);
- axisLabel.x = verticalAxis.x + 60, axisLabel.updatePosition(horizontalAxis.y), axisLabel.alpha = 1, axisLabels.push(axisLabel), game.addChild(axisLabel);
+boardBorder.x = j.width / 2;
+boardBorder.y = j.height * 0.85;
+var background = j.addChild(LK.getAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+background.x = 1024;
+background.y = 2732 * 0.71;
+var horizontalAxis = j.addChild(new ax(false));
+horizontalAxis.yValue = j.height * 0.75;
+horizontalAxis.drawAxis();
+horizontalAxis.y = horizontalAxis.yValue;
+horizontalAxis.width = j.width;
+horizontalAxis.height = 10;
+horizontalAxis.x = 0;
+var verticalAxis = new ax(true);
+verticalAxis.drawAxis();
+verticalAxis.rotation = Math.PI / 2;
+verticalAxis.x = 20;
+verticalAxis.width = j.height;
+verticalAxis.height = 10;
+verticalAxis.y = 0;
+var axisLabels = [];
+var nbMarkers = 7;
+for (var i = 0; i < nbMarkers; i++) {
+ var axisLabel = new al(i * 25);
+ axisLabel.x = verticalAxis.x + 60;
+ axisLabel.updatePosition(horizontalAxis.y);
+ axisLabel.alpha = 1;
+ axisLabels.push(axisLabel);
+ j.addChild(axisLabel);
}
-var buyButton = game.addChild(new BuyButton());
-buyButton.setText("Buy"), buyButton.x = .25 * game.width, buyButton.y = game.height - buyButton.height / 2 - 20;
-var sellButton = game.addChild(new SellButton());
-sellButton.setText("Sell"), sellButton.x = .75 * game.width, sellButton.y = game.height - sellButton.height / 2 - 20, sellButton.updateButtonState = function () {
- 0 < player.getStockCount() ? (this.alpha = 1, this.interactive = !0) : (this.alpha = .5, this.interactive = !1);
-}, sellButton.updateButtonState();
-var timerIcon = game.addChild(new TimerIcon()),
- timerText = new Text2("000", {
- size: 100,
- fill: "#ffffff",
- anchorX: .5
- });
-timerText.anchor.set(-.95, -.7), LK.gui.topLeft.addChild(timerText), timerIcon.x = .165 * game.width, timerIcon.y = .025 * game.height;
-var balanceIcon = game.addChild(new BalanceIcon());
-balanceIcon.x = .5 * game.width, balanceIcon.y = .025 * game.height;
-var stockIcon = game.addChild(new StockIcon());
-stockIcon.x = .94 * game.width, stockIcon.y = .028 * game.height;
-var balanceText = new Text2("$" + player.getBalance() + " ", {
+var buyButton = j.addChild(new bb());
+buyButton.setText('Buy');
+buyButton.x = j.width * 0.25;
+buyButton.y = j.height - buyButton.height / 2 - 20;
+var sellButton = j.addChild(new sb());
+sellButton.setText('Sell');
+sellButton.x = j.width * 0.75;
+sellButton.y = j.height - sellButton.height / 2 - 20;
+sellButton.updateButtonState = function () {
+ if (p.getStockCount() > 0) {
+ this.alpha = 1;
+ this.interactive = true;
+ } else {
+ this.alpha = 0.5;
+ this.interactive = false;
+ }
+};
+sellButton.updateButtonState();
+var timerIcon = j.addChild(new ti());
+var timerText = new Text2('000', {
size: 100,
fill: "#ffffff",
- anchorX: .5
+ anchorX: 0.5
});
-balanceText.anchor.set(.5, -.7), LK.gui.top.addChild(balanceText);
-var stocksNumber = new Text2(player.getPortfolio(), {
+timerText.anchor.set(-.95, -0.7);
+LK.gui.topLeft.addChild(timerText);
+timerIcon.x = j.width * 0.165;
+timerIcon.y = j.height * 0.025;
+var balanceIcon = j.addChild(new bi());
+balanceIcon.x = j.width * 0.5;
+balanceIcon.y = j.height * 0.025;
+var stockIcon = j.addChild(new si());
+stockIcon.x = j.width * 0.94;
+stockIcon.y = j.height * 0.028;
+var balanceText = new Text2('$' + p.getBalance() + ' ', {
size: 100,
fill: "#ffffff",
- anchorX: .5
+ anchorX: 0.5
});
-stocksNumber.anchor.set(1.6, -.7), LK.gui.topRight.addChild(stocksNumber);
-var verticalSlideAmount = 0,
- vsaText = new Text2("", {
- size: 50,
- fill: "#ffffff"
- });
-vsaText.anchor.set(0, 0), LK.gui.topLeft.addChild(vsaText);
-var stockValueText = new Text2("", {
+balanceText.anchor.set(.5, -0.7);
+LK.gui.top.addChild(balanceText);
+var stocksNumber = new Text2(p.getPortfolio(), {
+ size: 100,
+ fill: "#ffffff",
+ anchorX: 0.5
+});
+stocksNumber.anchor.set(1.6, -0.7);
+LK.gui.topRight.addChild(stocksNumber);
+var verticalSlideAmount = 0;
+var vsaText = new Text2('', {
+ size: 50,
+ fill: "#ffffff"
+});
+vsaText.anchor.set(0, 0);
+LK.gui.topLeft.addChild(vsaText);
+var stockValueText = new Text2('', {
size: 75,
fill: "#FFFFFF"
});
+stockValueText.anchor.set(1, 2);
+stockValueText.alpha = 0;
+LK.gui.right.addChild(stockValueText);
function updateStockValueText() {
- graphIndex < stockValuesHistory.length && stockValueText.setText("$" + stockValuesHistory[graphIndex + 1].toFixed(0));
+ if (gi < svh.length) {
+ stockValueText.setText('$' + svh[gi + 1].toFixed(0));
+ }
}
function updateBalanceDisplay() {
- balanceText.setText("$" + player.getBalance() + " "), stocksNumber.setText(player.getStockCount()), buyButton.updateButtonState();
+ balanceText.setText('$' + p.getBalance() + ' ');
+ stocksNumber.setText(p.getStockCount());
+ buyButton.updateButtonState();
}
-function buyStock(t) {
- player.buyStock(t, 1), updateBalanceDisplay();
+function buyStock(stock) {
+ p.buyStock(stock, 1);
+ updateBalanceDisplay();
}
-function sellStock(t) {
- player.sellStock(t, 1), updateBalanceDisplay();
+function sellStock(stock) {
+ p.sellStock(stock, 1);
+ updateBalanceDisplay();
}
-function drawNextSegment() {
- var t, e, a, n, i, o;
- graphIndex >= graphPoints.length - 1 ? gameResult() : drawingInProgress || (updateStockValueText(), buyButton.updateButtonState(), t = graphPoints[graphIndex], e = (i = graphPoints[graphIndex + 1]).y - t.y, o = i.x - t.x, a = Math.atan2(e, o), n = Math.sqrt(Math.pow(i.x - t.x, 2) + Math.pow(i.y - t.y, 2)), i = (o = 0 < graphSegments.length ? graphSegments[graphSegments.length - 1] : null) ? o.x + Math.cos(o.rotation) * o.width : graphPoints[graphIndex].x, o = o ? o.y + Math.sin(o.rotation) * o.width : graphPoints[graphIndex].y, t.x = i, t.y = lowerLimit < o ? lowerLimit : o, o = t.y + Math.sin(a) * n, lowerLimit < o && (n = (lowerLimit - t.y) / Math.sin(a)), moveSegmentsVertically = o < upperLimit || o >= .5 * game.height && 100 <= stockValuesHistory[graphIndex + 1] && 0 != e ? -1 * Math.sign(e) : 0, drawingInProgress = !0, drawSegment(game, graphIndex, t.x, t.y, a, n, .5));
+function dss() {
+ var hasFinished = gi >= gp.length - 1;
+ if (hasFinished) {
+ gr();
+ return;
+ }
+ if (!dip) {
+ updateStockValueText();
+ buyButton.updateButtonState();
+ var pointA = gp[gi];
+ var pointB = gp[gi + 1];
+ var deltaY = pointB.y - pointA.y;
+ var deltaX = pointB.x - pointA.x;
+ var nextSegmentRotation = Math.atan2(deltaY, deltaX);
+ if (deltaX < 0 || deltaY > 0) {}
+ var distance = Math.sqrt(Math.pow(pointB.x - pointA.x, 2) + Math.pow(pointB.y - pointA.y, 2));
+ var lastSegment = gss.length > 0 ? gss[gss.length - 1] : null;
+ var lastSegmentEndX = lastSegment ? lastSegment.x + Math.cos(lastSegment.rotation) * lastSegment.width : gp[gi].x;
+ var lastSegmentEndY = lastSegment ? lastSegment.y + Math.sin(lastSegment.rotation) * lastSegment.width : gp[gi].y;
+ pointA.x = lastSegmentEndX;
+ pointA.y = lastSegmentEndY > ll ? ll : lastSegmentEndY;
+ var nextSegmentEndY = pointA.y + Math.sin(nextSegmentRotation) * distance;
+ if (nextSegmentEndY > ll) {
+ distance = (ll - pointA.y) / Math.sin(nextSegmentRotation);
+ }
+ if (nextSegmentEndY < ul || nextSegmentEndY >= j.height * 0.5 && svh[gi + 1] >= 100 && deltaY != 0) {
+ msv = -1 * Math.sign(deltaY);
+ } else {
+ msv = 0;
+ }
+ var delay = 0.5;
+ dip = true;
+ dar(j, gi, pointA.x, pointA.y, nextSegmentRotation, distance, delay);
+ }
}
-function drawSegment(t, e, a, n, i, o, r) {
- var s = t.addChild(new GraphSegment());
- s.index1 = e, s.stockValue1 = stockValuesHistory[e], s.stockValue2 = stockValuesHistory[e + 1], s.x1 = a, s.y1 = n, s.rotation = i, s.width = 1, s.height = 20, graphSegments.push(s), s.x = a, s.y = n;
- var l = Date.now(),
- h = l + 1e3 * r * secondsPerSegment;
- (function t() {
- var e, a;
- running && (a = (e = Date.now()) - l, a = Math.min(a / (1e3 * r * secondsPerSegment) * o, o), s.width = a, e < h ? LK.setTimeout(t, 16) : (!moveSegments && s.x + s.width / 2 >= .5 * game.width && (moveSegments = !0), s.isFinished = !0, graphIndex++, drawingInProgress = !1));
- })();
+function dar(gameRef, index, x1, y1, rotation, width, delay) {
+ var segment = gameRef.addChild(new gs());
+ segment.index1 = index;
+ segment.stockValue1 = svh[index];
+ segment.stockValue2 = svh[index + 1];
+ segment.x1 = x1;
+ segment.y1 = y1;
+ segment.rotation = rotation;
+ segment.width = 1;
+ segment.height = 20;
+ gss.push(segment);
+ segment.x = x1;
+ segment.y = y1;
+ var startTime = Date.now();
+ var endTime = startTime + delay * 1000 * sps;
+ var mlg = function mlg() {
+ if (!mar) {
+ return;
+ }
+ var currentTime = Date.now();
+ var timeElapsed = currentTime - startTime;
+ var newWidth = Math.min(timeElapsed / (delay * 1000 * sps) * width, width);
+ segment.width = newWidth;
+ if (currentTime < endTime) {
+ LK.setTimeout(mlg, 16);
+ } else {
+ if (!ms && segment.x + segment.width / 2 >= j.width * 0.5) {
+ ms = true;
+ }
+ segment.isFinished = true;
+ gi++;
+ dip = false;
+ }
+ };
+ mlg();
}
-function setDebugValues() {
- stockValuesHistory = [];
- for (var t = [1, 50, 1], e = 0; e < 1; e++) {
- stockValuesHistory = stockValuesHistory.concat(t);
+function sj() {
+ var previousValue = svh[svh.length - 1];
+ for (var i = 0; i < 5; i++) {
+ var delta = Math.floor((Math.random() - 0.5) * mde);
+ var newValue = Math.max(1, previousValue + (previousValue == 1 ? Math.abs(delta) : delta));
+ svh.push(newValue);
+ previousValue = newValue;
}
-}
-function startGame() {
- for (var t = stockValuesHistory[stockValuesHistory.length - 1], e = 0; e < 5; e++) {
- var a = Math.floor((Math.random() - .5) * beginingValueDelta),
- n = Math.max(1, t + (1 == t ? Math.abs(a) : a));
- stockValuesHistory.push(n), t = n;
+ previousValue = svh[svh.length - 1];
+ for (var i = 5; i < ntv; i++) {
+ var delta = Math.floor((Math.random() - 0.5) * dmx);
+ var newValue = Math.max(1, previousValue + (previousValue == 1 ? Math.abs(delta) : delta));
+ svh.push(newValue);
+ previousValue = newValue;
}
- t = stockValuesHistory[stockValuesHistory.length - 1];
- for (var i, o, e = 5; e < nbTotalValues; e++) {
- a = Math.floor((Math.random() - .5) * maxValueDelta), n = Math.max(1, t + (1 == t ? Math.abs(a) : a));
- stockValuesHistory.push(n), t = n;
- }
- buyButton.updateButtonState(), debug && setDebugValues();
- for (e = 0; e < stockValuesHistory.length; e++) {
- i = segmentWidth * e, o = .75 * game.height - stockValuesHistory[e] * dollarToYPixelRatio, graphPoints.push({
- x: i,
- y: o
+ buyButton.updateButtonState();
+ var x, y;
+ for (var i = 0; i < svh.length; i++) {
+ x = sl * i;
+ y = j.height * 0.75 - svh[i] * epx;
+ gp.push({
+ x: x,
+ y: y
});
}
- running = !0, LK.setTimeout(function () {
+ mar = true;
+ LK.setTimeout(function () {
stockValueText.alpha = 1;
- }, 100), segmentDrawInterval = LK.setInterval(drawNextSegment, 10);
- LK.setInterval(function () {
- var t = Math.max(0, nbTotalValues - graphIndex - 1);
- timerText.setText(t.toString().padStart(3, "0"));
- }, 1e3);
+ }, 100);
+ sdi = LK.setInterval(dss, 10);
+ var timerUpdateInterval = LK.setInterval(function () {
+ var currentTime = Math.max(0, ntv - gi - 1);
+ timerText.setText(currentTime.toString().padStart(3, '0'));
+ }, 1000);
}
-stockValueText.anchor.set(1, 2), stockValueText.alpha = 0, LK.gui.right.addChild(stockValueText), LK.on("tick", function () {
- running && (graphSegments.forEach(function (t) {
- t.updateSlide();
- }), horizontalAxis.updateSlide(), axisLabels.forEach(function (t) {
- t.updatePosition(horizontalAxis.y);
- }), debug && vsaText.setText(graphIndex + " Mvt " + moveSegmentsVertically));
+LK.on('tick', function () {
+ if (!mar) {
+ return;
+ }
+ gss.forEach(function (segment) {
+ segment.updateSlide();
+ });
+ horizontalAxis.updateSlide();
+ axisLabels.forEach(function (label) {
+ label.updatePosition(horizontalAxis.y);
+ });
});
var startTime = Date.now();
LK.setTimeout(function () {
- startGame();
-}, 1e3);
\ No newline at end of file
+ sj();
+}, 1000);
\ No newline at end of file
A Technical dark background. Nothing just a gradiant of colors from black to dark blue. Theme : stock market. background
A modern clean empty rectangular button without borders. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
without shadow
a basic empty ui popup with a black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.