Hello everyone. I'm creating a small darts game, it has two players who take turns throwing darts. It's done by entering commands. So far, I've created a menu system with some classes to help. Here is my code.
public class Darts{ int userInput; public static void main(String[] args) { menu(); } public static void menu (){ int userInput; TextIO.putln("Darts!"); TextIO.putln(); TextIO.putln(); TextIO.putln("Please select an Option :"); TextIO.putln("1 - to Play the Game"); TextIO.putln("2 - for Instructions"); TextIO.putln("3 - to Exit the Game"); userInput = TextIO.getlnInt(); switch (userInput){ case 1 : playGame(); case 2 : instructions(); case 3 : endGame(); default : NotA(); } } public static void playGame() { char anyChar; Turn currentTurn = new Turn(); currentTurn.thrown[0] = new Throw(); TextIO.putln("What number are you aiming at?"); currentTurn.thrown[0].number = TextIO.getlnInt(); TextIO.putln("Enter 2 for a Double, 3 for a Treble, otherwise enter 1:"); currentTurn.thrown[0].multiplier = TextIO.getlnInt(); currentTurn.thrown[1] = new Throw(); TextIO.putln("What number are you aiming at?"); currentTurn.thrown[1].number = TextIO.getlnInt(); TextIO.putln("Enter 2 for a Double, 3 for a Treble, otherwise enter 1:"); currentTurn.thrown[1].multiplier = TextIO.getlnInt(); currentTurn.thrown[2] = new Throw(); TextIO.putln("What number are you aiming at?"); currentTurn.thrown[2].number = TextIO.getlnInt(); TextIO.putln("Enter 2 for a Double, 3 for a Treble, otherwise enter 1:"); currentTurn.thrown[2].multiplier = TextIO.getlnInt(); TextIO.put("Your score now is: "); TextIO.putln(currentTurn.total - (currentTurn.thrown[0].number + currentTurn.thrown[1].number + currentTurn.thrown[2].number)); TextIO.put("Game in Progress. Press any key to continue: "); anyChar = TextIO.getAnyChar(); menu(); } public static void instructions() { char anyChar; TextIO.putln(); TextIO.putln("Commands"); TextIO.putln(); TextIO.putln("You have three darts, when prompted you need to enter your command."); TextIO.putln("Your command will be a number followed by a number."); TextIO.putln("The numbers will be 1, 2 and 3."); TextIO.putln(""); TextIO.putln("They represent Single, Double or Triple"); TextIO.putln("E.g. 20 followed by 2 represents Double twenty."); TextIO.putln(); TextIO.put("Press any key to continue: "); anyChar = TextIO.getAnyChar(); menu(); } public static void endGame() { System.exit(0); } public static void NotA() { menu(); } }
Here are my other classes:
public class Turn { Throw[] thrown = new Throw[3]; // three darts thrown per turn int total = 501; }public class Throw { int number; int multiplier; // 3 for a treble, 2 for a double, 1 for anything else }
Basically at this moment in time, I'm just asking how to implement the multiplier from my throw class to show Triples, Doubles and a single. This is because at the moment so far, it's only noting the single number I put down but not the multipliers.
Thanks