/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ // Button class to handle button creation and interaction var Button = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5, text: 'generate number' }); self.down = function (x, y, obj) { // Generate a random number between 1 and 1000 with different probabilities for 1-2 digit, 3 digit and 4 digit numbers var randomNumber; var randomChance = Math.random(); if (randomChance < 0.6) { // 60% chance to generate a 1-2 digit number randomNumber = Math.floor(Math.random() * 100) + 1; } else if (randomChance < 0.95) { // 35% chance to generate a 3 digit number randomNumber = Math.floor(Math.random() * 900) + 100; } else { // 5% chance to generate a 4 digit number randomNumber = Math.floor(Math.random() * 9000) + 1000; } // Update the score text with the new random number scoreTxt.setText(randomNumber); // Check if the new random number is a new high score if (randomNumber > storage.highScore) { storage.highScore = randomNumber; highScoreTxt.setText("High Score: " + storage.highScore); } // Add a tween effect to the button tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 100, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xADD8E6 //Init game with light blue background }); /**** * Game Code ****/ //<Assets used in the game will automatically appear here> var background = game.addChild(LK.getAsset('background', { width: 2048, height: 2732 })); // Initialize variables var highScore = storage.highScore; LK.playMusic('casinoMusic'); // Create and position the button var button = game.addChild(new Button()); button.x = 2048 / 2; button.y = 2732 / 2; // Create score text to display the random number var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF, font: "'Comic Sans MS', cursive, sans-serif" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create high score text to display the highest number achieved var highScoreTxt = new Text2('High Score: ' + storage.highScore, { size: 100, fill: 0xFFFFFF, font: "'Comic Sans MS', cursive, sans-serif" }); highScoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(highScoreTxt); highScoreTxt.y = 150; // Update function to handle game logic game.update = function () { // Game logic can be added here if needed };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
// Button class to handle button creation and interaction
var Button = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
text: 'generate number'
});
self.down = function (x, y, obj) {
// Generate a random number between 1 and 1000 with different probabilities for 1-2 digit, 3 digit and 4 digit numbers
var randomNumber;
var randomChance = Math.random();
if (randomChance < 0.6) {
// 60% chance to generate a 1-2 digit number
randomNumber = Math.floor(Math.random() * 100) + 1;
} else if (randomChance < 0.95) {
// 35% chance to generate a 3 digit number
randomNumber = Math.floor(Math.random() * 900) + 100;
} else {
// 5% chance to generate a 4 digit number
randomNumber = Math.floor(Math.random() * 9000) + 1000;
}
// Update the score text with the new random number
scoreTxt.setText(randomNumber);
// Check if the new random number is a new high score
if (randomNumber > storage.highScore) {
storage.highScore = randomNumber;
highScoreTxt.setText("High Score: " + storage.highScore);
}
// Add a tween effect to the button
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xADD8E6 //Init game with light blue background
});
/****
* Game Code
****/
//<Assets used in the game will automatically appear here>
var background = game.addChild(LK.getAsset('background', {
width: 2048,
height: 2732
}));
// Initialize variables
var highScore = storage.highScore;
LK.playMusic('casinoMusic');
// Create and position the button
var button = game.addChild(new Button());
button.x = 2048 / 2;
button.y = 2732 / 2;
// Create score text to display the random number
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF,
font: "'Comic Sans MS', cursive, sans-serif"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create high score text to display the highest number achieved
var highScoreTxt = new Text2('High Score: ' + storage.highScore, {
size: 100,
fill: 0xFFFFFF,
font: "'Comic Sans MS', cursive, sans-serif"
});
highScoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(highScoreTxt);
highScoreTxt.y = 150;
// Update function to handle game logic
game.update = function () {
// Game logic can be added here if needed
};