I created a program where the user creates a superhero to defeat a computer generated super villain named Shredder. The program starts with the user entering a name and power for their superhero. A random agility and strength are then generated. The user enters a number of 1-5 to determine how they fight Shredder. The fighting continues until Shredder of the user created superhero has been defeated.
import java.util.Random;
import java.util.Scanner;
public class HeroPrinter {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a name for your super hero: ");
String name = scan.next();
System.out.println("Welcome " + name + " to this fantastic program ");
Scanner sc = new Scanner(System.in);
System.out.println("Enter a power for your super hero: ");
String power = scan.next();
System.out.println("Your super power is " + power);
int[] agilities = {1, 2, 3, 4, 5};
Random agility = new Random();
int randAgility = agility.nextInt(agilities.length);
System.out.println("Your agility is " + randAgility);
boolean activatePowers = true;
int strength; // declare a variable to hold hero's strength
strength = 4; // assign the value of strength as a number
System.out.println("Strength: " + strength); // print out the hero's strength
double health;
String badGuy = "Shredder";
int badGuyHealth = 10;
// you guys will do the same for doubles and strings
health = 5.6;
// Print values
// System.out.println("Strength: " + strength + " Name: "+ name + "Health: " + health + " Power: " + power + " Powers are activated!" + " Agility: " + randAgility);
System.out.println("Strength: " + strength + " Name: "+ name + "Health: " + health + " Power: " + power + " Powers are activated!" + " Agility: " + randAgility);
Scanner s = new Scanner(System.in);
System.out.println("Enter a number 1-5 to move your superhero");
int move = s.nextInt();
Random number = new Random();
int numbers = number.nextInt(5) + 1;
if (numbers == 1 || numbers == 2 || numbers == 3){
activatePowers = true;
System.out.println("The super power of " + power + " has been activated");
System.out.println("You used power of " + power + " on Shredder");
badGuyHealth -= 2;
System.out.println("Shredder's health is now " + badGuyHealth);
strength += 1;
randAgility += 1;
}else {
activatePowers = false;
System.out.println("The super power of " + power + " has been deactaivated");
System.out.println("Shredder has won");
health -= 2;
strength -= 1;
randAgility -=1;
}
if (move == 1 || move == 2){
health-= 2;
System.out.println("Oh no, " + name + " hit a building!!");
System.out.println("Your health is: " + health);
System.out.println("Shredder won with a health of " + badGuyHealth);
strength -= 5;
randAgility -=3;
}else if (move == 3 || move == 4){
System.out.println("You saved the world and defeat Shredder!");
health ++;
badGuyHealth = 0;
System.out.println("Your health is: " + health + "Shredder's health is " + badGuyHealth);
strength += 3;
randAgility +=4;
}else {
System.out.println("Your health stayed the same!!");
badGuyHealth -=2;
System.out.println("Shredder now has a health of " + badGuy);
}
System.out.println("Strength: " + strength + " Name: "+ name + " Health: " + health + " Power: " + power + " Agility " + randAgility);
System.out.println("Shredder has a health of " + badGuyHealth);
if (health > 0 && badGuyHealth > 0 ){
Scanner sca = new Scanner(System.in);
System.out.println("You encounter Shredder again, but this time in a cave ");
System.out.println("Enter a number 1-5 to determine what happens!");
int move2 = sca.nextInt();
if (move == 4){
System.out.println("You use your sick " + power + " and fight Shredder");
strength += 2;
health += 2;
randAgility += 1;
System.out.println("You've defeat Shredder");
}else if (move == 3 || move ==1){
System.out.println("You enter the cave, but once you go to take a punch at Shredder, a pile of rocks fall on you");
strength -=2;
health -=2;
randAgility -=3;
System.out.println("Strength: " + strength + " Name: "+ name + "Health: " + health + " Power: " + power + " Agility: " + randAgility);
System.out.println("Game over, you died!");
}else{
System.out.println("You take a punch at Shredder.");
System.out.println("You miss, but once you think all hope is lost you discover a magic potion that you use to poison Shredder");
strength += 2;
health += 2;
randAgility += 2;
System.out.println("You've defeat Shredder");
}
}
}
}