Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class lottorun {
- private static Scanner sc = new Scanner(System.in);
- private static int hasran = 0;
- private static int hasasked = 0;
- public static void main(String... args) throws IOException
- {prompt();}
- protected static void
- prompt(){
- if(hasran == 0)
- System.out.println("Lottoscript is running. Type 'spin' to test your luck.");
- String cmd = sc.nextLine();
- switch(cmd){
- case("spin"):
- case("Spin"):
- case("roll"):roll();
- break;
- default: System.out.println("Unknown Command.");
- hasran++;
- prompt();
- break;}
- }
- public static void
- roll(){
- int spins = 3;
- String[] rolls = {"*","@","%","&","$"};
- String[] luck = new String[3];
- int j = 0;
- while(j < (spins*4) + 1){
- System.out.print("-");j++;}j=0;
- System.out.println();
- for(int i = 0; i < spins; i++){
- int ran = (int) (Math.random()*(rolls.length - 1));
- luck[i] = rolls[ran];
- System.out.print(rolls[ran] + " ");
- if(i == spins - 1)
- System.out.println();}
- while(j < (spins*4) + 1){
- System.out.print("-");j++;}j=0;
- System.out.println();
- if(luck[0] == luck[1] &&
- luck[1] == luck[2] &&
- luck[2] == luck[0])
- System.out.println("\nYou won!");
- else
- System.out.println("Better luck next time!");
- spinAgain();
- }
- public static void spinAgain(){
- if(hasasked == 0)
- System.out.println("Spin again? (y/n)");
- String cmd = sc.nextLine();
- switch(cmd)
- {
- case("y"):
- case("yes"):roll();
- hasran = 0;
- break;
- case("n"):
- case("no"):System.exit(0);
- break;
- default:System.out.println("Unknown Command.");
- hasasked++;
- spinAgain();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement