Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: dont know how to describe the problem.

  1. #1
    Junior Member arqdia's Avatar
    Join Date
    Mar 2014
    Location
    Mexico
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default dont know how to describe the problem.

    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");
     
     
     
     
    	}
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: dont know how to describe the problem.

    Try using an AND, &&, instead of an OR, ||, in the if statement.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    arqdia (March 9th, 2014)

  4. #3
    Junior Member arqdia's Avatar
    Join Date
    Mar 2014
    Location
    Mexico
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: dont know how to describe the problem.

    Quote Originally Posted by GregBrannon View Post
    Try using an AND, &&, instead of an OR, ||, in the if statement.
    Tnx, that was the issue.

    i now want to add a "Play again" option, i'll try it tomorrow, any ideas are very welcome.

  5. #4
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default Re: dont know how to describe the problem.

    Play again:
    Wrap your code in a while loop & ask the user if they want to play again. Whatever the input, that should be part of the condition in your while loop.
    Who holds the KEY to all knowledge?

Similar Threads

  1. Please describe the output of the following program!
    By sgt98 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 11th, 2014, 01:47 AM
  2. Replies: 7
    Last Post: February 26th, 2013, 02:21 AM
  3. Problem with import java.util.*; dont know whats wrong
    By TheLeader in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 3rd, 2012, 12:33 PM
  4. describe this program code by code ....
    By izzahmed in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 29th, 2011, 11:03 PM
  5. I dont get it....please help
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 30th, 2010, 03:16 AM