User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.save_0 = undefined;' Line Number: 353 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Correction des sauvegarde et de l’histoire interactif ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage['save_' + i] = saves[i];' Line Number: 354 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.saves = saves;' Line Number: 344 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.set('saves', saves);' Line Number: 344 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.saves = saves;' Line Number: 344
User prompt
Please fix the bug: 'storage.get is not a function. (In 'storage.get('saves')', 'storage.get' is undefined)' in or related to this line: 'var saves = storage.get('saves');' Line Number: 340
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.set('saves', saves);' Line Number: 343
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.saves = saves;' Line Number: 343
Code edit (1 edits merged)
Please save this source code
User prompt
Pokémon Aventure : Générations 1 à 8 (FR)
Initial prompt
Un jeu Pokémon de la 1g à la 8g et en mode texte et en mode français texte choix entre plusieurs et plusieurs sauvegardes sauvegarder sur votre compte
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
saves: []
});
/****
* Classes
****/
// --- Choice Button ---
var ChoiceButton = Container.expand(function () {
var self = Container.call(this);
self.textObj = null;
self.callback = null;
self.setChoice = function (label, callback) {
if (self.textObj) self.removeChild(self.textObj);
self.textObj = new Text2(label, {
size: 80,
fill: "#fff"
});
self.textObj.anchor.set(0.5, 0.5);
self.addChild(self.textObj);
self.width = self.textObj.width + 80;
self.height = self.textObj.height + 40;
self.callback = callback;
};
self.down = function (x, y, obj) {
if (self.callback) self.callback();
};
return self;
});
// --- Main Text Box ---
var MainTextBox = Container.expand(function () {
var self = Container.call(this);
self.textObj = null;
self.setText = function (txt) {
if (self.textObj) self.removeChild(self.textObj);
self.textObj = new Text2(txt, {
size: 90,
fill: "#fff"
});
self.textObj.anchor.set(0.5, 0);
self.addChild(self.textObj);
self.width = self.textObj.width;
self.height = self.textObj.height;
};
return self;
});
// --- Save Slot Button ---
var SaveSlotButton = Container.expand(function () {
var self = Container.call(this);
self.index = 0;
self.saveData = null;
self.text = null;
self.setSlot = function (index, saveData) {
self.index = index;
self.saveData = saveData;
if (self.text) self.removeChild(self.text);
var label = saveData ? "Sauvegarde " + (index + 1) + " : " + (saveData.starterName || "Aventure") + " (" + (saveData.region || "Début") + ")" : "Nouvelle partie";
self.text = new Text2(label, {
size: 80,
fill: "#fff"
});
self.text.anchor.set(0.5, 0.5);
self.addChild(self.text);
self.width = self.text.width + 80;
self.height = self.text.height + 40;
};
self.down = function (x, y, obj) {
if (self.saveData) {
loadGame(self.index);
} else {
startNewGame(self.index);
}
};
return self;
});
// --- Team Display (minimal for MVP) ---
var TeamDisplay = Container.expand(function () {
var self = Container.call(this);
self.textObj = null;
self.setTeam = function (team) {
var txt = "Équipe : " + (team && team.length ? team.map(function (p) {
return p.name;
}).join(", ") : "aucun");
if (self.textObj) self.removeChild(self.textObj);
self.textObj = new Text2(txt, {
size: 60,
fill: "#fff"
});
self.textObj.anchor.set(0.5, 0.5);
self.addChild(self.textObj);
self.width = self.textObj.width;
self.height = self.textObj.height;
};
return self;
});
/****
* Initialize Game
****/
/****
* Data
****/
// --- Starters by Generation (minimal set for MVP, can be expanded) ---
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
// --- Starters by Generation (minimal set for MVP, can be expanded) ---
/****
* Data
****/
// Storage for save slots and persistent player data
// Tween for future UI animations (not used in MVP, but included for extensibility)
// --- Global UI Elements ---
var startersByGen = [
// Gen 1
[{
name: "Bulbizarre",
species: "Bulbasaur",
type: "Plante/Poison",
gen: 1
}, {
name: "Salamèche",
species: "Charmander",
type: "Feu",
gen: 1
}, {
name: "Carapuce",
species: "Squirtle",
type: "Eau",
gen: 1
}],
// Gen 2
[{
name: "Germignon",
species: "Chikorita",
type: "Plante",
gen: 2
}, {
name: "Héricendre",
species: "Cyndaquil",
type: "Feu",
gen: 2
}, {
name: "Kaiminus",
species: "Totodile",
type: "Eau",
gen: 2
}],
// Gen 3
[{
name: "Arcko",
species: "Treecko",
type: "Plante",
gen: 3
}, {
name: "Poussifeu",
species: "Torchic",
type: "Feu",
gen: 3
}, {
name: "Gobou",
species: "Mudkip",
type: "Eau",
gen: 3
}],
// Gen 4
[{
name: "Tortipouss",
species: "Turtwig",
type: "Plante",
gen: 4
}, {
name: "Ouisticram",
species: "Chimchar",
type: "Feu",
gen: 4
}, {
name: "Tiplouf",
species: "Piplup",
type: "Eau",
gen: 4
}],
// Gen 5
[{
name: "Vipélierre",
species: "Snivy",
type: "Plante",
gen: 5
}, {
name: "Gruikui",
species: "Tepig",
type: "Feu",
gen: 5
}, {
name: "Moustillon",
species: "Oshawott",
type: "Eau",
gen: 5
}],
// Gen 6
[{
name: "Marisson",
species: "Chespin",
type: "Plante",
gen: 6
}, {
name: "Feunnec",
species: "Fennekin",
type: "Feu",
gen: 6
}, {
name: "Grenousse",
species: "Froakie",
type: "Eau",
gen: 6
}],
// Gen 7
[{
name: "Brindibou",
species: "Rowlet",
type: "Plante/Vol",
gen: 7
}, {
name: "Flamiaou",
species: "Litten",
type: "Feu",
gen: 7
}, {
name: "Otaquin",
species: "Popplio",
type: "Eau",
gen: 7
}],
// Gen 8
[{
name: "Ouistempo",
species: "Grookey",
type: "Plante",
gen: 8
}, {
name: "Flambino",
species: "Scorbunny",
type: "Feu",
gen: 8
}, {
name: "Larméléon",
species: "Sobble",
type: "Eau",
gen: 8
}]];
// --- Regions by Generation ---
var regionsByGen = ["Kanto", "Johto", "Hoenn", "Sinnoh", "Unys", "Kalos", "Alola", "Galar"];
var mainText = new MainTextBox();
mainText.setText("");
mainText.x = 2048 / 2;
mainText.y = 350;
game.addChild(mainText);
var teamDisplay = new TeamDisplay();
teamDisplay.setTeam([]);
teamDisplay.x = 2048 / 2;
teamDisplay.y = 250;
game.addChild(teamDisplay);
// --- Choice Buttons (max 4 for MVP) ---
var choiceButtons = [];
for (var i = 0; i < 4; i++) {
var btn = new ChoiceButton();
btn.x = 2048 / 2;
btn.y = 1100 + i * 220;
game.addChild(btn);
choiceButtons.push(btn);
}
// --- Save Slot Buttons (max 3 for MVP) ---
var saveSlotButtons = [];
for (var i = 0; i < 3; i++) {
var slot = new SaveSlotButton();
slot.x = 2048 / 2;
slot.y = 700 + i * 220;
game.addChild(slot);
saveSlotButtons.push(slot);
}
// --- Hide/Show UI helpers ---
function showMainText(txt) {
mainText.setText(txt);
mainText.visible = true;
}
function hideMainText() {
mainText.visible = false;
}
function showChoices(choices) {
for (var i = 0; i < choiceButtons.length; i++) {
if (choices[i]) {
choiceButtons[i].setChoice(choices[i].label, choices[i].callback);
choiceButtons[i].visible = true;
} else {
choiceButtons[i].visible = false;
}
}
}
function hideChoices() {
for (var i = 0; i < choiceButtons.length; i++) {
choiceButtons[i].visible = false;
}
}
function showSaveSlots() {
for (var i = 0; i < saveSlotButtons.length; i++) {
saveSlotButtons[i].visible = true;
}
}
function hideSaveSlots() {
for (var i = 0; i < saveSlotButtons.length; i++) {
saveSlotButtons[i].visible = false;
}
}
function updateTeamDisplay(team) {
teamDisplay.setTeam(team);
}
// --- Game State ---
var currentSaveIndex = null;
var currentSave = null;
// --- Save/Load helpers ---
function getSaves() {
return storage.saves && storage.saves.length ? storage.saves : [];
}
function setSaves(saves) {
storage.saves = saves;
}
function saveCurrentGame() {
if (currentSaveIndex === null) return;
var saves = getSaves();
saves[currentSaveIndex] = currentSave;
setSaves(saves);
}
function loadGame(index) {
var saves = getSaves();
currentSaveIndex = index;
currentSave = saves[index];
hideSaveSlots();
updateTeamDisplay(currentSave.team);
showMainText("Bienvenue de retour à l'aventure Pokémon !\nRégion : " + currentSave.region + "\nStarter : " + currentSave.starterName);
showChoices([{
label: "Continuer l'aventure",
callback: function callback() {
enterRegion(currentSave.region);
}
}, {
label: "Voir l'équipe",
callback: function callback() {
showTeamMenu();
}
}, {
label: "Sauvegarder",
callback: function callback() {
saveCurrentGame();
showMainText("Partie sauvegardée !");
hideChoices();
showChoices([{
label: "Continuer",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
}]);
}
function startNewGame(index) {
currentSaveIndex = index;
currentSave = {
region: null,
starter: null,
starterName: null,
team: [],
bag: [],
progress: {}
};
hideSaveSlots();
chooseGeneration();
}
function updateSaveSlots() {
var saves = getSaves();
for (var i = 0; i < saveSlotButtons.length; i++) {
saveSlotButtons[i].setSlot(i, saves[i]);
}
}
// --- Main Menu ---
function showMainMenu() {
hideChoices();
hideMainText();
updateSaveSlots();
showSaveSlots();
showMainText("Pokémon Aventure : Générations 1 à 8\n\nChoisissez une sauvegarde :");
}
// --- Generation/Starter Selection ---
function chooseGeneration() {
showMainText("Choisissez la génération de départ :");
var choices = [];
for (var i = 0; i < startersByGen.length; i++) {
(function (genIndex) {
choices.push({
label: "Génération " + (genIndex + 1) + " (" + regionsByGen[genIndex] + ")",
callback: function callback() {
chooseStarter(genIndex);
}
});
})(i);
}
showChoices(choices);
}
function chooseStarter(genIndex) {
currentSave.region = regionsByGen[genIndex];
showMainText("Choisissez votre Pokémon de départ :");
var starters = startersByGen[genIndex];
var choices = [];
for (var i = 0; i < starters.length; i++) {
(function (starter) {
choices.push({
label: starter.name + " (" + starter.type + ")",
callback: function callback() {
currentSave.starter = starter;
currentSave.starterName = starter.name;
currentSave.team = [starter];
saveCurrentGame();
updateTeamDisplay(currentSave.team);
showMainText("Félicitations ! Vous avez choisi " + starter.name + " comme starter.\nL'aventure commence dans la région " + currentSave.region + " !");
showChoices([{
label: "Commencer l'aventure",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
});
})(starters[i]);
}
showChoices(choices);
}
// --- Region Exploration (MVP: simple random event or battle) ---
function enterRegion(region) {
showMainText("Vous explorez la région de " + region + ". Que souhaitez-vous faire ?");
showChoices([{
label: "Explorer",
callback: function callback() {
randomEvent();
}
}, {
label: "Voir l'équipe",
callback: function callback() {
showTeamMenu();
}
}, {
label: "Sauvegarder",
callback: function callback() {
saveCurrentGame();
showMainText("Partie sauvegardée !");
hideChoices();
showChoices([{
label: "Continuer",
callback: function callback() {
enterRegion(region);
}
}]);
}
}, {
label: "Retour au menu",
callback: function callback() {
showMainMenu();
}
}]);
}
// --- Team Menu (MVP: just list) ---
function showTeamMenu() {
var team = currentSave.team;
var txt = "Votre équipe :\n";
for (var i = 0; i < team.length; i++) {
txt += "- " + team[i].name + " (" + team[i].type + ")\n";
}
showMainText(txt);
showChoices([{
label: "Retour",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
// --- Random Event (MVP: wild Pokémon or trainer) ---
function randomEvent() {
var r = Math.random();
if (r < 0.5) {
// Wild Pokémon
var wild = getRandomWildPokemon();
showMainText("Un Pokémon sauvage apparaît : " + wild.name + " (" + wild.type + ") !");
showChoices([{
label: "Combattre",
callback: function callback() {
startBattle(wild);
}
}, {
label: "Fuir",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
} else {
// Trainer
showMainText("Un dresseur vous défie !");
showChoices([{
label: "Combattre",
callback: function callback() {
startTrainerBattle();
}
}, {
label: "Fuir",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
}
// --- Wild Pokémon generator (MVP: pick from starters of any gen) ---
function getRandomWildPokemon() {
var all = [];
for (var i = 0; i < startersByGen.length; i++) {
for (var j = 0; j < startersByGen[i].length; j++) {
all.push(startersByGen[i][j]);
}
}
return all[Math.floor(Math.random() * all.length)];
}
// --- Battle System (MVP: simple turn-based, win = catch, lose = nothing) ---
function startBattle(wild) {
showMainText("Le combat commence contre " + wild.name + " !");
showChoices([{
label: "Attaquer",
callback: function callback() {
battleTurn(wild, true);
}
}, {
label: "Lancer une Pokéball",
callback: function callback() {
tryCatch(wild);
}
}, {
label: "Fuir",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
function battleTurn(wild, playerAttack) {
if (playerAttack) {
// MVP: always win
showMainText("Votre Pokémon attaque !\n" + wild.name + " est affaibli !");
showChoices([{
label: "Lancer une Pokéball",
callback: function callback() {
tryCatch(wild);
}
}, {
label: "Attaquer encore",
callback: function callback() {
battleTurn(wild, true);
}
}, {
label: "Fuir",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
}
function tryCatch(wild) {
// MVP: 70% chance
if (Math.random() < 0.7) {
currentSave.team.push(wild);
saveCurrentGame();
updateTeamDisplay(currentSave.team);
showMainText("Félicitations ! Vous avez capturé " + wild.name + " !");
showChoices([{
label: "Continuer",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
} else {
showMainText("Oh non ! " + wild.name + " s'est échappé !");
showChoices([{
label: "Réessayer",
callback: function callback() {
tryCatch(wild);
}
}, {
label: "Fuir",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
}
// --- Trainer Battle (MVP: always win) ---
function startTrainerBattle() {
showMainText("Le combat contre le dresseur commence !");
showChoices([{
label: "Attaquer",
callback: function callback() {
winTrainerBattle();
}
}, {
label: "Fuir",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
function winTrainerBattle() {
showMainText("Vous avez vaincu le dresseur !\nVotre équipe gagne de l'expérience.");
showChoices([{
label: "Continuer",
callback: function callback() {
enterRegion(currentSave.region);
}
}]);
}
// --- Game Start ---
showMainMenu();
/****
* Touch Handling (for mobile)
****/
// All buttons are handled via their .down methods (see classes above)
// No additional code needed for MVP
/****
* GUI (Score, Timer, etc.)
****/
// Not used in MVP
/****
* Music, Sound, etc.
****/
// Not used in MVP ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,644 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ saves: []
+});
+
+/****
+* Classes
+****/
+// --- Choice Button ---
+var ChoiceButton = Container.expand(function () {
+ var self = Container.call(this);
+ self.textObj = null;
+ self.callback = null;
+ self.setChoice = function (label, callback) {
+ if (self.textObj) self.removeChild(self.textObj);
+ self.textObj = new Text2(label, {
+ size: 80,
+ fill: "#fff"
+ });
+ self.textObj.anchor.set(0.5, 0.5);
+ self.addChild(self.textObj);
+ self.width = self.textObj.width + 80;
+ self.height = self.textObj.height + 40;
+ self.callback = callback;
+ };
+ self.down = function (x, y, obj) {
+ if (self.callback) self.callback();
+ };
+ return self;
+});
+// --- Main Text Box ---
+var MainTextBox = Container.expand(function () {
+ var self = Container.call(this);
+ self.textObj = null;
+ self.setText = function (txt) {
+ if (self.textObj) self.removeChild(self.textObj);
+ self.textObj = new Text2(txt, {
+ size: 90,
+ fill: "#fff"
+ });
+ self.textObj.anchor.set(0.5, 0);
+ self.addChild(self.textObj);
+ self.width = self.textObj.width;
+ self.height = self.textObj.height;
+ };
+ return self;
+});
+// --- Save Slot Button ---
+var SaveSlotButton = Container.expand(function () {
+ var self = Container.call(this);
+ self.index = 0;
+ self.saveData = null;
+ self.text = null;
+ self.setSlot = function (index, saveData) {
+ self.index = index;
+ self.saveData = saveData;
+ if (self.text) self.removeChild(self.text);
+ var label = saveData ? "Sauvegarde " + (index + 1) + " : " + (saveData.starterName || "Aventure") + " (" + (saveData.region || "Début") + ")" : "Nouvelle partie";
+ self.text = new Text2(label, {
+ size: 80,
+ fill: "#fff"
+ });
+ self.text.anchor.set(0.5, 0.5);
+ self.addChild(self.text);
+ self.width = self.text.width + 80;
+ self.height = self.text.height + 40;
+ };
+ self.down = function (x, y, obj) {
+ if (self.saveData) {
+ loadGame(self.index);
+ } else {
+ startNewGame(self.index);
+ }
+ };
+ return self;
+});
+// --- Team Display (minimal for MVP) ---
+var TeamDisplay = Container.expand(function () {
+ var self = Container.call(this);
+ self.textObj = null;
+ self.setTeam = function (team) {
+ var txt = "Équipe : " + (team && team.length ? team.map(function (p) {
+ return p.name;
+ }).join(", ") : "aucun");
+ if (self.textObj) self.removeChild(self.textObj);
+ self.textObj = new Text2(txt, {
+ size: 60,
+ fill: "#fff"
+ });
+ self.textObj.anchor.set(0.5, 0.5);
+ self.addChild(self.textObj);
+ self.width = self.textObj.width;
+ self.height = self.textObj.height;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
+/****
+* Data
+****/
+// --- Starters by Generation (minimal set for MVP, can be expanded) ---
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a2e
+});
+
+/****
+* Game Code
+****/
+// --- Starters by Generation (minimal set for MVP, can be expanded) ---
+/****
+* Data
+****/
+// Storage for save slots and persistent player data
+// Tween for future UI animations (not used in MVP, but included for extensibility)
+// --- Global UI Elements ---
+var startersByGen = [
+// Gen 1
+[{
+ name: "Bulbizarre",
+ species: "Bulbasaur",
+ type: "Plante/Poison",
+ gen: 1
+}, {
+ name: "Salamèche",
+ species: "Charmander",
+ type: "Feu",
+ gen: 1
+}, {
+ name: "Carapuce",
+ species: "Squirtle",
+ type: "Eau",
+ gen: 1
+}],
+// Gen 2
+[{
+ name: "Germignon",
+ species: "Chikorita",
+ type: "Plante",
+ gen: 2
+}, {
+ name: "Héricendre",
+ species: "Cyndaquil",
+ type: "Feu",
+ gen: 2
+}, {
+ name: "Kaiminus",
+ species: "Totodile",
+ type: "Eau",
+ gen: 2
+}],
+// Gen 3
+[{
+ name: "Arcko",
+ species: "Treecko",
+ type: "Plante",
+ gen: 3
+}, {
+ name: "Poussifeu",
+ species: "Torchic",
+ type: "Feu",
+ gen: 3
+}, {
+ name: "Gobou",
+ species: "Mudkip",
+ type: "Eau",
+ gen: 3
+}],
+// Gen 4
+[{
+ name: "Tortipouss",
+ species: "Turtwig",
+ type: "Plante",
+ gen: 4
+}, {
+ name: "Ouisticram",
+ species: "Chimchar",
+ type: "Feu",
+ gen: 4
+}, {
+ name: "Tiplouf",
+ species: "Piplup",
+ type: "Eau",
+ gen: 4
+}],
+// Gen 5
+[{
+ name: "Vipélierre",
+ species: "Snivy",
+ type: "Plante",
+ gen: 5
+}, {
+ name: "Gruikui",
+ species: "Tepig",
+ type: "Feu",
+ gen: 5
+}, {
+ name: "Moustillon",
+ species: "Oshawott",
+ type: "Eau",
+ gen: 5
+}],
+// Gen 6
+[{
+ name: "Marisson",
+ species: "Chespin",
+ type: "Plante",
+ gen: 6
+}, {
+ name: "Feunnec",
+ species: "Fennekin",
+ type: "Feu",
+ gen: 6
+}, {
+ name: "Grenousse",
+ species: "Froakie",
+ type: "Eau",
+ gen: 6
+}],
+// Gen 7
+[{
+ name: "Brindibou",
+ species: "Rowlet",
+ type: "Plante/Vol",
+ gen: 7
+}, {
+ name: "Flamiaou",
+ species: "Litten",
+ type: "Feu",
+ gen: 7
+}, {
+ name: "Otaquin",
+ species: "Popplio",
+ type: "Eau",
+ gen: 7
+}],
+// Gen 8
+[{
+ name: "Ouistempo",
+ species: "Grookey",
+ type: "Plante",
+ gen: 8
+}, {
+ name: "Flambino",
+ species: "Scorbunny",
+ type: "Feu",
+ gen: 8
+}, {
+ name: "Larméléon",
+ species: "Sobble",
+ type: "Eau",
+ gen: 8
+}]];
+// --- Regions by Generation ---
+var regionsByGen = ["Kanto", "Johto", "Hoenn", "Sinnoh", "Unys", "Kalos", "Alola", "Galar"];
+var mainText = new MainTextBox();
+mainText.setText("");
+mainText.x = 2048 / 2;
+mainText.y = 350;
+game.addChild(mainText);
+var teamDisplay = new TeamDisplay();
+teamDisplay.setTeam([]);
+teamDisplay.x = 2048 / 2;
+teamDisplay.y = 250;
+game.addChild(teamDisplay);
+// --- Choice Buttons (max 4 for MVP) ---
+var choiceButtons = [];
+for (var i = 0; i < 4; i++) {
+ var btn = new ChoiceButton();
+ btn.x = 2048 / 2;
+ btn.y = 1100 + i * 220;
+ game.addChild(btn);
+ choiceButtons.push(btn);
+}
+// --- Save Slot Buttons (max 3 for MVP) ---
+var saveSlotButtons = [];
+for (var i = 0; i < 3; i++) {
+ var slot = new SaveSlotButton();
+ slot.x = 2048 / 2;
+ slot.y = 700 + i * 220;
+ game.addChild(slot);
+ saveSlotButtons.push(slot);
+}
+// --- Hide/Show UI helpers ---
+function showMainText(txt) {
+ mainText.setText(txt);
+ mainText.visible = true;
+}
+function hideMainText() {
+ mainText.visible = false;
+}
+function showChoices(choices) {
+ for (var i = 0; i < choiceButtons.length; i++) {
+ if (choices[i]) {
+ choiceButtons[i].setChoice(choices[i].label, choices[i].callback);
+ choiceButtons[i].visible = true;
+ } else {
+ choiceButtons[i].visible = false;
+ }
+ }
+}
+function hideChoices() {
+ for (var i = 0; i < choiceButtons.length; i++) {
+ choiceButtons[i].visible = false;
+ }
+}
+function showSaveSlots() {
+ for (var i = 0; i < saveSlotButtons.length; i++) {
+ saveSlotButtons[i].visible = true;
+ }
+}
+function hideSaveSlots() {
+ for (var i = 0; i < saveSlotButtons.length; i++) {
+ saveSlotButtons[i].visible = false;
+ }
+}
+function updateTeamDisplay(team) {
+ teamDisplay.setTeam(team);
+}
+// --- Game State ---
+var currentSaveIndex = null;
+var currentSave = null;
+// --- Save/Load helpers ---
+function getSaves() {
+ return storage.saves && storage.saves.length ? storage.saves : [];
+}
+function setSaves(saves) {
+ storage.saves = saves;
+}
+function saveCurrentGame() {
+ if (currentSaveIndex === null) return;
+ var saves = getSaves();
+ saves[currentSaveIndex] = currentSave;
+ setSaves(saves);
+}
+function loadGame(index) {
+ var saves = getSaves();
+ currentSaveIndex = index;
+ currentSave = saves[index];
+ hideSaveSlots();
+ updateTeamDisplay(currentSave.team);
+ showMainText("Bienvenue de retour à l'aventure Pokémon !\nRégion : " + currentSave.region + "\nStarter : " + currentSave.starterName);
+ showChoices([{
+ label: "Continuer l'aventure",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }, {
+ label: "Voir l'équipe",
+ callback: function callback() {
+ showTeamMenu();
+ }
+ }, {
+ label: "Sauvegarder",
+ callback: function callback() {
+ saveCurrentGame();
+ showMainText("Partie sauvegardée !");
+ hideChoices();
+ showChoices([{
+ label: "Continuer",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+ }
+ }]);
+}
+function startNewGame(index) {
+ currentSaveIndex = index;
+ currentSave = {
+ region: null,
+ starter: null,
+ starterName: null,
+ team: [],
+ bag: [],
+ progress: {}
+ };
+ hideSaveSlots();
+ chooseGeneration();
+}
+function updateSaveSlots() {
+ var saves = getSaves();
+ for (var i = 0; i < saveSlotButtons.length; i++) {
+ saveSlotButtons[i].setSlot(i, saves[i]);
+ }
+}
+// --- Main Menu ---
+function showMainMenu() {
+ hideChoices();
+ hideMainText();
+ updateSaveSlots();
+ showSaveSlots();
+ showMainText("Pokémon Aventure : Générations 1 à 8\n\nChoisissez une sauvegarde :");
+}
+// --- Generation/Starter Selection ---
+function chooseGeneration() {
+ showMainText("Choisissez la génération de départ :");
+ var choices = [];
+ for (var i = 0; i < startersByGen.length; i++) {
+ (function (genIndex) {
+ choices.push({
+ label: "Génération " + (genIndex + 1) + " (" + regionsByGen[genIndex] + ")",
+ callback: function callback() {
+ chooseStarter(genIndex);
+ }
+ });
+ })(i);
+ }
+ showChoices(choices);
+}
+function chooseStarter(genIndex) {
+ currentSave.region = regionsByGen[genIndex];
+ showMainText("Choisissez votre Pokémon de départ :");
+ var starters = startersByGen[genIndex];
+ var choices = [];
+ for (var i = 0; i < starters.length; i++) {
+ (function (starter) {
+ choices.push({
+ label: starter.name + " (" + starter.type + ")",
+ callback: function callback() {
+ currentSave.starter = starter;
+ currentSave.starterName = starter.name;
+ currentSave.team = [starter];
+ saveCurrentGame();
+ updateTeamDisplay(currentSave.team);
+ showMainText("Félicitations ! Vous avez choisi " + starter.name + " comme starter.\nL'aventure commence dans la région " + currentSave.region + " !");
+ showChoices([{
+ label: "Commencer l'aventure",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+ }
+ });
+ })(starters[i]);
+ }
+ showChoices(choices);
+}
+// --- Region Exploration (MVP: simple random event or battle) ---
+function enterRegion(region) {
+ showMainText("Vous explorez la région de " + region + ". Que souhaitez-vous faire ?");
+ showChoices([{
+ label: "Explorer",
+ callback: function callback() {
+ randomEvent();
+ }
+ }, {
+ label: "Voir l'équipe",
+ callback: function callback() {
+ showTeamMenu();
+ }
+ }, {
+ label: "Sauvegarder",
+ callback: function callback() {
+ saveCurrentGame();
+ showMainText("Partie sauvegardée !");
+ hideChoices();
+ showChoices([{
+ label: "Continuer",
+ callback: function callback() {
+ enterRegion(region);
+ }
+ }]);
+ }
+ }, {
+ label: "Retour au menu",
+ callback: function callback() {
+ showMainMenu();
+ }
+ }]);
+}
+// --- Team Menu (MVP: just list) ---
+function showTeamMenu() {
+ var team = currentSave.team;
+ var txt = "Votre équipe :\n";
+ for (var i = 0; i < team.length; i++) {
+ txt += "- " + team[i].name + " (" + team[i].type + ")\n";
+ }
+ showMainText(txt);
+ showChoices([{
+ label: "Retour",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+}
+// --- Random Event (MVP: wild Pokémon or trainer) ---
+function randomEvent() {
+ var r = Math.random();
+ if (r < 0.5) {
+ // Wild Pokémon
+ var wild = getRandomWildPokemon();
+ showMainText("Un Pokémon sauvage apparaît : " + wild.name + " (" + wild.type + ") !");
+ showChoices([{
+ label: "Combattre",
+ callback: function callback() {
+ startBattle(wild);
+ }
+ }, {
+ label: "Fuir",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+ } else {
+ // Trainer
+ showMainText("Un dresseur vous défie !");
+ showChoices([{
+ label: "Combattre",
+ callback: function callback() {
+ startTrainerBattle();
+ }
+ }, {
+ label: "Fuir",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+ }
+}
+// --- Wild Pokémon generator (MVP: pick from starters of any gen) ---
+function getRandomWildPokemon() {
+ var all = [];
+ for (var i = 0; i < startersByGen.length; i++) {
+ for (var j = 0; j < startersByGen[i].length; j++) {
+ all.push(startersByGen[i][j]);
+ }
+ }
+ return all[Math.floor(Math.random() * all.length)];
+}
+// --- Battle System (MVP: simple turn-based, win = catch, lose = nothing) ---
+function startBattle(wild) {
+ showMainText("Le combat commence contre " + wild.name + " !");
+ showChoices([{
+ label: "Attaquer",
+ callback: function callback() {
+ battleTurn(wild, true);
+ }
+ }, {
+ label: "Lancer une Pokéball",
+ callback: function callback() {
+ tryCatch(wild);
+ }
+ }, {
+ label: "Fuir",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+}
+function battleTurn(wild, playerAttack) {
+ if (playerAttack) {
+ // MVP: always win
+ showMainText("Votre Pokémon attaque !\n" + wild.name + " est affaibli !");
+ showChoices([{
+ label: "Lancer une Pokéball",
+ callback: function callback() {
+ tryCatch(wild);
+ }
+ }, {
+ label: "Attaquer encore",
+ callback: function callback() {
+ battleTurn(wild, true);
+ }
+ }, {
+ label: "Fuir",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+ }
+}
+function tryCatch(wild) {
+ // MVP: 70% chance
+ if (Math.random() < 0.7) {
+ currentSave.team.push(wild);
+ saveCurrentGame();
+ updateTeamDisplay(currentSave.team);
+ showMainText("Félicitations ! Vous avez capturé " + wild.name + " !");
+ showChoices([{
+ label: "Continuer",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+ } else {
+ showMainText("Oh non ! " + wild.name + " s'est échappé !");
+ showChoices([{
+ label: "Réessayer",
+ callback: function callback() {
+ tryCatch(wild);
+ }
+ }, {
+ label: "Fuir",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+ }
+}
+// --- Trainer Battle (MVP: always win) ---
+function startTrainerBattle() {
+ showMainText("Le combat contre le dresseur commence !");
+ showChoices([{
+ label: "Attaquer",
+ callback: function callback() {
+ winTrainerBattle();
+ }
+ }, {
+ label: "Fuir",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+}
+function winTrainerBattle() {
+ showMainText("Vous avez vaincu le dresseur !\nVotre équipe gagne de l'expérience.");
+ showChoices([{
+ label: "Continuer",
+ callback: function callback() {
+ enterRegion(currentSave.region);
+ }
+ }]);
+}
+// --- Game Start ---
+showMainMenu();
+/****
+* Touch Handling (for mobile)
+****/
+// All buttons are handled via their .down methods (see classes above)
+// No additional code needed for MVP
+/****
+* GUI (Score, Timer, etc.)
+****/
+// Not used in MVP
+/****
+* Music, Sound, etc.
+****/
+// Not used in MVP
\ No newline at end of file