Good, I'm doing a code from two different classes (two different * .java elements), in the first ('ball') I set the attributes and methods:
public class Pelota {
byte posX = 0;
byte posY = 0;
byte peso = 5;
public Pelota(){
this.posX = 0;
this.posY = 0;
this.peso = 5;}
public void moverEnX() {
this.posX = posX++;}
public void moverEnY(){
this.posX = posY++;}}
To then open a separate class ('Main') from which to create a new ball object that moves a certain number of steps,
public class MainPelota {
public static void main (String [] args){
Pelota objeto1 = new Pelota();
System.out.println("la posicion inicial de objeto1 es: " + objeto1.posX +"\n Hay un foso en la casilla 8");
objeto1.posX = 0;
while (objeto1.posX<8){
System.out.println("La pelota avanza, ahora está en la posición" + objeto1.posX);
objeto1.moverEnX();
if (objeto1.posX>=8){
System.out.println("La pelota se ha caído");}
}
}
}
However, when executing it, all it does is print the statement of the While loop indefinitely, without 'posX' advancing, I suspect that the problem is when it comes to complying with the 'moverEnX' method but I do not understand why not it works if it is able to access 'posX' without problem.