I am currently in the process of finishing my game for my school project. However, when I try to get what the user inputs, no matter what they put, it terminates and ends the game. I want it so that if you press "fight", it lists the 4 moves so that the user can input which one they want. However, no matter what I input, it says "Battle Terminated" and sends me back to the FrontPage. Please assist.
Current class:
FrontPage Class if needed:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.*; /** * Write a description of class Blastoise here. * * @author (your name) * @version (a version number or a date) */ public class Blastoise extends Actor { private String name; private String type; private double health; private int time; /** * Act - do whatever the Blastoise wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { time++; returnHealth(); Attack(); } public Blastoise() { name = "Blastoise"; type = "Water"; health = 362; } public void Attack() { double random = (Math.random()*0.85)+0.15; double damage = 0; double modifier = 0; Moves m1 = new Moves("Skull Bash",130,100,"Normal","Physical"); Moves m2 = new Moves("Hydro Pump",110,80,"Water","Special"); Moves m3 = new Moves("Ice Beam",90,100,"Ice","Special"); Moves m4 = new Moves("Weather Ball",50,100,"Normal","Special"); Moveset ms = new Moveset(m1,m2,m3,m4); Scanner scan = new Scanner(System.in); System.out.println("Enter: Fight or Run"); String response = scan.nextLine(); if(response.toLowerCase()=="fight") { System.out.println("Choose a move: "); for(int i = 0; i < 4;i++) { ArrayList<Moves> x = ms.getMoveset(); System.out.println("- " + x.get(i).getName()); } if(scan.nextLine().toLowerCase() == "skull bash") { String enemyType = " "; int enemyDefense = 0; int power = m1.getPower(); Actor enemy = BattlePage.getCPU(); //Start of Outside Code: https://www.greenfoot.org/topics/63103/0#bottom ArrayList<Integer> enemyStats = null; if(enemy instanceof Blastoise) { enemyDefense = 328; enemyType = ((Blastoise)enemy).getType(); if (enemyType.toLowerCase() == "water") { modifier = random; } } if(enemy instanceof Charizard) { enemyDefense = 280; enemyType = ((Charizard)enemy).getType(); if (enemyType.toLowerCase() == "fire") { modifier = random; } } if(enemy instanceof Venusaur) { enemyDefense = 291; enemyType = ((Venusaur)enemy).getType(); if (enemyType.toLowerCase() == "grass") { modifier = random; } } //End of Outside Code damage = ((42*power*(291/enemyDefense)/50)+2)* modifier; setHealth(damage); } } else { System.out.println("Battle Forfeited"); Greenfoot.setWorld(new FrontPage()); } } public String getType() { return type; } public double getHealth() { return health; } public void setHealth(double damage) { health = health - damage; } public String getName() { return name; } public void returnHealth() { System.out.println(getName() + "'s Health: " + getHealth()); } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class MyWorld here. * * @author (your name) * @version (a version number or a date) */ public class FrontPage extends World { /** * Constructor for objects of class MyWorld. * */ public FrontPage() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); setBackground("TitleScreen.jpg"); Actor startButton = new startButton(); addObject(startButton, 215, 300); Actor helpButton = new helpButton(); addObject(helpButton, 360, 300); } }