Results 1 to 3 of 3
  1. #1
    Areptom is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default Cant get if/else to work with bufferedreader

    Mah bufferedreader is working when it uses the input to create the player name string, but I cant get it to make the if/then/else thang work =\. I feel like it is something decently obvious im missing, help with that or any other criticism would be helpful :D

    Java Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.*;
    import java.util.*;
    
    
    
    public class Game {
    	public static void main(String[] args) throws Exception {
    		InputStreamReader input = new InputStreamReader(System.in);
    		BufferedReader reader = new BufferedReader(input);
    		String name = "";
    		System.out.println("What is your name?");
    		name = reader.readLine();
    		System.out.println("Welcome " + name + ".");
    		System.out.println("What would you like to do?");
    
    
    		int str = 100;
    		int lvl = 1;
    		int estr = 1;
    		int php = 200;
    		int ehp = 1;
    		int dmg = 1;
    		int xp = 0;
    
    		Random randdmg = new Random();
    
    
    
    
    		String in = "";
    		while(true){
    			in = reader.readLine();
    			if(in == "attack hannon follower"){
    	System.out.println("You: " + in + ".");	
    ehp = 50;
    		estr = 25;
    		while(php > 0 & ehp > 0){
    
    			//computer attack =\
    			dmg = randdmg.nextInt(estr);
    			System.out.println("The hannon follower (lvl 1) hits " + name + " for " + dmg + " damage!");
    			php = php - dmg;
    			System.out.println("" + name + " hp: " + php + "");
    			Thread.sleep(1000);
    			//player attack bro =\
    			dmg = randdmg.nextInt(str);
    			System.out.println("" + name + " hits The hannon follower (lvl 1) for " + dmg + " damage ");
    			ehp = ehp - dmg;
    			System.out.println("Hannon follower (lvl 1) hp: " + ehp + "");
    			Thread.sleep(1000);
    
    		}
    		if(php > 1){
    			System.out.println("" + name + " Wins the fight!");
    			xp = xp + ehp;
    			System.out.println("You gain " + ehp + " xp; you now have " + xp + "");
    		}
    		else if(ehp > 1){
    			System.out.println("Hannon Follower (lvl 1) wins the fight");
    		}
    	}
    			else if(in == "help"){
    				System.out.println("OUTPUT Bro");
    			}
    		}
    
    	} //end of while loop =\
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Java Code:
    if(in == "attack hannon follower"){
    Read my reply here: String If Statements

  3. #3
    Areptom is offline Member
    Join Date
    Jun 2011
    Posts
    5
    Rep Power
    0

    Default

    thanks bro =\ feel like ive gotten the if(string == "yah"){} before. Musta been on C# err something. Thanks <3

Similar Threads

  1. How to use BufferedReader?
    By ProgramBeginner in forum New To Java
    Replies: 4
    Last Post: 10-11-2011, 02:56 PM
  2. BufferedReader problem
    By dilpreet28 in forum New To Java
    Replies: 5
    Last Post: 07-05-2010, 12:18 PM
  3. BufferedReader
    By Nerijus in forum New To Java
    Replies: 4
    Last Post: 04-26-2010, 07:28 PM
  4. BufferedReader, need help!
    By zacharyrod in forum New To Java
    Replies: 10
    Last Post: 11-19-2009, 10:56 AM
  5. BufferedReader
    By vidhya.sk in forum New To Java
    Replies: 2
    Last Post: 09-18-2008, 01:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •