Results 1 to 3 of 3
  1. #1
    Lass is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Fighting Program Question, How to not make the while loop burst all at once.

    Java Code:
    package pack;
    import java.util.Random;
    public class Mainclass {
    	public static void main(String[] args){
    	Random asy = new Random();
    	int counter = 0;
    	int damageA;
    	int defenceA;
    	int healthA = 100;
    	warriora WarriorAObject = new warriora();
    	
    	
    	while(counter <=100){
    		defenceA = asy.nextInt(4);
    		damageA = asy.nextInt(11);
    		healthA = healthA - damageA + defenceA;
    		System.out.println("You've been hit "+damageA+" but you defended " +defenceA+ " of the hit.");
    		System.out.println(healthA);
    		counter++;
    		if(healthA<=0){
    			counter=101;
    		}
    	}
    	}
    }
    Question, Is the program looking good so far?
    What I'm trying to do is make a fighting program,
    In the future I will be making to other classes, warriora and warriorb.
    The program randomly generates damage and defence.
    Is there a way to make it so the program just doesn't burst to the end?
    If I need to add anything to the program let me know.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: Fighting Program Question, How to not make the while loop burst all at once.

    What does "burst to the end" mean?
    If you want pauses in the loop, you could call the Thread class's sleep() method
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Lass is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Re: Fighting Program Question, How to not make the while loop burst all at once.

    Thanks, thats actually what I ment, I was lacking the right vocabulary there lol.

Similar Threads

  1. Replies: 1
    Last Post: 08-30-2011, 02:28 PM
  2. Replies: 4
    Last Post: 07-23-2011, 08:08 PM
  3. How do you make program repeat question?
    By dexter in forum New To Java
    Replies: 3
    Last Post: 02-17-2011, 01:58 AM
  4. balloon burst source code
    By satti in forum Java Applets
    Replies: 20
    Last Post: 04-21-2009, 05:22 PM
  5. Like fighting with the tiped one of JAVA
    By Albert in forum Advanced Java
    Replies: 1
    Last Post: 06-27-2007, 04:38 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
  •