I can not solve a problem with an if

1

I'm doing a game in which you have to calculate the time in seconds that is requested by keyboard, and when that time exceeds the end of the game. But when it goes through that if , it does not calculate time or it's infinite or it just lets you play a round. I leave the code:

 public static void main(String[] args) {

        long tiempoini, tiempofin;
        Instrucciones num;
        boolean seguimos ;
        Instrucciones.pedirTiempoYCantidad();

        do {
            tiempoini = System.currentTimeMillis() / 1000;
            num = new Instrucciones();
            long y = tiempoini + num.getTiempoJue();
            tiempofin = System.currentTimeMillis() / 1000;

            if (tiempofin< y) {               
                if(num.getCant()==0){
                  System.out.println("Has acertado las " + num.getCantOperaciones() + " operaciones.Has ganado!!");
                  seguimos=false;
                }else{
                    seguimos=true;
                }
            }else{
                System.out.println("LO SIENTO, SE HA ACABADO EL TIEMPO PARA REALIZAR MAS OPERACIONES.");
                seguimos=false;
            }       
        } while (seguimos);
        if (num.getCant() != 0) {
            System.out.println("Lo siento, no ha acertado " + num.getCantOperaciones() + " operaciones.Has  perdido!!");
        }

    }
}
    
asked by zizu 24.01.2018 в 20:40
source

1 answer

1

In the following code:

tiempoini = System.currentTimeMillis() / 1000;
num = new Instrucciones();
long y = tiempoini + num.getTiempoJue();
tiempofin = System.currentTimeMillis() / 1000;

Unless the constructor of Instrucciones or the method getTiempoJue() take a considerable time, tiempoini and tiempofin will have the same value.

How are you calculating the game time?

    
answered by 24.01.2018 в 21:06