I'm trying to get a cheat code working by taking the player's input and performing an action if the right code is written down. I've got the player input working but for some reason, I can't seem to get the condition in characterPick() to be true even if I type in the correct cheat code. Does anyone know why?
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.util.ArrayList;
public class Character_Select extends World
{
Arena world; //main world
static GreenfootSound kazakh = new GreenfootSound("kazahkstan.mp3");
String cheatCode;
String[] alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"
,"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
SimpleTimer inputLag; //ensures accurate input
/**
* Constructor for objects of class Character_Select.
*
*/
public Character_Select(Arena _world)
{
super(600, 900, 1, false);
world = _world;
inputLag = new SimpleTimer();
cheatCode = "Cheat code: ";
}
private void characterPick(){
if (cheatCode == "Cheat code: kazakhstan")/*Condition is never true for some reason, rest of code works fine*/{
world.characterChoice = 6;
Greenfoot.setWorld(new Arena());
kazakh.playLoop();
}
}
private void playerInput(){
for (int i = 0; i < 26; i++){
if (Greenfoot.isKeyDown(alphabet[i]) && inputLag.millisElapsed()>400){
cheatCode += alphabet[i];
inputLag.mark();
}
}
}
public void act()
{
characterPick();
playerInput();
showText(cheatCode, 300, 750);
}
}