String trainerName = "";
String playerPokemon = "";
String playerMove = "";
int playerHP = 0;
int maxPlayerHP = 0;
int playerLevel = 1;
int playerXP = 0;
int badgeCount = 0;
bool gameStarted = false;
int starterChoice = 0;
int gymAttempts = 0;
String starters[3][2] = {
{"Chimchar", "Ember"},
{"Piplup", "Bubble"},
{"Turtwig", "Razor Leaf"}
};
int starterHPs[3] = {44, 53, 55};
String wildPokemon[3][2] = {
{"Starly", "Tackle"},
{"Shinx", "Bite"},
{"Bidoof", "Headbutt"}
};
String gymLeader = "Zara";
String gymPokemon = "Luxio";
String gymMove = "Spark";
int gymHP = 70;
void setup() {
Serial.begin(9600);
randomSeed(analogRead(A0));
delay(1000);
mainMenu();
}
void loop() {
}
void mainMenu() {
Serial.println("\n=== POKEMON ADVENTURE: SINNOH QUEST ===");
Serial.println("1. Start Game");
Serial.println("2. Help");
Serial.println("3. Exit");
Serial.println("Choose: ");
int choice = getValidInput(1, 3);
switch (choice) {
case 1: startGame(); break;
case 2: helpMenu(); break;
case 3: Serial.println("Good game. Goodbye trainer!"); break;
}
}
void helpMenu() {
Serial.println("\n=== HELP MENU ===");
Serial.println("- Choose a starter and battle wild Pokémon.");
Serial.println("- Your HP heals after each battle.");
Serial.println("- Catch Pokémon more easily when their HP is low.");
Serial.println("- Reach level 3 to battle the Gym Leader.");
delay(2500);
mainMenu();
}
void startGame() {
getTrainerName();
chooseStarter();
meetOpps();
encounterWildPokemon();
}
void getTrainerName() {
Serial.println("PROF. MEESHA: Welcome trainer! What is your name?");
while (Serial.available()==0) {}
trainerName = Serial.readString();
}
void chooseStarter() {
Serial.print("PROF. MEESHA: Hello "+trainerName);
Serial.print("! Your adventure awaits! ");
Serial.println("Choose your starter Pokemon!");
for (int i = 0; i < 3; i++) {
Serial.println(String((i + 1)) + ". " + starters[i][0] + " (Move: " + starters[i][1] + ", HP: " + starterHPs[i] + ")");
}
Serial.println("Pick 1-3: ");
delay(2500);
starterChoice = getValidInput(1, 3) - 1;
playerPokemon = starters[starterChoice][0];
playerMove = starters[starterChoice][1];
playerHP = starterHPs[starterChoice];
maxPlayerHP = playerHP;
Serial.println("PROF. MEESHA: Excellent choice! You've chosen " + playerPokemon + ".");
delay(2500);
}
void meetOpps() {
Serial.println("GURT (RIVAL): Ha! So you're starting your journey too?");
Serial.println("GURT: I chose the Pokemon that's strong against yours!");
Serial.println("GURT: I'll be waiting to battle you. Don't fall behind!");
gameStarted = true;
delay(2000);
}
void encounterWildPokemon() {
int wildIndex = random(0, 3);
String wildName = wildPokemon[wildIndex][0];
String wildMove = wildPokemon[wildIndex][1];
int wildHP = 35 + random(0, 20);
Serial.println("A wild " + wildName + " appeared!");
delay(2500);
battle(wildName, wildMove, wildHP);
}
void battle(String enemy, String move, int hp) {
while (hp > 0 && playerHP > 0) {
Serial.println("Choose an action:");
Serial.println("1. Attack");
Serial.println("2. Throw Pokeball");
Serial.print("Choice: ");
int action = getValidInput(1, 2);
if (action == 1) {
int damage = 12 + random(5, 10); // Stronger damage
hp -= damage;
Serial.println(playerPokemon + " used " + playerMove + "! " + enemy + " lost " + damage + " HP.");
if (hp <= 0) {
Serial.println("You defeated " + enemy + "!");
playerXP += 10;
if (playerXP >= 20) levelUp();
break;
}
int enemyDamage = 3 + random(0, 5); // Lower wild damage
playerHP -= enemyDamage;
Serial.println(enemy + " used " + move + "! Your " + playerPokemon + " lost " + enemyDamage + " HP.");
} else {
if (tryCatch(enemy, hp)) break;
}
}
if (playerHP <= 0) {
Serial.println("Your Pokémon fainted... Game Over.");
gameStarted = false;
mainMenu();
} else {
playerHP = maxPlayerHP; // Heal after battle
Serial.println("Your " + playerPokemon + " is healed to full HP!");
if (playerLevel >= 3 && badgeCount == 0) {
gymBattle();
} else {
delay(1000);
encounterWildPokemon();
}
}
}
bool tryCatch(String enemy, int hp) {
int chance = 90 - hp; // Lower HP = higher chance
// Manually clamp chance between 30 and 90
if (chance > 90) chance = 90;
if (chance < 30) chance = 30;
if (random(100) < chance) {
Serial.println("Success! You caught the wild " + enemy + "!");
return true;
}
Serial.println("It broke free!");
return false;
}
void gymBattle() {
Serial.println("GYM LEADER " + gymLeader + ": Ready for the challenge, " + trainerName + "?");
delay(2500);
Serial.println(gymLeader + " sent out " + gymPokemon + "!");
while (gymHP > 0 && playerHP > 0) {
Serial.println("Choose an action:");
Serial.println("1. Attack");
Serial.print("Choice: ");
int action = getValidInput(1, 1);
int damage = 12 + random(5, 10);
gymHP -= damage;
Serial.println(playerPokemon + " used " + playerMove + "! " + gymPokemon + " lost " + damage + " HP.");
if (gymHP <= 0) {
Serial.println(gymPokemon + " fainted!");
badgeCount++;
break;
}
int enemyDamage = 6 + random(0, 7);
playerHP -= enemyDamage;
Serial.println(gymPokemon + " used " + gymMove + "! Your " + playerPokemon + " lost " + enemyDamage + " HP.");
}
if (playerHP > 0) {
Serial.println("CONGRATS! You earned the Spark Badge!");
Serial.println("Your journey has just begun... Congrats!"+trainerName);
Serial.println("THE END");
}
if (playerHP <= 0) {
gymAttempts++;
if (gymAttempts >= 2) {
Serial.println("You've lost the gym battle twice... Game Over.");
gameStarted = false;
mainMenu();
} else {
Serial.println("You lost the gym battle... Try again after training!");
gymHP = 70;
playerHP = maxPlayerHP;
encounterWildPokemon();
}
}
}
void levelUp() {
playerLevel++;
playerXP = 0;
maxPlayerHP += 6;
playerHP = maxPlayerHP;
Serial.println("Your " + playerPokemon + " leveled up to level " + String(playerLevel) + "!");
Serial.println("Your HP increased to " + String(maxPlayerHP));
}
int getValidInput(int min, int max) {
int input;
while (true) {
while (!Serial.available()) {}
input = Serial.parseInt();
if (input >= min && input <= max) break;
Serial.print("Enter a valid number (" + String(min) + "-" + String(max) + "): ");
}
return input;
}