This question has already been solved
You
Please help me ... a NullPointerException appears
here's the codes
import java.util.Random;
public class Dice {
Random r =new Random();
int sides;
//constructor
public Dice(int s){
sides = s;
}
//roll method depending on sides on top
public int roll(){
return r.nextInt(sides-1)+1;
}
}
// end of class
public class Maze {
char [][] maze;
public Maze(int s){
maze=new char[s][s];
for (int x=0; x5) JOptionPane.showMessageDialog(null, "Karakter capacity exceeded");
else {
kararray[karakterCount] = new karaKter(JOptionPane.showInputDialog("Enter your name, challenger: "),Integer.parseInt(JOptionPane.showInputDialog("Enter your race: \n 1. Homo Sapien\n 2. Homo Alien\n 3. Super Goo\n 4. Enkantado"))-1);
// checks kung may laman yung initial postion ni character sa maze
while(m.maze[kararray[karakterCount].xpos][kararray[karakterCount].ypos]!=' '){
kararray[karakterCount].xpos=initpos.roll();
kararray[karakterCount].ypos=initpos.roll();
}
m.maze[kararray[karakterCount].xpos][kararray[karakterCount].ypos]=kararray[karakterCount].symbol;
}
karakterCount++;
}
public static void doBattle(String P1,String P2){
karaKter Player1=new karaKter(P1,2);
karaKter Player2=new karaKter(P2,3);
Dice Attack=new Dice(10);
int p=Attack.roll();
int p2=Attack.roll();
int life;
int Attack1=Player1.attack() + p;
int Attack2=Player2.attack() + p2;
JOptionPane.showMessageDialog(null,"=====================================In One Corner========================================= " + " \nName : " + P1 + "\nRace : "+ Player1.race + "\nRace Description:"+ Player1.raceDescription + "\nLife :" + Player1.life + "\n==================================In the Other Corner====================================== " + "\nName : " + P2 + "\nRace : "+ Player2.race + "\nRace Description:"+ Player2.raceDescription + "\nLife :" + Player2.life );
while(Player1.isDead && Player2.isDead){
int life1=Player1.getWounded();
int life2=Player2.getWounded();
if(life1<=0||life2<=0){
if(Player1.life !=0 )
JOptionPane.showMessageDialog(null,P1+ " Wins");
else{
JOptionPane.showMessageDialog(null,P2 + " Wins");
JOptionPane.showMessageDialog(null,"========================================== Lets Return To THe Map ==========================================");
break;
}
JOptionPane.showMessageDialog(null,Player1 + " Attacks " + Player2 + "\nDamage : " + Player1.attack() + "\n" + Player2 + "'s life is now " + Player2.getWounded() + "\n============================================\n " + Player2 + " Attacks " + Player1 + "\nDamage : " + Player2.attack() + "\n" + Player1 + "'s life is now " + Player1.getWounded() );
} //
}
}
}
//end of class
//please help me..why when I run the MainGameV1 class, a NullPointerException appears?please solve this error..tnx