Results 1 to 4 of 4
  1. #1
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default problem wit my game

    i have been having this little problem in my little game programm ..this is my method for attacking but i'm having a problem int the main project.
    i want the player to repeat the same fight if he doesnt win but it doesnt work with the method i used for it.. please help me...other details at bottom.
    Java Code:
    public void attacking(int health,int attack,String oppname,int minattack,int minstrength,int maxmaket)
        {
       
            System.out.println("TYPE IN \"1\" TO ATTACK ..\"8\"TO GO TO BUY STUFFS");
          
           while(input.hasNextInt() && alive && oppalive)
            { //int myhealth=gethealth();
               //to determine the number of times of marketing
                
            int oppattack=minattack+rand.nextInt(attack);//opponents attack
            int myattack=minstrength+rand.nextInt(getstrength());//my attack on opponent
                
               int ft=input.nextInt();
               //String choice=input.nextLine();
                //to go to the market
               
                
               System.out.println("attacked!!");
               System.out.println("YOUR LIFE IS = "+gethealth());
               System.out.println(oppname+"'S LIFE IS = "+health);
               System.out.println("number of market is" +this.marketed+" of "+maxmaket);
                if(ft==8 && this.marketed!=maxmaket)
                {   
                    this.marketed++;
                    buystuffs();
                    
                }
                
                
               //myhealth=myhealth-oppattack;
               this.health=this.health-oppattack;
               health=health-myattack;
              
               
              if(gethealth()<1)
              {
               System.out.println("YOU ARE DEAD!!");   
                  this.alive=false;
                 // sethealth(0);
              }
               else if(health<1)
                {
                    System.out.println("YOU KILLED "+oppname);
                    System.out.println("YOUR REWARD IS IN YOUR DETAILS");
                    this.health=this.health+100;
                    this.strength=this.strength+3;
                    this.cashew=this.cashew+50;        
                    oppalive=false;
                }
              
            } 
        }


    this is the main method
    Java Code:
     battleattack me=new battleattack(james,7,100,50);
          
            
           me.ds();
            me.details();
                    
            me.ds();
                    
            System.out.printf("%30s\n","| LEVEL 1 |-the man called beast!!");
            me.ds();
            System.out.println("you will fight the great ZALAKU the man called beast!!");
            //me.attacking(health , attack ,oppname,oppinitialattack,myinitialstrength,maxmunmarket)
           
               me.attacking(100, 45,"ZALAKU",1,1,2);
           
            me.ds();
          
          if(me.alive==false)
           { System.out.println("YOU HAVE TO FIGHT ZALAKU AGAIN...");
                me.sethealth(200);
                me.attacking(100,45,"ZALAKU",1,1,2);// this part doesnt run
           }
           
         me.details();
    with this main method, it shows you have to fight zalaku again and building ends without executing me.attacking(100,45,"zalaku",1,1,2)
    but sets the health to 200 but when i create me2.attacking(100,45,"ZALAKU",1,1,2); it works
    joy wouldnt feel so gud if it wasnt for pain

  2. #2
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Re: problem wit my game

    woah!.....no help for me??.....someone should please see this
    joy wouldnt feel so gud if it wasnt for pain

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: problem wit my game

    Quote Originally Posted by nonybrighto View Post
    Java Code:
          if(me.alive==false)
           { System.out.println("YOU HAVE TO FIGHT ZALAKU AGAIN...");
                me.sethealth(200);
                me.attacking(100,45,"ZALAKU",1,1,2);// this part doesnt run
           }
    with this main method, it shows you have to fight zalaku again and building ends without executing me.attacking(100,45,"zalaku",1,1,2)
    but sets the health to 200 but when i create me2.attacking(100,45,"ZALAKU",1,1,2); it works
    It's not possible for the if statement to pass, and the first two lines to execute but not the third, unless you get an exception.
    So either you are eating exceptions (look for empty catch blocks), or none of the above code is being executed.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Re: problem wit my game

    thanks a lot bro ...i will give it a try
    joy wouldnt feel so gud if it wasnt for pain

Similar Threads

  1. problem with typing game
    By beginner123 in forum New To Java
    Replies: 1
    Last Post: 11-20-2012, 09:46 PM
  2. java game problem
    By mathidioticz in forum New To Java
    Replies: 6
    Last Post: 02-04-2012, 07:41 PM
  3. Mastermind game problem
    By TheQuad in forum New To Java
    Replies: 1
    Last Post: 04-16-2011, 05:29 PM
  4. Some problem with game
    By kirayamato in forum NetBeans
    Replies: 13
    Last Post: 12-01-2010, 06:06 AM
  5. My java game problem!? Help!!!
    By Jcbconway in forum AWT / Swing
    Replies: 32
    Last Post: 09-26-2010, 09:33 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
  •