This site requires JavaScript, please enable it in your browser!
Greenfoot back
minetruck
minetruck wrote ...

2020/2/29

java.lang.ClassCastException need help

minetruck minetruck

2020/2/29

#
hi i have a game where you have to click on a dice and when you have 66 points you win. i want to reset all counters when 66 points are achieved. but i have this problem: java.lang.ClassCastException: class player1 cannot be cast to class player2 code of the winner screen:
public void act() 
    {
        ((player1)getWorld()).lose();
        ((player2)getWorld()).lose1(); // here is the problem
    } 
code of the method:
public void lose(){
        counter1.setValue(0);
        counter2.setValue(0);
    }
// and
public void lose1(){
        counter1.setValue(0);
        counter2.setValue(0);
    }
and the code to show the winner screen:
if(counter1.getValue() >= 66){
            removeObject(p2);
            addObject(new p1wins(), 640, 360);
           
        }
thanks
You need to login to post a reply.