Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Delete battle button. Add Normal Attack by Clicking
Code edit (7 edits merged)
Please save this source code
User prompt
Free syria add turkey as neighbors
User prompt
Add Free Syria with 30 power
User prompt
Although I have a power of 137, I cannot capture some countries, for example, I have a lot of power with Turkey, but I cannot defeat Hungary, if my strength is more than 100, add to take each country directly, that is, when you press the Battle button and click on a country, add that country directly to your country
User prompt
Change the name of your Serbia to Yugosnavia and make Power 50
User prompt
Make Turkey Name Turkiye And add Bulgaria to neighbors
User prompt
Delete Normal Fighting, let's fight only when you press the button
User prompt
When we click the button,Can fight
User prompt
We can fight even when we don't click the button. Just click the button and we'll be able to fight
User prompt
When we select a state, there are buttons at the bottom right, 1.Button-Battle button, if we click on the button, then it asks us to click on a state, if we are stronger than the state we clicked, let's take over it. But if we are weaker,we lose.
User prompt
As much our power can, we can take over that country (Let's say our total strength is 70,We cant take Russia)
Code edit (1 edits merged)
Please save this source code
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Country = Container.expand(function (name, x, y, power, neighbors) {
var self = Container.call(this);
self.countryName = name;
self.power = power;
self.neighbors = neighbors || [];
self.owner = 'neutral'; // 'player', 'enemy', 'neutral'
self.isSelected = false;
// Create visual representation
self.graphics = self.attachAsset('neutralCountry', {
anchorX: 0.5,
anchorY: 0.5
});
// Country name text
self.nameText = new Text2(name, {
size: 24,
fill: 0x000000
});
self.nameText.anchor.set(0.5, 0.5);
self.nameText.y = -15;
self.addChild(self.nameText);
// Power text
self.powerText = new Text2(power.toString(), {
size: 20,
fill: 0x000000
});
self.powerText.anchor.set(0.5, 0.5);
self.powerText.y = 15;
self.addChild(self.powerText);
self.x = x;
self.y = y;
self.updateVisual = function () {
var newAsset = 'neutralCountry';
if (self.owner === 'player') {
newAsset = 'playerCountry';
} else if (self.owner === 'enemy') {
newAsset = 'enemyCountry';
} else if (self.isSelected) {
newAsset = 'selectedCountry';
}
self.removeChild(self.graphics);
self.graphics = self.attachAsset(newAsset, {
anchorX: 0.5,
anchorY: 0.5
});
// Re-add texts on top
self.removeChild(self.nameText);
self.removeChild(self.powerText);
self.addChild(self.nameText);
self.addChild(self.powerText);
self.powerText.setText(self.power.toString());
};
self.down = function (x, y, obj) {
if (gameState === 'selection') {
selectCountry(self);
} else if (gameState === 'playing') {
if (battleState === 'selecting_target') {
// Battle mode - attack the selected country
if (self.owner === 'neutral' || self.owner === 'enemy') {
performBattle(self);
battleState = 'none';
instructionText.setText('Conquer neighboring territories!');
battleButton.setText('BATTLE');
}
} else {
// Only allow selecting player countries for battle
if (self.owner === 'player') {
selectCountryForBattle(self);
}
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x4682B4
});
/****
* Game Code
****/
// Estonia already exists in the game with power 35 at position (1200, 800)
// with neighbors: Finland, Latvia, Russia
// No changes needed as the country is already implemented
var mapBg = game.attachAsset('mapBackground', {
anchorX: 0.5,
anchorY: 0.5
});
mapBg.x = 1024;
mapBg.y = 1366;
var gameState = 'selection'; // 'selection', 'playing', 'gameOver'
var battleState = 'none'; // 'none', 'selecting_target'
var playerCountry = null;
var countries = [];
var playerPower = 0;
var conqueredCount = 0;
var totalCountries = 0;
var battleButton = null;
var selectedCountryForUI = null;
// European countries data (positioned to accurately match the map background)
var countryData = [{
name: 'Iceland',
x: 400,
y: 300,
power: 1,
neighbors: ['Norway']
}, {
name: 'Ireland',
x: 340,
y: 1250,
power: 30,
neighbors: ['UK']
}, {
name: 'UK',
x: 570,
y: 1300,
power: 65,
neighbors: ['France', 'Ireland']
}, {
name: 'Portugal',
x: 90,
y: 2100,
power: 35,
neighbors: ['Spain']
}, {
name: 'Spain',
x: 300,
y: 2150,
power: 55,
neighbors: ['France', 'Portugal']
}, {
name: 'France',
x: 600,
y: 1700,
power: 70,
neighbors: ['Germany', 'Spain', 'Italy', 'UK', 'Belgium', 'Switzerland', 'Luxembourg']
}, {
name: 'Belgium',
x: 750,
y: 1500,
power: 40,
neighbors: ['Netherlands', 'France', 'Luxembourg']
}, {
name: 'Luxembourg',
x: 800,
y: 1600,
power: 20,
neighbors: ['Belgium', 'France', 'Germany']
}, {
name: 'Netherlands',
x: 750,
y: 1400,
power: 45,
neighbors: ['Germany', 'Belgium']
}, {
name: 'Switzerland',
x: 780,
y: 1800,
power: 45,
neighbors: ['France', 'Germany', 'Austria', 'Italy']
}, {
name: 'Germany',
x: 875,
y: 1450,
power: 75,
neighbors: ['France', 'Poland', 'Austria', 'Netherlands', 'Denmark', 'Czech', 'Luxembourg']
}, {
name: 'Denmark',
x: 880,
y: 1200,
power: 40,
neighbors: ['Sweden', 'Norway', 'Germany']
}, {
name: 'Norway',
x: 850,
y: 850,
power: 45,
neighbors: ['Sweden', 'Denmark', 'Finland', 'Iceland']
}, {
name: 'Sweden',
x: 1050,
y: 950,
power: 50,
neighbors: ['Norway', 'Denmark', 'Finland']
}, {
name: 'Finland',
x: 1300,
y: 700,
power: 30,
neighbors: ['Sweden', 'Norway', 'Russia', 'Estonia']
}, {
name: 'Italy',
x: 950,
y: 2050,
power: 60,
neighbors: ['France', 'Austria', 'Greece', 'Switzerland']
}, {
name: 'Austria',
x: 1000,
y: 1750,
power: 45,
neighbors: ['Germany', 'Italy', 'Czech', 'Hungary', 'Switzerland', 'Slovakia']
}, {
name: 'Czech',
x: 1000,
y: 1600,
power: 40,
neighbors: ['Poland', 'Austria', 'Germany', 'Slovakia']
}, {
name: 'Slovakia',
x: 1150,
y: 1700,
power: 35,
neighbors: ['Czech', 'Austria', 'Hungary']
}, {
name: 'Hungary',
x: 1200,
y: 1800,
power: 40,
neighbors: ['Austria', 'Romania', 'Slovakia', 'Serbia']
}, {
name: 'Poland',
x: 1180,
y: 1450,
power: 50,
neighbors: ['Germany', 'Czech', 'Ukraine', 'Belarus', 'Lithuania']
}, {
name: 'Belarus',
x: 1475,
y: 1350,
power: 40,
neighbors: ['Poland', 'Ukraine', 'Russia']
}, {
name: 'Ukraine',
x: 1600,
y: 1600,
power: 55,
neighbors: ['Poland', 'Romania', 'Russia', 'Belarus']
}, {
name: 'Russia',
x: 1800,
y: 1000,
power: 90,
neighbors: ['Finland', 'Ukraine', 'Belarus', 'Estonia']
}, {
name: 'Romania',
x: 1425,
y: 1900,
power: 45,
neighbors: ['Ukraine', 'Turkey', 'Hungary', 'Bulgaria', 'Serbia']
}, {
name: 'Bulgaria',
x: 1400,
y: 2100,
power: 25,
neighbors: ['Romania', 'Greece', 'Serbia']
}, {
name: 'Greece',
x: 1300,
y: 2350,
power: 40,
neighbors: ['Italy', 'Turkey', 'Bulgaria']
}, {
name: 'Turkey',
x: 1700,
y: 2250,
power: 65,
neighbors: ['Greece', 'Romania']
}, {
name: 'Serbia',
x: 1250,
y: 2000,
power: 35,
neighbors: ['Hungary', 'Romania', 'Bulgaria']
}, {
name: 'Estonia',
x: 1290,
y: 1000,
power: 35,
neighbors: ['Finland', 'Latvia', 'Russia']
}, {
name: 'Latvia',
x: 1300,
y: 1100,
power: 25,
neighbors: ['Estonia', 'Lithuania']
}, {
name: 'Lithuania',
x: 1250,
y: 1200,
power: 30,
neighbors: ['Latvia', 'Poland']
}];
// Create countries
for (var i = 0; i < countryData.length; i++) {
var data = countryData[i];
var country = new Country(data.name, data.x, data.y, data.power, data.neighbors);
countries.push(country);
game.addChild(country);
}
totalCountries = countries.length;
// UI Elements
var instructionText = new Text2('Select your starting country', {
size: 60,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
var scoreText = new Text2('Power: 0 | Conquered: 0/' + totalCountries, {
size: 40,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
scoreText.y = 80;
LK.gui.top.addChild(scoreText);
// Create battle button (initially hidden)
battleButton = new Text2('BATTLE', {
size: 50,
fill: 0xFFFFFF
});
battleButton.anchor.set(1, 1);
battleButton.x = -50;
battleButton.y = -50;
battleButton.alpha = 0;
LK.gui.bottomRight.addChild(battleButton);
// Battle button click handler
battleButton.down = function (x, y, obj) {
if (selectedCountryForUI && selectedCountryForUI.owner === 'player') {
if (battleState === 'none') {
battleState = 'selecting_target';
instructionText.setText('Click on a country to attack!');
battleButton.setText('CANCEL');
} else if (battleState === 'selecting_target') {
battleState = 'none';
instructionText.setText('Conquer neighboring territories!');
battleButton.setText('BATTLE');
}
}
};
function selectCountry(country) {
if (gameState !== 'selection') {
return;
}
// Deselect all countries
for (var i = 0; i < countries.length; i++) {
countries[i].isSelected = false;
countries[i].updateVisual();
}
// Select this country
country.isSelected = true;
country.owner = 'player';
country.updateVisual();
playerCountry = country;
playerPower = country.power;
conqueredCount = 1;
// Start the game
gameState = 'playing';
instructionText.setText('Conquer neighboring territories!');
updateScore();
// Hide battle button during initial selection
if (battleButton) {
battleButton.alpha = 0;
}
// Make some countries enemy controlled
var enemyCount = Math.floor(totalCountries * 0.3);
var availableCountries = [];
for (var j = 0; j < countries.length; j++) {
if (countries[j] !== playerCountry) {
availableCountries.push(countries[j]);
}
}
for (var k = 0; k < enemyCount && k < availableCountries.length; k++) {
var randomIndex = Math.floor(Math.random() * availableCountries.length);
var enemyCountry = availableCountries[randomIndex];
enemyCountry.owner = 'enemy';
enemyCountry.updateVisual();
availableCountries.splice(randomIndex, 1);
}
}
function attemptConquest(targetCountry) {
if (gameState !== 'playing') {
return;
}
// Check if target is neighboring a player country
var canAttack = false;
for (var i = 0; i < countries.length; i++) {
var country = countries[i];
if (country.owner === 'player') {
for (var j = 0; j < country.neighbors.length; j++) {
if (country.neighbors[j] === targetCountry.countryName) {
canAttack = true;
break;
}
}
}
if (canAttack) {
break;
}
}
if (!canAttack) {
// Flash the target red to indicate invalid move
LK.effects.flashObject(targetCountry, 0xFF0000, 500);
return;
}
// Check if player has enough power to attack this country
if (playerPower < targetCountry.power) {
// Flash the target red to indicate insufficient power
LK.effects.flashObject(targetCountry, 0xFF0000, 500);
return;
}
// Calculate conquest success based on power differential
var attackPower = playerPower;
var defensePower = targetCountry.power;
var successChance = Math.min(0.9, Math.max(0.1, attackPower / (attackPower + defensePower)));
if (Math.random() < successChance) {
// Successful conquest
targetCountry.owner = 'player';
targetCountry.updateVisual();
playerPower += Math.floor(targetCountry.power * 0.3);
conqueredCount++;
LK.getSound('conquest').play();
LK.effects.flashObject(targetCountry, 0x00FF00, 1000);
// Check win condition
if (conqueredCount >= Math.ceil(totalCountries * 0.7)) {
LK.setScore(playerPower);
LK.showYouWin();
}
} else {
// Failed conquest
playerPower = Math.max(10, playerPower - Math.floor(targetCountry.power * 0.1));
LK.getSound('defeat').play();
LK.effects.flashObject(targetCountry, 0xFF0000, 1000);
// Check lose condition
if (playerPower < 20) {
LK.showGameOver();
}
}
updateScore();
}
function selectCountryForBattle(country) {
if (gameState !== 'playing' || country.owner !== 'player') {
return;
}
// Deselect all countries
for (var i = 0; i < countries.length; i++) {
countries[i].isSelected = false;
countries[i].updateVisual();
}
// Select this country and show battle button
country.isSelected = true;
country.updateVisual();
selectedCountryForUI = country;
// Show battle button
battleButton.alpha = 1;
battleButton.setText('BATTLE');
}
function performBattle(targetCountry) {
if (gameState !== 'playing' || !selectedCountryForUI) {
return;
}
// Check if target is neighboring the selected player country
var canAttack = false;
for (var j = 0; j < selectedCountryForUI.neighbors.length; j++) {
if (selectedCountryForUI.neighbors[j] === targetCountry.countryName) {
canAttack = true;
break;
}
}
if (!canAttack) {
// Flash the target red to indicate invalid move
LK.effects.flashObject(targetCountry, 0xFF0000, 500);
return;
}
// Battle logic - if we're stronger, we win; if weaker, we lose
if (playerPower >= targetCountry.power) {
// We win - take over the country
targetCountry.owner = 'player';
targetCountry.updateVisual();
playerPower += Math.floor(targetCountry.power * 0.3);
conqueredCount++;
LK.getSound('conquest').play();
LK.effects.flashObject(targetCountry, 0x00FF00, 1000);
// Check win condition
if (conqueredCount >= Math.ceil(totalCountries * 0.7)) {
LK.setScore(playerPower);
LK.showYouWin();
}
} else {
// We lose - reduce our power significantly
playerPower = Math.max(10, playerPower - Math.floor(targetCountry.power * 0.2));
LK.getSound('defeat').play();
LK.effects.flashObject(targetCountry, 0xFF0000, 1000);
// Check lose condition
if (playerPower < 20) {
LK.showGameOver();
}
}
updateScore();
}
function updateScore() {
scoreText.setText('Power: ' + playerPower + ' | Conquered: ' + conqueredCount + '/' + totalCountries);
}
// AI behavior for enemy expansion
var aiTimer = 0;
game.update = function () {
if (gameState === 'playing') {
aiTimer++;
// AI acts every 3 seconds
if (aiTimer >= 180) {
aiTimer = 0;
performAIAction();
}
}
};
function performAIAction() {
// Find enemy countries that can expand
var enemyCountries = [];
var neutralTargets = [];
for (var i = 0; i < countries.length; i++) {
if (countries[i].owner === 'enemy') {
enemyCountries.push(countries[i]);
} else if (countries[i].owner === 'neutral') {
neutralTargets.push(countries[i]);
}
}
if (enemyCountries.length === 0 || neutralTargets.length === 0) {
return;
}
// Random enemy country attempts to conquer a neutral neighbor
var randomEnemy = enemyCountries[Math.floor(Math.random() * enemyCountries.length)];
var validTargets = [];
for (var j = 0; j < neutralTargets.length; j++) {
var target = neutralTargets[j];
for (var k = 0; k < randomEnemy.neighbors.length; k++) {
if (randomEnemy.neighbors[k] === target.countryName) {
validTargets.push(target);
break;
}
}
}
if (validTargets.length > 0) {
var target = validTargets[Math.floor(Math.random() * validTargets.length)];
var successChance = randomEnemy.power / (randomEnemy.power + target.power);
if (Math.random() < successChance) {
target.owner = 'enemy';
target.updateVisual();
LK.effects.flashObject(target, 0xFF6B6B, 800);
}
}
} ===================================================================
--- original.js
+++ change.js
@@ -69,13 +69,11 @@
instructionText.setText('Conquer neighboring territories!');
battleButton.setText('BATTLE');
}
} else {
- // Allow direct fighting without battle button
+ // Only allow selecting player countries for battle
if (self.owner === 'player') {
selectCountryForBattle(self);
- } else if (self.owner === 'neutral' || self.owner === 'enemy') {
- attemptConquest(self);
}
}
}
};