i have a small game i made, and it runs fine. but after maybe 2 minutes of playing it gives me this:
java Exception:
Classes: 5
Methods: 0
On the NXT'S LCD display. im really confused and any help would be greatly appreciated.
the code is:
- Code: Select all
import lejos.nxt.*;
import java.util.*;
class funcs {
public void addenimie (int n,int b) {
LCD.drawString("||",n,b);
}
}
public class moveygame {
/**
* @param args
*/
public static void main(String[] args) {
LCD.clear();
funcs funcs = new funcs();
funcs.addenimie(5, 3);
//_posx = the virtical position
//_posy = the horizontal position
//x = 15 y = 7
//(x,y);
//SET UP VARS FOR GAME
int player_posx = 6;
int end = 0;
int player_posy = 4;
int enimey1_posx = 0;
int amo = 20;
int sleeptime = 80;
int already = 0;
int fire = 0;
int shooty = 4;
int shootx = 0;
int score = 0;
Random gen = new Random();
int num = gen.nextInt(15);
int enimey1_posy = num;
//Calebration of the motor. VVVVVVVVVVVVV
while(1 < 2){
if(Button.ENTER.isPressed()){
Motor.A.resetTachoCount();
break;
}else{
}
try{
Thread.sleep(200);
} catch(InterruptedException e){
}
int test = 0;
LCD.clear();
LCD.drawString("Calebrate \nthe MOTOR",0,0);
LCD.drawString("To calebrate,\nTurn the wheel\n so the red\n pegs are facing\n left, Then \nPress enter",0,1);
LCD.refresh();
}
// the main loop where the game runs! VVVVVVVVVVVVV
while(end == 0){
LCD.drawString("| |",enimey1_posx,enimey1_posy);
TouchSensor touch = new TouchSensor(SensorPort.S1);
player_posx = Motor.A.getTachoCount() / 12;
LCD.clear();
LCD.drawString("/^\\",player_posx,player_posy);
LCD.drawString("\\-/",player_posx,player_posy + 1);
LCD.drawString("Score:",7,7);
LCD.drawInt(score,13,7);
if(fire == 1){
LCD.drawString(" *",shootx,shooty);
}
LCD.drawString("Amo:",0,7);
LCD.drawInt(amo,4,7);
LCD.refresh();
if(touch.isPressed()){
if(already == 0){
if(amo == 0){
LCD.drawString("No amo",9,0);
LCD.refresh();
}else{
fire = 1;
shooty = 4;
already = 1;
amo = amo -1;
shootx = player_posx;
}
}
}
try {
Thread.sleep(sleeptime);
} catch(InterruptedException e){
}
if(shooty < 1){
try{
Thread.sleep(90);
} catch(InterruptedException e){
}
fire = 0;
already = 0;
shooty = 4;
}else{
shooty = shooty - 1;
}
if(enimey1_posy == 7){
enimey1_posy = 0;
enimey1_posx = gen.nextInt(15);
}else{
enimey1_posy = enimey1_posy + 1;
}
}
}
}
OH and my version of lejos is 0.4.0, for some reason thats the only version that works for me.
Thanks
