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 8 of 8

Thread: Help with a Game that's gone wrong.

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with a Game that's gone wrong.

    HI i currently have this code:

    //Imports packages
    import java.io.*;
    import java.lang.*;
     
    //class name
    class Parkour
     
     
    //i think this is right
      public void static main ( String[] args )
     
    //These varibles have been declared right
    {
    String proname = "";
    String programq = "";
    char programa = "y";
    String programc = "";
    int Strength ="";
    int Agility ="";
    int Charisma ="";
     
     
         System.out.println("Sub Question 3");
     
        System.out.println("\nBy Harry Thompson cook");
     
     
    //And here's where the problem starts:
     
     
             System.out.println("\nTron:Parkour");
     
          System.out.print("\nWhat is your name:");
     
    //Hope i've done this right
     
        InputStreamReader isr =
                  new InputStreamReader(System.in );
     
              BufferedReader buffer = new BufferedReader( isr );
     
    //All Good?
      try
    {
           proname = buffer.readline();
           buffer.close();
    }
    catch ( IOException e )
    {
            System.out.println( "Invalid Name choose again program!");
    }
     
         System.out.println("\nWelcome" + name);
     
          System.out.print("\nWe must go through some basic setup options, Proceed y/n?");
     
    InputStreamReader isr =
         new InputStreamReader(System.in );
     
     
         BufferedReader buffer = new Bufferedreader( isr );
     
    try
    {
           programq = buffer.readline();
           buffer.close();
    }
    catch ( IOException e )
    {
              System.out.println("Invalid Input");
    }
     
    if(programq == programa)
    {
     
      System.out.println("\n You have 10 energy point's");
      System.out.println("\n You can use these to upgrade either");
      System.out.println("\nStrength");
      System.out.println("\nAgility");
      System.out.println("\nOr Charisma");
      System.out.println("\nEach of these Qualties can help you out on your mission");
      System.out.println("\nStrength will help you out when the going get's tough");
      System.out.println("\nAgility makes it easier to run from fights and can help in infiltrating buildings");
      System.out.println("\nIf you choose Charisma you could use your looks to help you out in tough situation's");
      System.out.println("\nNow it is the time to choose what skills you want:");
      System.out.print("\nHow much energy will you give to strenth?");
     
     InputStreamReader isr =
          new InputStreamReader(System.in );
     
     
     
       BufferedReader buffer = new Bufferedreader( isr );
     
    try
    {
     
        Strength = buffer.readline();
        buffer.close();
    }
    catch ( IOException e )
    {
          System.out.println(\n You must input a number!);
    }
     
     
     
     
    {
     
    }
    else
    {
       System.out.println("Setup Will Exit");
    }


    So i know it's messy but if someone could help me out it would be very much appreciated.

    Retro Man


  2. #2
    Junior Member
    Join Date
    Jun 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a Game that's gone wrong.

    That smiley face should'nt be there!

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Help with a Game that's gone wrong.

    Quote Originally Posted by Retro Man View Post
    //And here's where the problem starts:
    What problem?

    Do you get errors? Then copy an paste the full error messages.
    Do you get incorrect behaviour? Then describe what it should do and what it does do instead.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help with a Game that's gone wrong.

    Quote Originally Posted by Retro Man View Post
    That smiley face should'nt be there!
    That's why you need to wrap your code in the highlight tags. Please see my signature. I've done it for you this time.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: Help with a Game that's gone wrong.

    //And here's where the problem starts:
    I don't see any problem. Please identify what it is that went wrong like Junky said.

  6. #6
    Member OutputStream's Avatar
    Join Date
    Apr 2011
    Posts
    32
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 3 Posts

    Default Re: Help with a Game that's gone wrong.

    There are no brackets after the class definition

  7. #7
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Help with a Game that's gone wrong.

    There are a couple of mistakes here I wanted to point out.

    catch ( IOException e )
    {
            System.out.println( "Invalid Name choose again program!");
    }

    This will not do what you are expecting it to. It will not print your error message when someone enters rubbish input like "123"

    System.out.println("\nWelcome" + name);

    There should be a space inside the quotes after Welcome. As it is it will print "WelcomeChris".

    if(programq == programa)

    This is a very common mistake made by new java programmers. To check equality of string use programq.equals(programa)

    On a more general note, try and get the behaviour of your program working correctly before you fill out the details.

  8. #8
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Help with a Game that's gone wrong.

    incase u do not understand chris:

    second problem is simply easy to fix

    System.out.println("\nWelcome, " + name);

    Add a space after Welcome inside the string.

    Third problem should be
    if(programq.equals(programa))

    First problem souldnt be printing to a console. you should have a new JLabel in your GUI and set the text to your error message. newLabel.setText("");

    Also if you are a beginner programmer, should you really be attempting to create such a complex game for your level?

    also to help you out abit you could also print the exception error name in the catch and then simply throw it from the method..
    public void methodName() throws ExceptionName

Similar Threads

  1. WHAT IS WRONG HERE PLEASE?
    By mjava in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 27th, 2010, 08:29 PM
  2. Not sure what is wrong with this
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 29th, 2010, 02:23 PM
  3. Something is wrong? Please help.
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 29th, 2010, 07:47 AM
  4. What's wrong?!
    By deeerek in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 22nd, 2010, 07:11 PM
  5. don't know what's wrong
    By james in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 15th, 2010, 07:37 PM