I've been rewriting a copy of the original Pokemon battle system in java.
hered my current code:

private void opTurn(){
//Todo: opponents random attack does random damage,
//misses, or causes a status effect
//p.pause(005);
wait(1)
Action.setText("Tiffayoniton attacked!");
curPl -= 10;
plCur.setText("" + curPl);
        
}
private void A1MouseClicked(java.awt.event.MouseEvent evt) {                                
        if (fight == true) {
            if (curOp == 0) {
                Action.setText("Tiffayoniton fainted");
            } else {
                Action.setText("Pikachu used Thundershock");
                curOp -= 10;
                opCurrent.setText("" + curOp);
                opTurn();
            }


        }

        if (item == true) {
            Action.setText("You threw a pokeball");

            //p.pause(2);
            //Action.setText("The pokeball missed");
        }

p.pause references this:

public static void pause(int s, int m, int n){
try{
Thread.sleep(500);
//Thread.currentThread().sleep((s * 1000) + m, n);
//Thread.sleep((s * 1000) + m, n);

}catch(InterruptedException e){

e.printStackTrace();

}

}

public static void pause(int s, int m){

pause(s, m, 0);

}

public static void pause(int s){

pause(s, 0, 0);

}

public static void pause(){

pause(1, 0, 0);

}

}

no matter what ive tried it always pauses everything first(without displaying anything in the else statement) then skips to the end of opTurn instead of displaying the stuff in the else statement,pausing, then displaying the remainder of opTurn.

is there any way of getting this to work properly?

Recommended Answers

All 2 Replies

Read up on Swing Threads - your wait is causing the whole of Swing to wait - hence no screen updates

Try debugging your code to see what it is doing and why. Add lots of println() statements to follow logic flow and see how variables change.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.