/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
selectedCountry: "undefined",
currentLevel: 1
});
/****
* Classes
****/
var CaptureButton = Container.expand(function () {
var self = Container.call(this);
self.targetProvince = null;
self.buttonGraphic = null;
self.textLabel = null;
self.init = function (label, targetProvince) {
self.targetProvince = targetProvince;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2(label, {
size: 40,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
if (atWar[self.targetProvince.countryIndex]) {
var random = Math.random();
var successChance = power / (power + 100);
if (random < successChance) {
self.targetProvince.countryIndex = playerCountryIndex;
self.targetProvince.updateGraphic();
money += 10;
moneyText.setText('Money: $' + money);
LK.effects.flashObject(self.targetProvince, 0x4CAF50, 500);
var enemyCountryIndex = self.targetProvince.countryIndex;
if (self.targetProvince.power > power) {
LK.setTimeout(function () {
var counterRandom = Math.random();
var counterSuccessChance = self.targetProvince.power / (self.targetProvince.power + power);
if (counterRandom < counterSuccessChance && self.targetProvince.countryIndex === playerCountryIndex) {
self.targetProvince.countryIndex = enemyCountryIndex;
self.targetProvince.updateGraphic();
LK.effects.flashObject(self.targetProvince, 0xF44336, 500);
}
}, 500);
}
} else {
LK.effects.flashObject(self.targetProvince, 0xF44336, 500);
}
LK.game.removeChild(currentPanel);
currentPanel = null;
}
};
return self;
});
//{custom_lcs_12}
var ConfirmationDialog = Container.expand(function () {
var self = Container.call(this);
//{custom_confirm_1}
self.panelGraphic = null; //{custom_confirm_2}
self.init = function (message, onConfirm, onCancel) {
//{custom_confirm_3}
self.panelGraphic = self.attachAsset('panel', {
//{custom_confirm_4}
anchorX: 0.5,
//{custom_confirm_5}
anchorY: 0.5 //{custom_confirm_6}
}); //{custom_confirm_7}
self.x = 1024; //{custom_confirm_8}
self.y = 1366; //{custom_confirm_9}
var messageText = new Text2(message, {
//{custom_confirm_10}
size: 60,
//{custom_confirm_11}
fill: 0xFFFFFF //{custom_confirm_12}
}); //{custom_confirm_13}
messageText.anchor.set(0.5, 0.5); //{custom_confirm_14}
messageText.x = 0; //{custom_confirm_15}
messageText.y = -100; //{custom_confirm_16}
self.addChild(messageText); //{custom_confirm_17}
var confirmBtn = self.addChild(new Container()); //{custom_confirm_18}
confirmBtn.attachAsset('button', {
//{custom_confirm_19}
anchorX: 0.5,
//{custom_confirm_20}
anchorY: 0.5 //{custom_confirm_21}
}); //{custom_confirm_22}
confirmBtn.x = -180; //{custom_confirm_23}
confirmBtn.y = 120; //{custom_confirm_24}
confirmBtn.interactive = true; //{custom_confirm_25}
var confirmLabel = confirmBtn.addChild(new Text2('YES', {
//{custom_confirm_26}
size: 50,
//{custom_confirm_27}
fill: 0xFFFFFF //{custom_confirm_28}
})); //{custom_confirm_29}
confirmLabel.anchor.set(0.5, 0.5); //{custom_confirm_30}
confirmBtn.down = function () {
//{custom_confirm_31}
game.removeChild(self); //{custom_confirm_32}
onConfirm(); //{custom_confirm_33}
}; //{custom_confirm_34}
var cancelBtn = self.addChild(new Container()); //{custom_confirm_35}
cancelBtn.attachAsset('buttonNegative', {
//{custom_confirm_36}
anchorX: 0.5,
//{custom_confirm_37}
anchorY: 0.5 //{custom_confirm_38}
}); //{custom_confirm_39}
cancelBtn.x = 180; //{custom_confirm_40}
cancelBtn.y = 120; //{custom_confirm_41}
cancelBtn.interactive = true; //{custom_confirm_42}
var cancelLabel = cancelBtn.addChild(new Text2('NO', {
//{custom_confirm_43}
size: 50,
//{custom_confirm_44}
fill: 0xFFFFFF //{custom_confirm_45}
})); //{custom_confirm_46}
cancelLabel.anchor.set(0.5, 0.5); //{custom_confirm_47}
cancelBtn.down = function () {
//{custom_confirm_48}
game.removeChild(self); //{custom_confirm_49}
onCancel(); //{custom_confirm_50}
}; //{custom_confirm_51}
}; //{custom_confirm_52}
return self; //{custom_confirm_53}
});
var CountryButton = Container.expand(function () {
var self = Container.call(this);
self.countryIndex = -1;
self.countryName = '';
self.buttonGraphic = null;
self.textLabel = null;
self.init = function (countryName, index) {
self.countryName = countryName;
self.countryIndex = index;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2(countryName, {
size: 70,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
playerCountryIndex = self.countryIndex;
storage.selectedCountry = self.countryIndex;
initializeGame();
LK.game.removeChild(countrySelection);
countrySelection = null;
};
return self;
});
var CountrySelectionScreen = Container.expand(function () {
var self = Container.call(this);
var countries = ['Iraq', 'Syria', 'Turkey', 'Saudi Arabia', 'Iran'];
var buttons = [];
self.init = function () {
var titleText = new Text2('Select Your Country', {
size: 140,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
self.addChild(titleText);
var buttonWidth = 300;
var buttonHeight = 100;
var spacing = 220;
var startY = 600;
for (var i = 0; i < countries.length; i++) {
var btn = self.addChild(new CountryButton());
btn.init(countries[i], i);
btn.x = 1024;
btn.y = startY + i * spacing;
buttons.push(btn);
}
var resetBtn = self.addChild(new ResetProgressButton()); //{custom_selection_reset_1}
resetBtn.init(); //{custom_selection_reset_2}
resetBtn.x = 1024; //{custom_selection_reset_3}
resetBtn.y = 2500; //{custom_selection_reset_4}
};
self.init();
return self;
});
var EconomicInvestmentButton = Container.expand(function () {
var self = Container.call(this);
self.targetProvince = null;
self.buttonGraphic = null;
self.textLabel = null;
self.investmentCost = 30;
self.init = function (targetProvince) {
self.targetProvince = targetProvince;
self.investmentCost = 30 + targetProvince.investmentLevel * 10;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonLabel = 'Invest ($' + self.investmentCost + ')';
if (targetProvince.investmentLevel >= 10) {
buttonLabel = 'Max Level (10)';
self.buttonGraphic.tint = 0x666666;
}
self.textLabel = self.addChild(new Text2(buttonLabel, {
size: 36,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
if (self.targetProvince.investmentLevel < 10 && money >= self.investmentCost) {
money -= self.investmentCost;
self.targetProvince.investmentLevel += 1;
moneyText.setText('Money: $' + money);
if (currentPanel) {
game.removeChild(currentPanel);
currentPanel = null;
}
} else if (self.targetProvince.investmentLevel >= 10) {
// Max level reached, do nothing
}
};
return self;
});
var InteractionButton = Container.expand(function () {
var self = Container.call(this);
self.countryIndex = -1;
self.isPositive = true;
self.buttonGraphic = null;
self.textLabel = null;
self.init = function (label, countryIndex, isPositive) {
self.countryIndex = countryIndex;
self.isPositive = isPositive;
var color = isPositive ? 'button' : 'buttonNegative';
self.buttonGraphic = self.attachAsset(color, {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2(label, {
size: 40,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
var change = self.isPositive ? 10 : -10;
relationships[self.countryIndex] += change;
if (relationships[self.countryIndex] <= -50 && !atWar[self.countryIndex]) {
atWar[self.countryIndex] = true;
}
if (currentPanel && currentPanel.closeBtn) {
var relationshipText = null;
for (var i = 0; i < currentPanel.children.length; i++) {
if (currentPanel.children[i].id === 'relationshipText') {
relationshipText = currentPanel.children[i];
break;
}
}
if (relationshipText) {
relationshipText.setText('Relationship: ' + relationships[self.countryIndex]);
}
}
};
return self;
});
var InteractionPanel = Container.expand(function () {
var self = Container.call(this);
self.targetProvince = null;
self.targetCountryIndex = -1;
self.panelGraphic = null;
self.closeBtn = null;
self.init = function (province) {
self.targetProvince = province;
self.targetCountryIndex = province.countryIndex;
self.panelGraphic = self.attachAsset('panel', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 1024;
self.y = 1366;
var targetCountryName = countryNames[self.targetCountryIndex];
var titleText = new Text2('Interact with ' + targetCountryName, {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 0;
titleText.y = -270;
self.addChild(titleText);
var relationshipText = new Text2('Relationship: ' + relationships[self.targetCountryIndex], {
size: 50,
fill: 0xFFEB3B
});
relationshipText.anchor.set(0.5, 0);
relationshipText.x = 0;
relationshipText.y = -200;
relationshipText.id = 'relationshipText';
self.addChild(relationshipText);
var warText = new Text2('', {
size: 50,
fill: 0xF44336
});
warText.anchor.set(0.5, 0);
warText.x = 0;
warText.y = -130;
if (atWar[self.targetCountryIndex]) {
warText.setText('AT WAR');
}
self.addChild(warText);
var provinceNameText = self.addChild(new Text2('Province Power: ' + province.power, {
size: 50,
fill: 0xFFFFFF
}));
provinceNameText.anchor.set(0.5, 0);
provinceNameText.x = 0;
provinceNameText.y = -60;
if (self.targetCountryIndex === playerCountryIndex) {
var investmentLevelText = self.addChild(new Text2('Level: ' + province.investmentLevel + '/10', {
size: 42,
fill: 0x00FF00
}));
investmentLevelText.anchor.set(0.5, 0);
investmentLevelText.x = 0;
investmentLevelText.y = 70;
var incomeText = self.addChild(new Text2('Income: +' + (2 + province.investmentLevel) + '/sec', {
size: 42,
fill: 0x00FF00
}));
incomeText.anchor.set(0.5, 0);
incomeText.x = 0;
incomeText.y = 140;
var defenseText = self.addChild(new Text2('Defense: ' + province.defenseLevel + '/10', {
//{custom_defense_text_1}
size: 42,
//{custom_defense_text_2}
fill: 0xFF6B9D //{custom_defense_text_3}
})); //{custom_defense_text_4}
defenseText.anchor.set(0.5, 0); //{custom_defense_text_5}
defenseText.x = 0; //{custom_defense_text_6}
defenseText.y = 210; //{custom_defense_text_7}
var investBtn = self.addChild(new EconomicInvestmentButton());
investBtn.init(province);
investBtn.x = -150;
investBtn.y = 300;
var defenseBtn = self.addChild(new ProvinceDefenseButton()); //{custom_defense_btn_panel_1}
defenseBtn.init(province); //{custom_defense_btn_panel_2}
defenseBtn.x = 150; //{custom_defense_btn_panel_3}
defenseBtn.y = 300; //{custom_defense_btn_panel_4}
} else {
var increaseBtn = self.addChild(new InteractionButton());
increaseBtn.init('+10 Relationship', self.targetCountryIndex, true);
increaseBtn.x = -220;
increaseBtn.y = 100;
var decreaseBtn = self.addChild(new InteractionButton());
decreaseBtn.init('-10 Relationship', self.targetCountryIndex, false);
decreaseBtn.x = 220;
decreaseBtn.y = 100;
}
self.closeBtn = self.addChild(new Container());
self.closeBtn.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.closeBtn.x = 370;
self.closeBtn.y = -270;
self.closeBtn.interactive = true;
var closeLabel = self.closeBtn.addChild(new Text2('X', {
size: 40,
fill: 0xFFFFFF
}));
closeLabel.anchor.set(0.5, 0.5);
self.closeBtn.down = function () {
LK.game.removeChild(self);
currentPanel = null;
};
};
return self;
});
var LevelCompleteScreen = Container.expand(function () {
var self = Container.call(this);
//{custom_lcs_1}
self.panelGraphic = null; //{custom_lcs_2}
self.init = function () {
self.panelGraphic = self.attachAsset('panel', {
anchorX: 0.5,
anchorY: 0.5
}); //{custom_lcs_3}
self.x = 1024;
self.y = 1366;
var titleText = new Text2('LEVEL COMPLETE!', {
size: 80,
fill: 0x4CAF50
}); //{custom_lcs_4}
titleText.anchor.set(0.5, 0.5);
titleText.x = 0;
titleText.y = -150;
self.addChild(titleText); //{custom_lcs_5}
var nextLevelText = new Text2('Level ' + (currentLevel + 1) + ' Starting...', {
size: 60,
fill: 0xFFFFFF
}); //{custom_lcs_6}
nextLevelText.anchor.set(0.5, 0.5);
nextLevelText.x = 0;
nextLevelText.y = 0;
self.addChild(nextLevelText); //{custom_lcs_7}
var bonusText = new Text2('Bonus: +50 Money', {
size: 40,
fill: 0xFFEB3B
}); //{custom_lcs_8}
bonusText.anchor.set(0.5, 0.5);
bonusText.x = 0;
bonusText.y = 100;
self.addChild(bonusText); //{custom_lcs_9}
}; //{custom_lcs_10}
self.init();
return self; //{custom_lcs_11}
});
//{custom_lcs_12}
var PowerUpButton = Container.expand(function () {
var self = Container.call(this);
self.buttonGraphic = null;
self.textLabel = null;
self.powerCost = 50;
self.init = function (powerCost) {
self.powerCost = powerCost;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2('Power +1 ($' + powerCost + ')', {
size: 40,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
if (money >= self.powerCost) {
money -= self.powerCost;
power += 1;
moneyText.setText('Money: $' + money);
powerText.setText('Power: ' + power);
}
};
return self;
});
var Province = Container.expand(function () {
var self = Container.call(this);
self.countryIndex = -1;
self.gridX = 0;
self.gridY = 0;
self.graphic = null;
self.init = function (gridX, gridY, countryIndex) {
self.gridX = gridX;
self.gridY = gridY;
self.countryIndex = countryIndex;
self.investmentLevel = 0;
self.defenseLevel = 0;
self.power = 50;
if (countryIndex === playerCountryIndex) {
//{custom_province_init_1}
self.power = 20; //{custom_province_init_2}
} //{custom_province_init_3}
self.lastIncomeTime = Date.now();
self.updateGraphic();
self.interactive = true;
};
self.updateGraphic = function () {
if (self.graphic) {
self.removeChild(self.graphic);
}
if (self.powerText) {
self.removeChild(self.powerText);
self.powerText = null;
}
var assetId = 'province';
if (self.countryIndex === -1) {
assetId = 'provinceNeutral';
} else if (self.countryIndex === playerCountryIndex) {
assetId = 'province';
} else if (self.countryIndex === 0) {
assetId = 'provinceIraq';
} else if (self.countryIndex === 1) {
assetId = 'provinceSyria';
} else if (self.countryIndex === 2) {
assetId = 'provinceTurkey';
} else if (self.countryIndex === 3) {
assetId = 'provinceSaudiArabia';
} else if (self.countryIndex === 4) {
assetId = 'provinceIran';
} else if (self.countryIndex === 5) {
//{custom_asset_egypt}
assetId = 'provinceEgypt'; //{custom_asset_egypt_2}
} else if (self.countryIndex === 6) {
//{custom_asset_israel}
assetId = 'provinceIsrael'; //{custom_asset_israel_2}
} else if (self.countryIndex === 7) {
//{custom_asset_yemen}
assetId = 'provinceYemen'; //{custom_asset_yemen_2}
} else if (self.countryIndex === 8) {
//{custom_asset_oman}
assetId = 'provinceOman'; //{custom_asset_oman_2}
}
self.graphic = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
if (atWar[self.countryIndex] && self.countryIndex !== playerCountryIndex && self.countryIndex !== -1) {
self.powerText = self.addChild(new Text2(self.power || '0', {
size: 24,
fill: 0xFFFFFF
}));
self.powerText.anchor.set(0.5, 0.5);
self.powerText.x = 0;
self.powerText.y = 0;
}
};
self.down = function (x, y, obj) {
if (self.countryIndex !== -1) {
openProvincePanel(self);
}
if (self.countryIndex === playerCountryIndex) {
openProvincePanel(self);
}
};
return self;
});
//{custom_confirm_54}
var ProvinceDefenseButton = Container.expand(function () {
var self = Container.call(this);
//{custom_defense_1}
//{custom_defense_2}
self.targetProvince = null; //{custom_defense_3}
self.buttonGraphic = null; //{custom_defense_4}
self.textLabel = null; //{custom_defense_5}
self.defenseCost = 40; //{custom_defense_6}
self.init = function (targetProvince) {
//{custom_defense_7}
self.targetProvince = targetProvince; //{custom_defense_8}
self.defenseCost = 40 + targetProvince.defenseLevel * 5; //{custom_defense_9}
self.buttonGraphic = self.attachAsset('button', {
//{custom_defense_10}
anchorX: 0.5,
//{custom_defense_11}
anchorY: 0.5 //{custom_defense_12}
}); //{custom_defense_13}
var buttonLabel = 'Upgrade Defense ($' + self.defenseCost + ')'; //{custom_defense_14}
if (targetProvince.defenseLevel >= 10) {
//{custom_defense_15}
buttonLabel = 'Max Defense (10)'; //{custom_defense_16}
self.buttonGraphic.tint = 0x666666; //{custom_defense_17}
} //{custom_defense_18}
self.textLabel = self.addChild(new Text2(buttonLabel, {
//{custom_defense_19}
size: 36,
//{custom_defense_20}
fill: 0xFFFFFF //{custom_defense_21}
})); //{custom_defense_22}
self.textLabel.anchor.set(0.5, 0.5); //{custom_defense_23}
self.textLabel.x = 0; //{custom_defense_24}
self.textLabel.y = 0; //{custom_defense_25}
self.interactive = true; //{custom_defense_26}
}; //{custom_defense_27}
self.down = function (x, y, obj) {
//{custom_defense_28}
if (self.targetProvince.defenseLevel < 10 && money >= self.defenseCost) {
//{custom_defense_29}
money -= self.defenseCost; //{custom_defense_30}
self.targetProvince.defenseLevel += 1; //{custom_defense_31}
self.targetProvince.power += 5; //{custom_defense_32}
moneyText.setText('Money: $' + money); //{custom_defense_33}
if (currentPanel) {
//{custom_defense_34}
game.removeChild(currentPanel); //{custom_defense_35}
currentPanel = null; //{custom_defense_36}
} //{custom_defense_37}
} else if (self.targetProvince.defenseLevel >= 10) {//{custom_defense_38}
// Max level reached, do nothing
} //{custom_defense_39}
}; //{custom_defense_40}
return self; //{custom_defense_41}
});
//{custom_defense_42}
var ResetProgressButton = Container.expand(function () {
var self = Container.call(this);
//{custom_reset_btn_1}
//{custom_reset_btn_2}
self.buttonGraphic = null; //{custom_reset_btn_3}
self.textLabel = null; //{custom_reset_btn_4}
self.init = function () {
//{custom_reset_btn_5}
self.buttonGraphic = self.attachAsset('buttonNegative', {
//{custom_reset_btn_6}
anchorX: 0.5,
//{custom_reset_btn_7}
anchorY: 0.5 //{custom_reset_btn_8}
}); //{custom_reset_btn_9}
self.textLabel = self.addChild(new Text2('Clear All Progress', {
//{custom_reset_btn_10}
size: 45,
//{custom_reset_btn_11}
fill: 0xFFFFFF //{custom_reset_btn_12}
})); //{custom_reset_btn_13}
self.textLabel.anchor.set(0.5, 0.5); //{custom_reset_btn_14}
self.textLabel.x = 0; //{custom_reset_btn_15}
self.textLabel.y = 0; //{custom_reset_btn_16}
self.interactive = true; //{custom_reset_btn_17}
}; //{custom_reset_btn_18}
self.down = function (x, y, obj) {
//{custom_reset_btn_19}
var confirmDialog = game.addChild(new ConfirmationDialog()); //{custom_reset_btn_20}
confirmDialog.init('Clear all progress?', function () {
//{custom_reset_btn_21}
storage.selectedCountry = 'undefined'; //{custom_reset_btn_22}
storage.currentLevel = 1; //{custom_reset_btn_23}
playerCountryIndex = -1; //{custom_reset_btn_24}
currentLevel = 1; //{custom_reset_btn_25}
money = 100; //{custom_reset_btn_26}
power = 10; //{custom_reset_btn_27}
provinces = []; //{custom_reset_btn_28}
while (game.children.length > 0) {
//{custom_reset_btn_29}
game.removeChild(game.children[0]); //{custom_reset_btn_30}
} //{custom_reset_btn_31}
LK.gui.topLeft.removeChild(moneyText); //{custom_reset_btn_32}
LK.gui.topLeft.removeChild(powerText); //{custom_reset_btn_33}
LK.gui.top.removeChild(levelText); //{custom_reset_btn_34}
for (var i = LK.gui.bottom.children.length - 1; i >= 0; i--) {
//{custom_reset_btn_35}
LK.gui.bottom.removeChild(LK.gui.bottom.children[i]); //{custom_reset_btn_36}
} //{custom_reset_btn_37}
initializeGame(); //{custom_reset_btn_38}
}, function () {//{custom_reset_btn_39}
// Cancel - do nothing
}); //{custom_reset_btn_40}
}; //{custom_reset_btn_41}
return self; //{custom_reset_btn_42}
});
/****
* Initialize Game
****/
//{custom_reset_btn_43}
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
LK.game = game;
/****
* Game Variables
****/
var countryNames = ['Iraq', 'Syria', 'Turkey', 'Saudi Arabia', 'Iran', 'Egypt', 'Israel', 'Yemen', 'Oman'];
var relationships = [0, 0, 0, 0, 0, 0, 0, 0, 0];
var atWar = [false, false, false, false, false, false, false, false, false];
var playerCountryIndex = storage.selectedCountry !== undefined ? storage.selectedCountry : -1;
var currentLevel = storage.currentLevel || 1;
var money = 100;
var power = 10;
var provinces = [];
var countrySelection = null;
var currentPanel = null;
var moneyText = null;
var powerText = null;
var levelText = null;
function initializeMap() {
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var difficultyMultiplier = 1 + (currentLevel - 1) * 0.15;
var mapWidth = 8; //{custom_map_width}
var mapHeight = 8; //{custom_map_height}
var provinceSize = 100; //{custom_map_size}
var totalMapWidth = mapWidth * provinceSize;
var totalMapHeight = mapHeight * provinceSize;
var startX = (2048 - totalMapWidth) / 2;
var startY = (2732 - totalMapHeight) / 2 + 100;
function getCountryPowerRange(countryIndex) {
if (countryIndex === playerCountryIndex) {
return {
min: 50,
max: 100
};
}
if (countryIndex === 0) {
return {
min: 20,
max: 35
};
}
if (countryIndex === 1) {
return {
min: 20,
max: 20
};
}
if (countryIndex === 2) {
return {
min: 65,
max: 70
};
}
if (countryIndex === 3) {
return {
min: 40,
max: 50
};
}
if (countryIndex === 4) {
return {
min: 60,
max: 65
};
}
if (countryIndex === 5) {
//{custom_egypt_range}
return {
//{custom_egypt_range_2}
min: 35,
//{custom_egypt_range_3}
max: 45 //{custom_egypt_range_4}
}; //{custom_egypt_range_5}
} //{custom_egypt_range_6}
if (countryIndex === 6) {
//{custom_israel_range}
return {
//{custom_israel_range_2}
min: 40,
//{custom_israel_range_3}
max: 55 //{custom_israel_range_4}
}; //{custom_israel_range_5}
} //{custom_israel_range_6}
if (countryIndex === 7) {
//{custom_yemen_range}
return {
//{custom_yemen_range_2}
min: 25,
//{custom_yemen_range_3}
max: 40 //{custom_yemen_range_4}
}; //{custom_yemen_range_5}
} //{custom_yemen_range_6}
if (countryIndex === 8) {
//{custom_oman_range}
return {
//{custom_oman_range_2}
min: 30,
//{custom_oman_range_3}
max: 45 //{custom_oman_range_4}
}; //{custom_oman_range_5}
} //{custom_oman_range_6}
return {
min: 30,
max: 50
};
}
for (var y = 0; y < mapHeight; y++) {
for (var x = 0; x < mapWidth; x++) {
var randomCountry = Math.floor(Math.random() * 9); //{custom_random_9}
var province = game.addChild(new Province());
province.init(x, y, randomCountry);
province.x = startX + x * provinceSize + provinceSize / 2;
province.y = startY + y * provinceSize + provinceSize / 2;
var powerRange = getCountryPowerRange(randomCountry);
var basePower = powerRange.min + Math.floor(Math.random() * (powerRange.max - powerRange.min + 1));
province.power = Math.floor(basePower * difficultyMultiplier);
provinces.push(province);
}
}
for (var i = 0; i < 9; i++) {
//{custom_reset_9}
relationships[i] = 0;
atWar[i] = false;
} //{custom_reset_relationships}
var playerCountriesToConquer = 12; //{custom_conquer_12}
var assignedCount = 0;
for (var i = 0; i < provinces.length && assignedCount < playerCountriesToConquer; i++) {
var randomIndex = Math.floor(Math.random() * provinces.length);
if (provinces[randomIndex].countryIndex !== playerCountryIndex) {
provinces[randomIndex].countryIndex = playerCountryIndex;
provinces[randomIndex].investmentLevel = 0;
provinces[randomIndex].defenseLevel = 0; //{custom_init_defense_level}
provinces[randomIndex].updateGraphic();
assignedCount += 1;
}
}
}
function openProvincePanel(province) {
if (currentPanel) {
game.removeChild(currentPanel);
}
currentPanel = game.addChild(new InteractionPanel());
currentPanel.init(province);
if (atWar[province.countryIndex]) {
var captureBtn = currentPanel.addChild(new CaptureButton());
captureBtn.init('CAPTURE PROVINCE', province);
captureBtn.x = 0;
captureBtn.y = 250;
}
}
function showLevelComplete() {
game.update = function () {};
var levelCompleteScreen = game.addChild(new LevelCompleteScreen());
currentLevel += 1;
storage.currentLevel = currentLevel;
money += 50;
LK.setTimeout(function () {
while (game.children.length > 0) {
game.removeChild(game.children[0]);
}
LK.gui.top.removeChild(levelText);
LK.gui.topLeft.removeChild(moneyText);
LK.gui.topLeft.removeChild(powerText);
LK.gui.bottom.removeChild(LK.gui.bottom.children[0]);
provinces = [];
initializeMap();
moneyText = new Text2('Money: $' + money, {
size: 90,
fill: 0xFFFFFF
});
moneyText.anchor.set(0, 0);
moneyText.x = 30;
moneyText.y = 30;
LK.gui.topLeft.addChild(moneyText);
powerText = new Text2('Power: ' + power, {
size: 90,
fill: 0xFFEB3B
});
powerText.anchor.set(0, 0);
powerText.x = 30;
powerText.y = 140;
LK.gui.topLeft.addChild(powerText);
levelText = new Text2('Level ' + currentLevel, {
size: 90,
fill: 0x4CAF50
});
levelText.anchor.set(0.5, 0);
levelText.x = 0;
levelText.y = 40;
LK.gui.top.addChild(levelText);
var powerUpBtn = LK.gui.bottom.addChild(new PowerUpButton());
powerUpBtn.init(50);
powerUpBtn.x = 0;
powerUpBtn.y = -120;
game.update = function () {
if (LK.ticks % 60 === 0) {
var incomePerSecond = 0;
var playerProvincesCount = 0;
var totalProvincesCount = 0;
for (var p = 0; p < provinces.length; p++) {
totalProvincesCount += 1;
if (provinces[p].countryIndex === playerCountryIndex) {
incomePerSecond += 2 + provinces[p].investmentLevel;
playerProvincesCount += 1;
}
}
money += incomePerSecond;
moneyText.setText('Money: $' + money);
if (playerProvincesCount === totalProvincesCount && totalProvincesCount > 0) {
showLevelComplete();
}
}
};
}, 3000);
} //{custom_show_level_complete}
function initializeGame() {
if (playerCountryIndex === -1) {
countrySelection = game.addChild(new CountrySelectionScreen());
return;
}
while (game.children.length > 0) {
game.removeChild(game.children[0]);
}
initializeMap();
moneyText = new Text2('Money: $' + money, {
size: 90,
fill: 0xFFFFFF
});
moneyText.anchor.set(0, 0);
moneyText.x = 30;
moneyText.y = 30;
LK.gui.topLeft.addChild(moneyText);
powerText = new Text2('Power: ' + power, {
size: 90,
fill: 0xFFEB3B
});
powerText.anchor.set(0, 0);
powerText.x = 30;
powerText.y = 140;
LK.gui.topLeft.addChild(powerText);
levelText = new Text2('Level ' + currentLevel, {
size: 90,
fill: 0x4CAF50
});
levelText.anchor.set(0.5, 0);
levelText.x = 0;
levelText.y = 40;
LK.gui.top.addChild(levelText);
var powerUpBtn = LK.gui.bottom.addChild(new PowerUpButton());
powerUpBtn.init(50);
powerUpBtn.x = 0;
powerUpBtn.y = -120;
game.update = function () {
if (LK.ticks % 60 === 0) {
var incomePerSecond = 0;
var playerProvincesCount = 0;
var totalProvincesCount = 0;
for (var p = 0; p < provinces.length; p++) {
totalProvincesCount += 1;
if (provinces[p].countryIndex === playerCountryIndex) {
incomePerSecond += 2 + provinces[p].investmentLevel;
playerProvincesCount += 1;
}
}
money += incomePerSecond;
moneyText.setText('Money: $' + money);
if (playerProvincesCount === totalProvincesCount && totalProvincesCount > 0) {
showLevelComplete();
} //{custom_level_check}
}
};
}
if (playerCountryIndex === -1) {
countrySelection = game.addChild(new CountrySelectionScreen());
} else {
initializeGame();
}
LK.playMusic('TheConquest', {
loop: true,
fade: {
start: 0,
end: 0.3,
duration: 2000
}
});
//{custom_reset_btn_43} /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
selectedCountry: "undefined",
currentLevel: 1
});
/****
* Classes
****/
var CaptureButton = Container.expand(function () {
var self = Container.call(this);
self.targetProvince = null;
self.buttonGraphic = null;
self.textLabel = null;
self.init = function (label, targetProvince) {
self.targetProvince = targetProvince;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2(label, {
size: 40,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
if (atWar[self.targetProvince.countryIndex]) {
var random = Math.random();
var successChance = power / (power + 100);
if (random < successChance) {
self.targetProvince.countryIndex = playerCountryIndex;
self.targetProvince.updateGraphic();
money += 10;
moneyText.setText('Money: $' + money);
LK.effects.flashObject(self.targetProvince, 0x4CAF50, 500);
var enemyCountryIndex = self.targetProvince.countryIndex;
if (self.targetProvince.power > power) {
LK.setTimeout(function () {
var counterRandom = Math.random();
var counterSuccessChance = self.targetProvince.power / (self.targetProvince.power + power);
if (counterRandom < counterSuccessChance && self.targetProvince.countryIndex === playerCountryIndex) {
self.targetProvince.countryIndex = enemyCountryIndex;
self.targetProvince.updateGraphic();
LK.effects.flashObject(self.targetProvince, 0xF44336, 500);
}
}, 500);
}
} else {
LK.effects.flashObject(self.targetProvince, 0xF44336, 500);
}
LK.game.removeChild(currentPanel);
currentPanel = null;
}
};
return self;
});
//{custom_lcs_12}
var ConfirmationDialog = Container.expand(function () {
var self = Container.call(this);
//{custom_confirm_1}
self.panelGraphic = null; //{custom_confirm_2}
self.init = function (message, onConfirm, onCancel) {
//{custom_confirm_3}
self.panelGraphic = self.attachAsset('panel', {
//{custom_confirm_4}
anchorX: 0.5,
//{custom_confirm_5}
anchorY: 0.5 //{custom_confirm_6}
}); //{custom_confirm_7}
self.x = 1024; //{custom_confirm_8}
self.y = 1366; //{custom_confirm_9}
var messageText = new Text2(message, {
//{custom_confirm_10}
size: 60,
//{custom_confirm_11}
fill: 0xFFFFFF //{custom_confirm_12}
}); //{custom_confirm_13}
messageText.anchor.set(0.5, 0.5); //{custom_confirm_14}
messageText.x = 0; //{custom_confirm_15}
messageText.y = -100; //{custom_confirm_16}
self.addChild(messageText); //{custom_confirm_17}
var confirmBtn = self.addChild(new Container()); //{custom_confirm_18}
confirmBtn.attachAsset('button', {
//{custom_confirm_19}
anchorX: 0.5,
//{custom_confirm_20}
anchorY: 0.5 //{custom_confirm_21}
}); //{custom_confirm_22}
confirmBtn.x = -180; //{custom_confirm_23}
confirmBtn.y = 120; //{custom_confirm_24}
confirmBtn.interactive = true; //{custom_confirm_25}
var confirmLabel = confirmBtn.addChild(new Text2('YES', {
//{custom_confirm_26}
size: 50,
//{custom_confirm_27}
fill: 0xFFFFFF //{custom_confirm_28}
})); //{custom_confirm_29}
confirmLabel.anchor.set(0.5, 0.5); //{custom_confirm_30}
confirmBtn.down = function () {
//{custom_confirm_31}
game.removeChild(self); //{custom_confirm_32}
onConfirm(); //{custom_confirm_33}
}; //{custom_confirm_34}
var cancelBtn = self.addChild(new Container()); //{custom_confirm_35}
cancelBtn.attachAsset('buttonNegative', {
//{custom_confirm_36}
anchorX: 0.5,
//{custom_confirm_37}
anchorY: 0.5 //{custom_confirm_38}
}); //{custom_confirm_39}
cancelBtn.x = 180; //{custom_confirm_40}
cancelBtn.y = 120; //{custom_confirm_41}
cancelBtn.interactive = true; //{custom_confirm_42}
var cancelLabel = cancelBtn.addChild(new Text2('NO', {
//{custom_confirm_43}
size: 50,
//{custom_confirm_44}
fill: 0xFFFFFF //{custom_confirm_45}
})); //{custom_confirm_46}
cancelLabel.anchor.set(0.5, 0.5); //{custom_confirm_47}
cancelBtn.down = function () {
//{custom_confirm_48}
game.removeChild(self); //{custom_confirm_49}
onCancel(); //{custom_confirm_50}
}; //{custom_confirm_51}
}; //{custom_confirm_52}
return self; //{custom_confirm_53}
});
var CountryButton = Container.expand(function () {
var self = Container.call(this);
self.countryIndex = -1;
self.countryName = '';
self.buttonGraphic = null;
self.textLabel = null;
self.init = function (countryName, index) {
self.countryName = countryName;
self.countryIndex = index;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2(countryName, {
size: 70,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
playerCountryIndex = self.countryIndex;
storage.selectedCountry = self.countryIndex;
initializeGame();
LK.game.removeChild(countrySelection);
countrySelection = null;
};
return self;
});
var CountrySelectionScreen = Container.expand(function () {
var self = Container.call(this);
var countries = ['Iraq', 'Syria', 'Turkey', 'Saudi Arabia', 'Iran'];
var buttons = [];
self.init = function () {
var titleText = new Text2('Select Your Country', {
size: 140,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
self.addChild(titleText);
var buttonWidth = 300;
var buttonHeight = 100;
var spacing = 220;
var startY = 600;
for (var i = 0; i < countries.length; i++) {
var btn = self.addChild(new CountryButton());
btn.init(countries[i], i);
btn.x = 1024;
btn.y = startY + i * spacing;
buttons.push(btn);
}
var resetBtn = self.addChild(new ResetProgressButton()); //{custom_selection_reset_1}
resetBtn.init(); //{custom_selection_reset_2}
resetBtn.x = 1024; //{custom_selection_reset_3}
resetBtn.y = 2500; //{custom_selection_reset_4}
};
self.init();
return self;
});
var EconomicInvestmentButton = Container.expand(function () {
var self = Container.call(this);
self.targetProvince = null;
self.buttonGraphic = null;
self.textLabel = null;
self.investmentCost = 30;
self.init = function (targetProvince) {
self.targetProvince = targetProvince;
self.investmentCost = 30 + targetProvince.investmentLevel * 10;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonLabel = 'Invest ($' + self.investmentCost + ')';
if (targetProvince.investmentLevel >= 10) {
buttonLabel = 'Max Level (10)';
self.buttonGraphic.tint = 0x666666;
}
self.textLabel = self.addChild(new Text2(buttonLabel, {
size: 36,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
if (self.targetProvince.investmentLevel < 10 && money >= self.investmentCost) {
money -= self.investmentCost;
self.targetProvince.investmentLevel += 1;
moneyText.setText('Money: $' + money);
if (currentPanel) {
game.removeChild(currentPanel);
currentPanel = null;
}
} else if (self.targetProvince.investmentLevel >= 10) {
// Max level reached, do nothing
}
};
return self;
});
var InteractionButton = Container.expand(function () {
var self = Container.call(this);
self.countryIndex = -1;
self.isPositive = true;
self.buttonGraphic = null;
self.textLabel = null;
self.init = function (label, countryIndex, isPositive) {
self.countryIndex = countryIndex;
self.isPositive = isPositive;
var color = isPositive ? 'button' : 'buttonNegative';
self.buttonGraphic = self.attachAsset(color, {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2(label, {
size: 40,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
var change = self.isPositive ? 10 : -10;
relationships[self.countryIndex] += change;
if (relationships[self.countryIndex] <= -50 && !atWar[self.countryIndex]) {
atWar[self.countryIndex] = true;
}
if (currentPanel && currentPanel.closeBtn) {
var relationshipText = null;
for (var i = 0; i < currentPanel.children.length; i++) {
if (currentPanel.children[i].id === 'relationshipText') {
relationshipText = currentPanel.children[i];
break;
}
}
if (relationshipText) {
relationshipText.setText('Relationship: ' + relationships[self.countryIndex]);
}
}
};
return self;
});
var InteractionPanel = Container.expand(function () {
var self = Container.call(this);
self.targetProvince = null;
self.targetCountryIndex = -1;
self.panelGraphic = null;
self.closeBtn = null;
self.init = function (province) {
self.targetProvince = province;
self.targetCountryIndex = province.countryIndex;
self.panelGraphic = self.attachAsset('panel', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 1024;
self.y = 1366;
var targetCountryName = countryNames[self.targetCountryIndex];
var titleText = new Text2('Interact with ' + targetCountryName, {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 0;
titleText.y = -270;
self.addChild(titleText);
var relationshipText = new Text2('Relationship: ' + relationships[self.targetCountryIndex], {
size: 50,
fill: 0xFFEB3B
});
relationshipText.anchor.set(0.5, 0);
relationshipText.x = 0;
relationshipText.y = -200;
relationshipText.id = 'relationshipText';
self.addChild(relationshipText);
var warText = new Text2('', {
size: 50,
fill: 0xF44336
});
warText.anchor.set(0.5, 0);
warText.x = 0;
warText.y = -130;
if (atWar[self.targetCountryIndex]) {
warText.setText('AT WAR');
}
self.addChild(warText);
var provinceNameText = self.addChild(new Text2('Province Power: ' + province.power, {
size: 50,
fill: 0xFFFFFF
}));
provinceNameText.anchor.set(0.5, 0);
provinceNameText.x = 0;
provinceNameText.y = -60;
if (self.targetCountryIndex === playerCountryIndex) {
var investmentLevelText = self.addChild(new Text2('Level: ' + province.investmentLevel + '/10', {
size: 42,
fill: 0x00FF00
}));
investmentLevelText.anchor.set(0.5, 0);
investmentLevelText.x = 0;
investmentLevelText.y = 70;
var incomeText = self.addChild(new Text2('Income: +' + (2 + province.investmentLevel) + '/sec', {
size: 42,
fill: 0x00FF00
}));
incomeText.anchor.set(0.5, 0);
incomeText.x = 0;
incomeText.y = 140;
var defenseText = self.addChild(new Text2('Defense: ' + province.defenseLevel + '/10', {
//{custom_defense_text_1}
size: 42,
//{custom_defense_text_2}
fill: 0xFF6B9D //{custom_defense_text_3}
})); //{custom_defense_text_4}
defenseText.anchor.set(0.5, 0); //{custom_defense_text_5}
defenseText.x = 0; //{custom_defense_text_6}
defenseText.y = 210; //{custom_defense_text_7}
var investBtn = self.addChild(new EconomicInvestmentButton());
investBtn.init(province);
investBtn.x = -150;
investBtn.y = 300;
var defenseBtn = self.addChild(new ProvinceDefenseButton()); //{custom_defense_btn_panel_1}
defenseBtn.init(province); //{custom_defense_btn_panel_2}
defenseBtn.x = 150; //{custom_defense_btn_panel_3}
defenseBtn.y = 300; //{custom_defense_btn_panel_4}
} else {
var increaseBtn = self.addChild(new InteractionButton());
increaseBtn.init('+10 Relationship', self.targetCountryIndex, true);
increaseBtn.x = -220;
increaseBtn.y = 100;
var decreaseBtn = self.addChild(new InteractionButton());
decreaseBtn.init('-10 Relationship', self.targetCountryIndex, false);
decreaseBtn.x = 220;
decreaseBtn.y = 100;
}
self.closeBtn = self.addChild(new Container());
self.closeBtn.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.closeBtn.x = 370;
self.closeBtn.y = -270;
self.closeBtn.interactive = true;
var closeLabel = self.closeBtn.addChild(new Text2('X', {
size: 40,
fill: 0xFFFFFF
}));
closeLabel.anchor.set(0.5, 0.5);
self.closeBtn.down = function () {
LK.game.removeChild(self);
currentPanel = null;
};
};
return self;
});
var LevelCompleteScreen = Container.expand(function () {
var self = Container.call(this);
//{custom_lcs_1}
self.panelGraphic = null; //{custom_lcs_2}
self.init = function () {
self.panelGraphic = self.attachAsset('panel', {
anchorX: 0.5,
anchorY: 0.5
}); //{custom_lcs_3}
self.x = 1024;
self.y = 1366;
var titleText = new Text2('LEVEL COMPLETE!', {
size: 80,
fill: 0x4CAF50
}); //{custom_lcs_4}
titleText.anchor.set(0.5, 0.5);
titleText.x = 0;
titleText.y = -150;
self.addChild(titleText); //{custom_lcs_5}
var nextLevelText = new Text2('Level ' + (currentLevel + 1) + ' Starting...', {
size: 60,
fill: 0xFFFFFF
}); //{custom_lcs_6}
nextLevelText.anchor.set(0.5, 0.5);
nextLevelText.x = 0;
nextLevelText.y = 0;
self.addChild(nextLevelText); //{custom_lcs_7}
var bonusText = new Text2('Bonus: +50 Money', {
size: 40,
fill: 0xFFEB3B
}); //{custom_lcs_8}
bonusText.anchor.set(0.5, 0.5);
bonusText.x = 0;
bonusText.y = 100;
self.addChild(bonusText); //{custom_lcs_9}
}; //{custom_lcs_10}
self.init();
return self; //{custom_lcs_11}
});
//{custom_lcs_12}
var PowerUpButton = Container.expand(function () {
var self = Container.call(this);
self.buttonGraphic = null;
self.textLabel = null;
self.powerCost = 50;
self.init = function (powerCost) {
self.powerCost = powerCost;
self.buttonGraphic = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.textLabel = self.addChild(new Text2('Power +1 ($' + powerCost + ')', {
size: 40,
fill: 0xFFFFFF
}));
self.textLabel.anchor.set(0.5, 0.5);
self.textLabel.x = 0;
self.textLabel.y = 0;
self.interactive = true;
};
self.down = function (x, y, obj) {
if (money >= self.powerCost) {
money -= self.powerCost;
power += 1;
moneyText.setText('Money: $' + money);
powerText.setText('Power: ' + power);
}
};
return self;
});
var Province = Container.expand(function () {
var self = Container.call(this);
self.countryIndex = -1;
self.gridX = 0;
self.gridY = 0;
self.graphic = null;
self.init = function (gridX, gridY, countryIndex) {
self.gridX = gridX;
self.gridY = gridY;
self.countryIndex = countryIndex;
self.investmentLevel = 0;
self.defenseLevel = 0;
self.power = 50;
if (countryIndex === playerCountryIndex) {
//{custom_province_init_1}
self.power = 20; //{custom_province_init_2}
} //{custom_province_init_3}
self.lastIncomeTime = Date.now();
self.updateGraphic();
self.interactive = true;
};
self.updateGraphic = function () {
if (self.graphic) {
self.removeChild(self.graphic);
}
if (self.powerText) {
self.removeChild(self.powerText);
self.powerText = null;
}
var assetId = 'province';
if (self.countryIndex === -1) {
assetId = 'provinceNeutral';
} else if (self.countryIndex === playerCountryIndex) {
assetId = 'province';
} else if (self.countryIndex === 0) {
assetId = 'provinceIraq';
} else if (self.countryIndex === 1) {
assetId = 'provinceSyria';
} else if (self.countryIndex === 2) {
assetId = 'provinceTurkey';
} else if (self.countryIndex === 3) {
assetId = 'provinceSaudiArabia';
} else if (self.countryIndex === 4) {
assetId = 'provinceIran';
} else if (self.countryIndex === 5) {
//{custom_asset_egypt}
assetId = 'provinceEgypt'; //{custom_asset_egypt_2}
} else if (self.countryIndex === 6) {
//{custom_asset_israel}
assetId = 'provinceIsrael'; //{custom_asset_israel_2}
} else if (self.countryIndex === 7) {
//{custom_asset_yemen}
assetId = 'provinceYemen'; //{custom_asset_yemen_2}
} else if (self.countryIndex === 8) {
//{custom_asset_oman}
assetId = 'provinceOman'; //{custom_asset_oman_2}
}
self.graphic = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
if (atWar[self.countryIndex] && self.countryIndex !== playerCountryIndex && self.countryIndex !== -1) {
self.powerText = self.addChild(new Text2(self.power || '0', {
size: 24,
fill: 0xFFFFFF
}));
self.powerText.anchor.set(0.5, 0.5);
self.powerText.x = 0;
self.powerText.y = 0;
}
};
self.down = function (x, y, obj) {
if (self.countryIndex !== -1) {
openProvincePanel(self);
}
if (self.countryIndex === playerCountryIndex) {
openProvincePanel(self);
}
};
return self;
});
//{custom_confirm_54}
var ProvinceDefenseButton = Container.expand(function () {
var self = Container.call(this);
//{custom_defense_1}
//{custom_defense_2}
self.targetProvince = null; //{custom_defense_3}
self.buttonGraphic = null; //{custom_defense_4}
self.textLabel = null; //{custom_defense_5}
self.defenseCost = 40; //{custom_defense_6}
self.init = function (targetProvince) {
//{custom_defense_7}
self.targetProvince = targetProvince; //{custom_defense_8}
self.defenseCost = 40 + targetProvince.defenseLevel * 5; //{custom_defense_9}
self.buttonGraphic = self.attachAsset('button', {
//{custom_defense_10}
anchorX: 0.5,
//{custom_defense_11}
anchorY: 0.5 //{custom_defense_12}
}); //{custom_defense_13}
var buttonLabel = 'Upgrade Defense ($' + self.defenseCost + ')'; //{custom_defense_14}
if (targetProvince.defenseLevel >= 10) {
//{custom_defense_15}
buttonLabel = 'Max Defense (10)'; //{custom_defense_16}
self.buttonGraphic.tint = 0x666666; //{custom_defense_17}
} //{custom_defense_18}
self.textLabel = self.addChild(new Text2(buttonLabel, {
//{custom_defense_19}
size: 36,
//{custom_defense_20}
fill: 0xFFFFFF //{custom_defense_21}
})); //{custom_defense_22}
self.textLabel.anchor.set(0.5, 0.5); //{custom_defense_23}
self.textLabel.x = 0; //{custom_defense_24}
self.textLabel.y = 0; //{custom_defense_25}
self.interactive = true; //{custom_defense_26}
}; //{custom_defense_27}
self.down = function (x, y, obj) {
//{custom_defense_28}
if (self.targetProvince.defenseLevel < 10 && money >= self.defenseCost) {
//{custom_defense_29}
money -= self.defenseCost; //{custom_defense_30}
self.targetProvince.defenseLevel += 1; //{custom_defense_31}
self.targetProvince.power += 5; //{custom_defense_32}
moneyText.setText('Money: $' + money); //{custom_defense_33}
if (currentPanel) {
//{custom_defense_34}
game.removeChild(currentPanel); //{custom_defense_35}
currentPanel = null; //{custom_defense_36}
} //{custom_defense_37}
} else if (self.targetProvince.defenseLevel >= 10) {//{custom_defense_38}
// Max level reached, do nothing
} //{custom_defense_39}
}; //{custom_defense_40}
return self; //{custom_defense_41}
});
//{custom_defense_42}
var ResetProgressButton = Container.expand(function () {
var self = Container.call(this);
//{custom_reset_btn_1}
//{custom_reset_btn_2}
self.buttonGraphic = null; //{custom_reset_btn_3}
self.textLabel = null; //{custom_reset_btn_4}
self.init = function () {
//{custom_reset_btn_5}
self.buttonGraphic = self.attachAsset('buttonNegative', {
//{custom_reset_btn_6}
anchorX: 0.5,
//{custom_reset_btn_7}
anchorY: 0.5 //{custom_reset_btn_8}
}); //{custom_reset_btn_9}
self.textLabel = self.addChild(new Text2('Clear All Progress', {
//{custom_reset_btn_10}
size: 45,
//{custom_reset_btn_11}
fill: 0xFFFFFF //{custom_reset_btn_12}
})); //{custom_reset_btn_13}
self.textLabel.anchor.set(0.5, 0.5); //{custom_reset_btn_14}
self.textLabel.x = 0; //{custom_reset_btn_15}
self.textLabel.y = 0; //{custom_reset_btn_16}
self.interactive = true; //{custom_reset_btn_17}
}; //{custom_reset_btn_18}
self.down = function (x, y, obj) {
//{custom_reset_btn_19}
var confirmDialog = game.addChild(new ConfirmationDialog()); //{custom_reset_btn_20}
confirmDialog.init('Clear all progress?', function () {
//{custom_reset_btn_21}
storage.selectedCountry = 'undefined'; //{custom_reset_btn_22}
storage.currentLevel = 1; //{custom_reset_btn_23}
playerCountryIndex = -1; //{custom_reset_btn_24}
currentLevel = 1; //{custom_reset_btn_25}
money = 100; //{custom_reset_btn_26}
power = 10; //{custom_reset_btn_27}
provinces = []; //{custom_reset_btn_28}
while (game.children.length > 0) {
//{custom_reset_btn_29}
game.removeChild(game.children[0]); //{custom_reset_btn_30}
} //{custom_reset_btn_31}
LK.gui.topLeft.removeChild(moneyText); //{custom_reset_btn_32}
LK.gui.topLeft.removeChild(powerText); //{custom_reset_btn_33}
LK.gui.top.removeChild(levelText); //{custom_reset_btn_34}
for (var i = LK.gui.bottom.children.length - 1; i >= 0; i--) {
//{custom_reset_btn_35}
LK.gui.bottom.removeChild(LK.gui.bottom.children[i]); //{custom_reset_btn_36}
} //{custom_reset_btn_37}
initializeGame(); //{custom_reset_btn_38}
}, function () {//{custom_reset_btn_39}
// Cancel - do nothing
}); //{custom_reset_btn_40}
}; //{custom_reset_btn_41}
return self; //{custom_reset_btn_42}
});
/****
* Initialize Game
****/
//{custom_reset_btn_43}
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
LK.game = game;
/****
* Game Variables
****/
var countryNames = ['Iraq', 'Syria', 'Turkey', 'Saudi Arabia', 'Iran', 'Egypt', 'Israel', 'Yemen', 'Oman'];
var relationships = [0, 0, 0, 0, 0, 0, 0, 0, 0];
var atWar = [false, false, false, false, false, false, false, false, false];
var playerCountryIndex = storage.selectedCountry !== undefined ? storage.selectedCountry : -1;
var currentLevel = storage.currentLevel || 1;
var money = 100;
var power = 10;
var provinces = [];
var countrySelection = null;
var currentPanel = null;
var moneyText = null;
var powerText = null;
var levelText = null;
function initializeMap() {
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
var difficultyMultiplier = 1 + (currentLevel - 1) * 0.15;
var mapWidth = 8; //{custom_map_width}
var mapHeight = 8; //{custom_map_height}
var provinceSize = 100; //{custom_map_size}
var totalMapWidth = mapWidth * provinceSize;
var totalMapHeight = mapHeight * provinceSize;
var startX = (2048 - totalMapWidth) / 2;
var startY = (2732 - totalMapHeight) / 2 + 100;
function getCountryPowerRange(countryIndex) {
if (countryIndex === playerCountryIndex) {
return {
min: 50,
max: 100
};
}
if (countryIndex === 0) {
return {
min: 20,
max: 35
};
}
if (countryIndex === 1) {
return {
min: 20,
max: 20
};
}
if (countryIndex === 2) {
return {
min: 65,
max: 70
};
}
if (countryIndex === 3) {
return {
min: 40,
max: 50
};
}
if (countryIndex === 4) {
return {
min: 60,
max: 65
};
}
if (countryIndex === 5) {
//{custom_egypt_range}
return {
//{custom_egypt_range_2}
min: 35,
//{custom_egypt_range_3}
max: 45 //{custom_egypt_range_4}
}; //{custom_egypt_range_5}
} //{custom_egypt_range_6}
if (countryIndex === 6) {
//{custom_israel_range}
return {
//{custom_israel_range_2}
min: 40,
//{custom_israel_range_3}
max: 55 //{custom_israel_range_4}
}; //{custom_israel_range_5}
} //{custom_israel_range_6}
if (countryIndex === 7) {
//{custom_yemen_range}
return {
//{custom_yemen_range_2}
min: 25,
//{custom_yemen_range_3}
max: 40 //{custom_yemen_range_4}
}; //{custom_yemen_range_5}
} //{custom_yemen_range_6}
if (countryIndex === 8) {
//{custom_oman_range}
return {
//{custom_oman_range_2}
min: 30,
//{custom_oman_range_3}
max: 45 //{custom_oman_range_4}
}; //{custom_oman_range_5}
} //{custom_oman_range_6}
return {
min: 30,
max: 50
};
}
for (var y = 0; y < mapHeight; y++) {
for (var x = 0; x < mapWidth; x++) {
var randomCountry = Math.floor(Math.random() * 9); //{custom_random_9}
var province = game.addChild(new Province());
province.init(x, y, randomCountry);
province.x = startX + x * provinceSize + provinceSize / 2;
province.y = startY + y * provinceSize + provinceSize / 2;
var powerRange = getCountryPowerRange(randomCountry);
var basePower = powerRange.min + Math.floor(Math.random() * (powerRange.max - powerRange.min + 1));
province.power = Math.floor(basePower * difficultyMultiplier);
provinces.push(province);
}
}
for (var i = 0; i < 9; i++) {
//{custom_reset_9}
relationships[i] = 0;
atWar[i] = false;
} //{custom_reset_relationships}
var playerCountriesToConquer = 12; //{custom_conquer_12}
var assignedCount = 0;
for (var i = 0; i < provinces.length && assignedCount < playerCountriesToConquer; i++) {
var randomIndex = Math.floor(Math.random() * provinces.length);
if (provinces[randomIndex].countryIndex !== playerCountryIndex) {
provinces[randomIndex].countryIndex = playerCountryIndex;
provinces[randomIndex].investmentLevel = 0;
provinces[randomIndex].defenseLevel = 0; //{custom_init_defense_level}
provinces[randomIndex].updateGraphic();
assignedCount += 1;
}
}
}
function openProvincePanel(province) {
if (currentPanel) {
game.removeChild(currentPanel);
}
currentPanel = game.addChild(new InteractionPanel());
currentPanel.init(province);
if (atWar[province.countryIndex]) {
var captureBtn = currentPanel.addChild(new CaptureButton());
captureBtn.init('CAPTURE PROVINCE', province);
captureBtn.x = 0;
captureBtn.y = 250;
}
}
function showLevelComplete() {
game.update = function () {};
var levelCompleteScreen = game.addChild(new LevelCompleteScreen());
currentLevel += 1;
storage.currentLevel = currentLevel;
money += 50;
LK.setTimeout(function () {
while (game.children.length > 0) {
game.removeChild(game.children[0]);
}
LK.gui.top.removeChild(levelText);
LK.gui.topLeft.removeChild(moneyText);
LK.gui.topLeft.removeChild(powerText);
LK.gui.bottom.removeChild(LK.gui.bottom.children[0]);
provinces = [];
initializeMap();
moneyText = new Text2('Money: $' + money, {
size: 90,
fill: 0xFFFFFF
});
moneyText.anchor.set(0, 0);
moneyText.x = 30;
moneyText.y = 30;
LK.gui.topLeft.addChild(moneyText);
powerText = new Text2('Power: ' + power, {
size: 90,
fill: 0xFFEB3B
});
powerText.anchor.set(0, 0);
powerText.x = 30;
powerText.y = 140;
LK.gui.topLeft.addChild(powerText);
levelText = new Text2('Level ' + currentLevel, {
size: 90,
fill: 0x4CAF50
});
levelText.anchor.set(0.5, 0);
levelText.x = 0;
levelText.y = 40;
LK.gui.top.addChild(levelText);
var powerUpBtn = LK.gui.bottom.addChild(new PowerUpButton());
powerUpBtn.init(50);
powerUpBtn.x = 0;
powerUpBtn.y = -120;
game.update = function () {
if (LK.ticks % 60 === 0) {
var incomePerSecond = 0;
var playerProvincesCount = 0;
var totalProvincesCount = 0;
for (var p = 0; p < provinces.length; p++) {
totalProvincesCount += 1;
if (provinces[p].countryIndex === playerCountryIndex) {
incomePerSecond += 2 + provinces[p].investmentLevel;
playerProvincesCount += 1;
}
}
money += incomePerSecond;
moneyText.setText('Money: $' + money);
if (playerProvincesCount === totalProvincesCount && totalProvincesCount > 0) {
showLevelComplete();
}
}
};
}, 3000);
} //{custom_show_level_complete}
function initializeGame() {
if (playerCountryIndex === -1) {
countrySelection = game.addChild(new CountrySelectionScreen());
return;
}
while (game.children.length > 0) {
game.removeChild(game.children[0]);
}
initializeMap();
moneyText = new Text2('Money: $' + money, {
size: 90,
fill: 0xFFFFFF
});
moneyText.anchor.set(0, 0);
moneyText.x = 30;
moneyText.y = 30;
LK.gui.topLeft.addChild(moneyText);
powerText = new Text2('Power: ' + power, {
size: 90,
fill: 0xFFEB3B
});
powerText.anchor.set(0, 0);
powerText.x = 30;
powerText.y = 140;
LK.gui.topLeft.addChild(powerText);
levelText = new Text2('Level ' + currentLevel, {
size: 90,
fill: 0x4CAF50
});
levelText.anchor.set(0.5, 0);
levelText.x = 0;
levelText.y = 40;
LK.gui.top.addChild(levelText);
var powerUpBtn = LK.gui.bottom.addChild(new PowerUpButton());
powerUpBtn.init(50);
powerUpBtn.x = 0;
powerUpBtn.y = -120;
game.update = function () {
if (LK.ticks % 60 === 0) {
var incomePerSecond = 0;
var playerProvincesCount = 0;
var totalProvincesCount = 0;
for (var p = 0; p < provinces.length; p++) {
totalProvincesCount += 1;
if (provinces[p].countryIndex === playerCountryIndex) {
incomePerSecond += 2 + provinces[p].investmentLevel;
playerProvincesCount += 1;
}
}
money += incomePerSecond;
moneyText.setText('Money: $' + money);
if (playerProvincesCount === totalProvincesCount && totalProvincesCount > 0) {
showLevelComplete();
} //{custom_level_check}
}
};
}
if (playerCountryIndex === -1) {
countrySelection = game.addChild(new CountrySelectionScreen());
} else {
initializeGame();
}
LK.playMusic('TheConquest', {
loop: true,
fade: {
start: 0,
end: 0.3,
duration: 2000
}
});
//{custom_reset_btn_43}