Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.52 KB | None | 0 0
  1. import java.util.Random;
  2. import javax.swing.JOptionPane;
  3.  
  4. public class Setup
  5. {
  6.     private int pile;
  7.     private int comp;
  8.     private String pname;
  9.     private String diff;
  10.    
  11.     Random randNum = new Random();
  12.    
  13.     public Setup()
  14.     {
  15.         pile = 0;
  16.     }
  17.    
  18.     public void setName()
  19.     {
  20.         String name = JOptionPane.showInputDialog("What is your name?");
  21.         pname = name;
  22.     }
  23.    
  24.     public void setPileSize()
  25.     {
  26.         String input = JOptionPane.showInputDialog("How big of a pile? From 10-100");
  27.         int amt = Integer.parseInt(input);
  28.         while (amt < 10 || amt > 100)
  29.         {
  30.             input = JOptionPane.showInputDialog("How big of a pile? From 10-100");
  31.             amt = Integer.parseInt(input);
  32.         }
  33.        
  34.         pile = amt;
  35.     }
  36.    
  37.     public void ranPileSize()
  38.     {
  39.         int f = 1+randNum.nextInt(100);
  40.         while (f<10)
  41.             f = 1+randNum.nextInt(100);
  42.         pile = f;
  43.     }
  44.    
  45.     public void setComp()
  46.     {
  47.         String input = JOptionPane.showInputDialog("Dumb or Smart computer? Dumb = 0, Smart = 1");
  48.         int amt = Integer.parseInt(input);
  49.        
  50.         do
  51.         {
  52.             if (input.equals("0"))
  53.                 diff = "Dumb";
  54.             else if (input.equals("1"))
  55.                 diff = "Smart";
  56.             else    
  57.             {
  58.                 input = JOptionPane.showInputDialog("Dumb or Smart ccomputer? Dumb = 0, Smart = 1");
  59.                 amt = Integer.parseInt(input);
  60.             }
  61.         } while (amt < 0 || amt > 1);
  62.     }
  63.    
  64.     public int getPile()
  65.     {
  66.         return pile;
  67.     }
  68.    
  69.     public String getName()
  70.     {
  71.         return pname;
  72.     }
  73.    
  74.     public String getDiff()
  75.     {
  76.         return diff;
  77.     }
  78.  
  79.     public int runPile()
  80.     {
  81.         setName();
  82.         setComp();
  83.        
  84.         String input = JOptionPane.showInputDialog("Random size or Select size? 0 = Select, 1 = Random");
  85.         int amt = Integer.parseInt(input);
  86.        
  87.         if (amt == 0)
  88.             setPileSize();
  89.         else if (amt == 1)
  90.             ranPileSize();
  91.         while (amt < 0 || amt > 1)
  92.         {
  93.             input = JOptionPane.showInputDialog("Random size or Select size? 0 = Select, 1 = Random");
  94.                 amt = Integer.parseInt(input);
  95.         }
  96.        
  97.         System.out.println("Player name: "+ getName() + "\nPile Size: "+ getPile() + "\nDifficulty: " + getDiff());
  98.        
  99.         System.exit(0);
  100.        
  101.         return pile;
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement