Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class darts_final2 {
- public static String[] dartThrow() {
- intMultiply = (1 + (int)(Math.random()*3));
- intThrow = (1+(int)(Math.random()*22));
- strThrow = Integer.toString(intThrow);
- if(intThrow == 21){
- intThrow = 25;
- intMultiply = 1;
- strThrow = "Bull";
- }
- else if (intThrow == 22){
- intThrow = 25;
- intMultiply = 2;
- strThrow = "Bull";
- }
- if(intMultiply == 1){
- strMultiplier = ("Single");
- }
- else if(intMultiply == 2){
- strMultiplier = ("Double");
- }
- else if(intMultiply == 3){
- strMultiplier = ("Treble");
- }
- intTotal = (intMultiply * intThrow);
- strTotal = Integer.toString(intTotal);
- arrThrow = new String[3];
- arrThrow[0] = strMultiplier;
- arrThrow[1] = strThrow;
- arrThrow[2] = strTotal;
- return arrThrow;
- }
- public static int aTurn() {
- intTurn = 0;
- for(int i=1; i<4; i++){
- arrThrowTemp = new String[3];
- arrThrowTemp = dartThrow();
- TextIO.putln(" " + arrThrowTemp[0] + " " + arrThrowTemp[1] + " = " + arrThrowTemp[2]);
- intTurn = intTurn + Integer.parseInt(arrThrowTemp[2]);
- if (intPlayerScore - intTurn <= 0){
- break;
- }
- }
- TextIO.putln("Turn Score = " + intTurn);
- TextIO.putln("");
- return intTurn;
- }
- public static String[] arrThrow;
- public static String[] arrThrowTemp;
- public static String strMultiplier;
- public static String strThrow;
- public static String strTotal;
- public static int intMultiply;
- public static int intThrow;
- public static int intTotal;
- public static int intTurn;
- public static int intTurn2;
- public static int intDart;
- public static int intPlayerScore;
- public static int intPlayerScore2;
- public static int intPlayerTurnScore;
- public static int intPlayerTurnScore2;
- public static int intTurnCounter;
- public static int intTurnCounter2;
- public static int intWinSwitch;
- public static int userInput;
- public static void main(String[] args) {
- intPlayerScore = 501;
- intPlayerScore2 = 501;
- intTurnCounter = 1;
- intTurnCounter2 =1;
- intWinSwitch = 0;
- while (intWinSwitch == 0) {
- TextIO.putln("Press 1 to throw");
- userInput = TextIO.getlnInt();
- if(userInput == 1 ){
- TextIO.putln("Score " + intPlayerScore + " Turn " + intTurnCounter);
- intTurnCounter++;
- intPlayerTurnScore = aTurn();
- intPlayerScore = intPlayerScore - intPlayerTurnScore;
- }
- if(intPlayerScore <0){
- TextIO.putln("Bust - Player Two Wins.");
- intWinSwitch = 1;
- }
- else if(intMultiply != 2){
- while(intPlayerScore == 0){
- TextIO.putln("You Lose, Player Two wins.");
- intWinSwitch = 1;
- }
- }
- else if(intPlayerScore == 0){
- while(intMultiply == 2){
- TextIO.putln("You Win!");
- intWinSwitch = 1;
- }
- }
- TextIO.putln("");
- TextIO.putln("Player One Score " + intPlayerScore + " Turn " + intTurnCounter);
- TextIO.putln("");
- TextIO.putln("Press 1 to throw");
- userInput = TextIO.getlnInt();
- if(userInput == 1 ){
- TextIO.putln("Score " + intPlayerScore2 + " Turn " + intTurnCounter);
- intTurnCounter2++;
- intPlayerTurnScore2 = aTurn();
- intPlayerScore2 = intPlayerScore2 - intPlayerTurnScore2;
- }
- if(intPlayerScore2 <0){
- TextIO.putln("Bust - Player One Wins.");
- intWinSwitch = 1;
- }
- else if(intMultiply != 2){
- while(intPlayerScore2 == 0){
- TextIO.putln("You Lose, Player Two wins.");
- intWinSwitch = 1;
- }
- }
- else if(intPlayerScore2 == 0){
- while(intMultiply == 2){
- TextIO.putln("You Win!");
- intWinSwitch = 1;
- }
- }
- TextIO.putln("");
- TextIO.putln("Player Two Score " + intPlayerScore2 + " Turn " + intTurnCounter2);
- TextIO.putln("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement