Advertisement
RageDoc

lottorun

Jun 24th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class lottorun {
  5.    
  6.     private static Scanner sc = new Scanner(System.in);
  7.     private static int hasran = 0;
  8.     private static int hasasked = 0;
  9.    
  10.     public static void main(String... args) throws IOException
  11.     {prompt();}
  12.     protected static void
  13.         prompt(){
  14.         if(hasran == 0)
  15.         System.out.println("Lottoscript is running. Type 'spin' to test your luck.");
  16.         String cmd = sc.nextLine();
  17.         switch(cmd){
  18.             case("spin"):
  19.             case("Spin"):
  20.             case("roll"):roll();
  21.                 break;
  22.             default: System.out.println("Unknown Command.");
  23.             hasran++;
  24.             prompt();
  25.                 break;}
  26.     }
  27.     public static void
  28.     roll(){
  29.         int spins = 3;
  30.         String[] rolls = {"*","@","%","&","$"};
  31.         String[] luck = new String[3];
  32.         int j = 0;
  33.         while(j < (spins*4) + 1){
  34.         System.out.print("-");j++;}j=0;
  35.         System.out.println();
  36.         for(int i = 0; i < spins; i++){
  37.             int ran = (int) (Math.random()*(rolls.length - 1));
  38.             luck[i] = rolls[ran];
  39.             System.out.print(rolls[ran] + "     ");
  40.             if(i == spins - 1)
  41.                 System.out.println();}
  42.         while(j < (spins*4) + 1){
  43.             System.out.print("-");j++;}j=0;
  44.             System.out.println();
  45.         if(luck[0] == luck[1] &&
  46.            luck[1] == luck[2] &&
  47.            luck[2] == luck[0])
  48.             System.out.println("\nYou won!");
  49.         else
  50.             System.out.println("Better luck next time!");
  51.         spinAgain();
  52.     }
  53.    
  54.     public static void spinAgain(){
  55.         if(hasasked == 0)
  56.         System.out.println("Spin again? (y/n)");
  57.         String cmd = sc.nextLine();
  58.         switch(cmd)
  59.         {
  60.         case("y"):
  61.         case("yes"):roll();
  62.                     hasran = 0;
  63.             break;
  64.         case("n"):
  65.         case("no"):System.exit(0);
  66.             break;
  67.            default:System.out.println("Unknown Command.");
  68.             hasasked++;
  69.             spinAgain();
  70.             break;
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement