Thanks EddArmitage!
Unfortunatly it still refuses to work and I cant for the life of me figure out why. I have put the main class and the dart class for you to have a closer look if you dont mind mate.
I appreciate any clues you can pass my way coz this needs to be done asap and I am about to give up
Mainpublic class JavaDarts {
/*JavaDarts class is used to play a game of darts, by calling methods from other Classes.
*There is two players which have three throws each turn. You are able to Replay a game that you have played.
*/
public static void main(String[] args) {
TextIO.putln("Welcome to JDarts!");
TextIO.putln();
TextIO.putln();
TextIO.putln("Enter <1> to Play JDarts. " );
TextIO.putln("Enter <2> to Quit. " );
int menu = TextIO.getlnInt(); // Selects options that are given in the Menu.
TextIO.putln();
switch (menu) {
case 1: TextIO.put("");
break;
case 2: TextIO.put("");
break;
case 3: System.exit(0);
break;
} //End switch case.
Game G1=new Game();
TextIO.putln();
TextIO.putln("You Win! Congratulations!");
TextIO.putln();
TextIO.putln("--------------------------------------------------------------------------------");
TextIO.putln("Press <1> to see you Game History.");
TextIO.putln("Press <2> to Quit.");
int menu2 = TextIO.getlnInt(); // Selects options that are given in the Menu.
TextIO.putln();
switch (menu2) {
case 1: TextIO.put("");
break;
case 2: System.exit(0);
break;
}
G1.display();
} //End Main.
} //End Class.
Dart Class/* Dart() class will ask the user for a dart number and if it's single, double or treble.
* The values returned will be the either the number
* asked for or the neighbour number on a dart board*/
public class Dart {
int modifier = 1; //Stores the value of Single, Double or Treble.
int totalScore; //Displays the value of the the modifier * requestedScore(or numberScored).
int numberScored; //This will store either the neighbour value or the value that was entered by the user, depending on the maths random.
int bustScore = 0;
/* Dart() is used to get the dart information from the user, this data might be changed
* it is then displayed at the end of a throw to show what the user got and how many remaining
* points they have left to complete the game
*/
public Dart(int target){
Neighbour[]neighbour = new Neighbour[20];
neighbour[0] = new Neighbour(20, 18);
neighbour[1] = new Neighbour(15, 17);
neighbour[2] = new Neighbour(17, 19);
neighbour[3] = new Neighbour(18, 13);
neighbour[4] = new Neighbour(12, 20);
neighbour[5] = new Neighbour(13, 10);
neighbour[6] = new Neighbour(19, 16);
neighbour[7] = new Neighbour(11, 16);
neighbour[8] = new Neighbour(14, 12);
neighbour[9] = new Neighbour(6, 15);
neighbour[10] = new Neighbour(14, 8);
neighbour[11] = new Neighbour(9, 5);
neighbour[12] = new Neighbour(4, 6);
neighbour[13] = new Neighbour(11, 9);
neighbour[14] = new Neighbour(10, 2);
neighbour[15] = new Neighbour(8, 7);
neighbour[16] = new Neighbour(3, 2);
neighbour[17] = new Neighbour(1, 4);
neighbour[18] = new Neighbour(7, 3);
neighbour[19] = new Neighbour(5, 1);
TextIO.putln("-------------------------------------------------------------------------");
TextIO.putln();
/* Do this while it's not within the boundaries of the Dartboard, when boundaries have been met then break.*/
do
{
TextIO.put("Enter you target between <1-20> or Bullseye <25 or 50>: " );
numberScored = TextIO.getlnInt();
if (!(numberScored >= 1 && numberScored <= 20 || numberScored == 25 || numberScored == 50)) // Within the boundaries of Dartboard.
TextIO.put("Invalid Input: " );
if (numberScored == 25)
TextIO.putln("You have hit 25!");
if (numberScored == 50)
TextIO.putln("You have hit bullseye!!!");
} while (!(numberScored >= 1 && numberScored <= 20 || numberScored == 25 || numberScored == 50));
if (numberScored != 50 && numberScored != 25) { // If numberScored is not 50 or 25 then carry out this code.
TextIO.put("Type in <1> for Single, <2> for Double or <3> for Treble: " );
modifier = TextIO.getlnInt();
TextIO.putln();
TextIO.put("You have chosen: " );
switch (modifier) {
case 1: TextIO.put("Single ");
break;
case 2: TextIO.put("Double ");
break;
case 3: TextIO.put("Treble ");
break;
} // End Switch.
TextIO.put(numberScored);
TextIO.putln();
TextIO.putln();
TextIO.put("You have hit: ");
// int modifier = (int)(3*Math.random())+ 1; //Picks random modifier.
switch (modifier) {
case 1: TextIO.put("Single ");
break;
case 2: TextIO.put("Double ");
break;
case 3: TextIO.put("Treble ");
break;
} //End Switch.
} // End If Statement.
if (numberScored != 50 && numberScored != 25 ) { // If numberScored is not 50 or 25 then carry out this code.
numberScored=getThrow(numberScored, neighbour[numberScored-1].getLeft(),neighbour[numberScored-1].getRight()) ;
TextIO.putln(numberScored);
} // End If Statement.
totalScore = numberScored * modifier;
TextIO.putln("Your total dart score is " + totalScore);
TextIO.putln();
if ((target-totalScore)<0){
TextIO.putln("--------------------------------------------------------------------------------");
TextIO.putln(" YOU HAVE GONE BUST!");
TextIO.putln(" YOU MUST FINISH ON 0 EXACTLY!");
TextIO.putln(" YOU HAVE " + (target) + " REMAINING!");
TextIO.putln("--------------------------------------------------------------------------------");
} // End if.
else if ((target - totalScore)==0){
TextIO.putln("Good Job!");
}
else {
TextIO.putln("Your remaining game score is " + (target -= totalScore));
}
} // End Dart() method.
/* getThrow() will assign the numberScored either the left, right or initial value on a dartboard, once the numberScored
* is changed this will be returned to the Dart() method so it can be changed by the modifier.
*/
public int getThrow(int dartThrow, int left, int right) {
// int neighbour = (int)(8*Math.random())+ 1;
int neighbour = 3;
switch (neighbour) {
case 1: dartThrow = left;
break;
case 2: dartThrow = right;
break;
case 3: dartThrow = dartThrow;
break;
}
return dartThrow ;
}
/*Returns the totalScore*/
public int gettotalScore(){
return totalScore;
} // end gettotalScore() method.
/*
*display() will display all the results of each dartThrow you have made during the game. this will be displayed at
*the end of the game, so you can see your what darts you have hit to win the game.
*/
public void display() {
TextIO.putln();
TextIO.putln();
TextIO.putln("------------------------------------------------------------------------");
TextIO.putln("------------------------------------------------------------------------");
TextIO.putln();
TextIO.putln(" You hit dart: " + numberScored);
TextIO.putln(" Your modifier was: " + modifier);
TextIO.putln(" Your total dart score for this dartThrow is: " + totalScore);
TextIO.putln();
} // End display() method.
} // End class.