Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.07 KB | None | 0 0
  1. public class darts_final2 {
  2.  
  3.    public static String[] dartThrow() {  
  4.                
  5.     intMultiply =  (1 + (int)(Math.random()*3));
  6.     intThrow = (1+(int)(Math.random()*22));
  7.     strThrow = Integer.toString(intThrow);
  8.            
  9.      if(intThrow == 21){
  10.         intThrow = 25;
  11.         intMultiply = 1;
  12.         strThrow = "Bull";
  13.         }
  14.      else if (intThrow == 22){
  15.               intThrow = 25;
  16.               intMultiply = 2;
  17.               strThrow = "Bull";
  18.               }
  19.     if(intMultiply == 1){
  20.        strMultiplier = ("Single");
  21.        }
  22.     else if(intMultiply == 2){
  23.             strMultiplier = ("Double");
  24.             }
  25.     else if(intMultiply == 3){
  26.             strMultiplier = ("Treble");
  27.             }
  28.            
  29.     intTotal = (intMultiply * intThrow);
  30.     strTotal = Integer.toString(intTotal);
  31.            
  32.     arrThrow = new String[3];
  33.     arrThrow[0] = strMultiplier;
  34.     arrThrow[1] = strThrow;
  35.     arrThrow[2] = strTotal;
  36.            
  37.     return arrThrow;
  38.    }
  39.  
  40. public static int aTurn() {
  41.              
  42.   intTurn = 0;  
  43.              
  44.  for(int i=1; i<4; i++){
  45.     arrThrowTemp = new String[3];
  46.     arrThrowTemp = dartThrow();
  47.     TextIO.putln("   " + arrThrowTemp[0] + " " + arrThrowTemp[1] + " = " + arrThrowTemp[2]);
  48.     intTurn = intTurn + Integer.parseInt(arrThrowTemp[2]);      
  49.  
  50.     if (intPlayerScore - intTurn <= 0){
  51.            break;
  52.         }
  53.   }
  54.     TextIO.putln("Turn Score = " + intTurn);
  55.     TextIO.putln("");
  56.              
  57.     return intTurn;
  58.     }
  59.  
  60. public static String[] arrThrow;
  61. public static String[] arrThrowTemp;
  62. public static String strMultiplier;
  63. public static String strThrow;
  64. public static String strTotal;
  65. public static int intMultiply;
  66. public static int intThrow;
  67. public static int intTotal;
  68. public static int intTurn;
  69. public static int intTurn2;
  70. public static int intDart;
  71. public static int intPlayerScore;
  72. public static int intPlayerScore2;
  73. public static int intPlayerTurnScore;
  74. public static int intPlayerTurnScore2;
  75. public static int intTurnCounter;
  76. public static int intTurnCounter2;
  77. public static int intWinSwitch;
  78. public static int userInput;
  79.            
  80. public static void main(String[] args) {
  81.     intPlayerScore = 501;
  82.     intPlayerScore2 = 501;
  83.     intTurnCounter = 1;
  84.     intTurnCounter2 =1;
  85.     intWinSwitch = 0;
  86.  
  87.     while (intWinSwitch == 0) {                
  88.            TextIO.putln("Press 1 to throw");
  89.             userInput = TextIO.getlnInt();
  90.  
  91.             if(userInput == 1 ){
  92.                    
  93.                 TextIO.putln("Score " + intPlayerScore + "    Turn " + intTurnCounter);
  94.                 intTurnCounter++;
  95.                 intPlayerTurnScore = aTurn();
  96.                 intPlayerScore = intPlayerScore - intPlayerTurnScore;
  97.                 }
  98.             if(intPlayerScore <0){
  99.                 TextIO.putln("Bust - Player Two Wins.");
  100.                 intWinSwitch = 1;
  101.                 }
  102.             else if(intMultiply != 2){
  103.                 while(intPlayerScore == 0){
  104.                    TextIO.putln("You Lose, Player Two wins.");
  105.                    intWinSwitch = 1;
  106.                    }
  107.              }
  108.             else if(intPlayerScore == 0){
  109.                 while(intMultiply == 2){
  110.                    TextIO.putln("You Win!");
  111.                    intWinSwitch = 1;
  112.                 }
  113.             }
  114.                
  115.             TextIO.putln("");
  116.             TextIO.putln("Player One Score " + intPlayerScore + "    Turn " + intTurnCounter);     
  117.             TextIO.putln("");
  118.  
  119.  
  120.             TextIO.putln("Press 1 to throw");
  121.             userInput = TextIO.getlnInt();
  122.  
  123.             if(userInput == 1 ){
  124.                    
  125.                 TextIO.putln("Score " + intPlayerScore2 + "    Turn " + intTurnCounter);
  126.                 intTurnCounter2++;
  127.                 intPlayerTurnScore2 = aTurn();
  128.                 intPlayerScore2 = intPlayerScore2 - intPlayerTurnScore2;
  129.                 }
  130.             if(intPlayerScore2 <0){
  131.                 TextIO.putln("Bust - Player One Wins.");
  132.                 intWinSwitch = 1;
  133.                 }
  134.             else if(intMultiply != 2){
  135.                 while(intPlayerScore2 == 0){
  136.                    TextIO.putln("You Lose, Player Two wins.");
  137.                    intWinSwitch = 1;
  138.                    }
  139.              }
  140.             else if(intPlayerScore2 == 0){
  141.                 while(intMultiply == 2){
  142.                    TextIO.putln("You Win!");
  143.                    intWinSwitch = 1;
  144.                 }
  145.             }
  146.                
  147.             TextIO.putln("");
  148.             TextIO.putln("Player Two Score " + intPlayerScore2 + "    Turn " + intTurnCounter2);   
  149.             TextIO.putln("");
  150.             }          
  151.             }
  152.            
  153.                                
  154.            
  155.        
  156.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement