The thing is, i'm making a little simple game, you hit a zombie and zombie hits you back. the thing is, the user have 2 attack types (normal and magic) and are controlled by the letters M and N (uppercase).
i want to display a message if you type other letters besides N and M and i what to accept lowecase characters to by converting lower to upper.
System.out.println("Ataca !!! (N para golpe normal, M para golpe Magico):"); input = myScanner.findWithinHorizon(".",0) .charAt(0); attack = Character.toUpperCase(input); System.out.println(attack); if (attack != 'M' || attack != 'N'){ System.out.println("No entendi."); }
some of the instructions are in spanish, sorry. every thing works fine, except if you time lowercase m or n. the program displays the error message (no entendi) and continues the normal run.
what should i do?
i being reading about have for 2 days only, and have little knowledge, ill post the complete code of the game, that summarize almost all that i know about java.
package heroVsZombie; import java.util.Scanner; import java.util.Random; public class arena { public static void main(String[] args) { Scanner myScanner = new Scanner(System.in); Random myRandom = new Random(); int zombieLife = 130; int heroLife = 120; char attack; int hit; int zombieHit; String Hero; int Crit; int zLuck = 8; char again; char input; System.out.println("Cual es el nombre del Heroe?:"); Hero = myScanner.nextLine(); while (zombieLife >= 1 && heroLife >= 1) { System.out.println("Ataca !!! (N para golpe normal, M para golpe Magico):"); input = myScanner.findWithinHorizon(".",0) .charAt(0); attack = Character.toUpperCase(input); System.out.println(attack); if (attack != 'M' || attack != 'N'){ System.out.println("No entendi."); } if (attack == 'M' || attack == 'N') { Crit = myRandom.nextInt (10)+1; if (Crit >= zLuck){ zombieHit = myRandom.nextInt (10)+18; heroLife = heroLife - zombieHit; System.out.println("Zombie do " + zombieHit + " Critical Damage"); } else { zombieHit = myRandom.nextInt (10)+9; heroLife = heroLife - zombieHit; System.out.println("Zombie do " + zombieHit + " Normal Damage"); } } if(attack == 'N') { hit = myRandom.nextInt (10)+5; System.out.println("you do " + hit + " Damage"); zombieLife = zombieLife - hit; System.out.println("El Zombie tiene " + zombieLife + " HP restantes."); System.out.println(Hero + " tiene " + heroLife + " HP restantes."); } if (attack == 'M'){ hit = myRandom.nextInt (50)+20; System.out.println("you do " + hit + " Magic Damage"); zombieLife = zombieLife - hit; System.out.println("El Zombie tiene " + zombieLife + " HP restantes."); System.out.println(Hero + " tiene " + heroLife + " HP restantes."); } if (zombieLife <= 0) { System.out.println("El Zombie esta Murides, " + Hero + " le puso una chinga."); } if (heroLife <= 0) { System.out.println(Hero + " esta Murides."); } } System.out.println("El Fin"); } }