RE:Por que puede ser que varie la ejecucion??...
esta es la otra clase
import uni.robot.*;
import java.awt.event.*;
import java.awt.Color;
public class RobotJugador extends Robot implements KeyListener {
public RobotJugador(Mundo miMundo, int fila, int columna, int dirInicial,
int cantidadMaxima, int cantConos) {
super(miMundo, fila, columna, dirInicial, cantidadMaxima, cantConos);
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
char[] textoCaracteres = new char[texto.length()];
texto.getChars(0, texto.length(), textoCaracteres, 0);
if (e.getKeyChar() != e.VK_BACK_SPACE) {
if (e.getKeyChar() == textoCaracteres[contador] &&
mundo.getCantidadFilas() - 1 != player.getFila()) {
contador++;
totalTeclas++;
teclasCorrectas++;
mundo.setColor(new Color(0, 128, 0), contador - 1);
cont++;
if (cont == 2) {
avanzar();
cont = 0;
}
if ((mundo.getCantidadFilas() - 1 == player.getFila() &&
player.getDireccion() == SUR) ||
(player.getColumna() == 0 && player.getDireccion() == OESTE) ||
(player.getFila() == 0 && player.getDireccion() == NORTE)) {
mundo.mostrarMensaje("Perdiste!");
}
if (mundo.getCantidadColumnas() - 1 == player.getColumna()) {
acuraccy = ((teclasCorrectas * 100) / totalTeclas);
if (acuraccy > 70) {
mensaje = excelente;
}
if (acuraccy > 45 && acuraccy < 70) {
mensaje = medio;
}
if (acuraccy < 45) {
mensaje = mal;
}
mundo.mostrarMensaje(
"Juego Terminado \n\n Total de teclas presionadas: " +
totalTeclas +
"\n Total de teclas correctas: " +
teclasCorrectas + "\n Total de Errores: " + errores +
"\n Precision: " +
acuraccy + "%" + "\n\n" + mensaje + "\n ");
nextLevel();
}
} else {
girarDerecha();
mundo.setColor(new Color(255, 0, 0), contador);
totalTeclas++;
errores++;
}
} else {
girarIzquierda();
mundo.setColor(new Color(0, 0, 0), contador);
totalTeclas++;
}
}
public static void jugar() {
mundo.addKeyListener(player);
}
public void nextLevel() {
level++;
mundo = new MundoConTexto(texto, "World Game Level 2", 5, columnas);
player=null;
player = new RobotJugador(mundo, 2, 0,
Robot.ESTE, 0, 0);
mundo.addKeyListener(player);
}
public void mirarHacia(int direccion) {
while (getDireccion() != direccion) {
this.girarIzquierda();
}
}
public static String texto() {
return texto;
}
private static String[] easy = {
"Un gallego llama a la operadora de beepers",
"- Quiero enviar un mensaje al señor Pablo Hernández.",
"- ¿Qué desea decirle?", "- Que se dejó el beeper en mi casa."};
private static int level = 1;
private static String texto = easy[level];
static int cont = 0;
private static int contador = 0;
private static int columnas = (texto.length() / 2) + 1;
private static MundoConTexto mundo = new MundoConTexto(texto, "Game World",
5, columnas);
private static RobotJugador player = new RobotJugador(mundo, 2, 0,
Robot.ESTE, 0, 0);
private int errores = 0;
private int totalTeclas = 0;
private int teclasCorrectas = 0;
private int acuraccy = 0;
private String mensaje;
private String excelente = "Excelente precision!";
private String medio = "No esta mal!, pero puedes mejorarlo";
private String mal =
"Oh Dear!, Conozco un Oculista que te podria recetar unos buenos lentes";
}
y aqui esta el main...
//import uni.robot.*;
/* Alumno: _____________________________
* Introduccion a la Programacion II
* FIUNI
*/
/** Esta clase contiene el metodo main() para ejecutar
* su programa de robot.
*/
public class MiPrograma {
public static void main(String[] args) {
RobotJugador.jugar();
}
}