import java.util.Random;
import java.util.Scanner;
public class Dice {
static Random ranNum = new Random();
static int output ;
public Dice(){
output = ranNum.nextInt(6) + 1;
}
public int OutPut(){
return(output);
}
}
public class Player {
private int position;
Dice roll = new Dice();
boolean cont;
public Player(){
this.position = 0;
}
public void Move(){
if( (position + roll.OutPut()) >= 100){
position = 100;
cont = true;
}
else{
position += roll.OutPut();
cont = false;
}
}
public boolean Cont(){
return(cont);
}
}
public class GamePlay {
Player[] person;
int takeTurn;
public GamePlay(int numPl){
this.person = new Player[numPl];
takeTurn = 0;
}
public void Turn(){
do{
person[takeTurn].Move();
if(takeTurn == (person.length-1))
takeTurn = 0;
else
takeTurn += 1;
}while(person[takeTurn].Cont() == true);
System.out.printf("Player %f Wins",(takeTurn + 1));
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
GamePlay newGame = new GamePlay(scan.nextInt());
newGame.Turn();
}
}
↧
null pointer exception occurs.
↧