KillianO92

Edited Craps

Dec 19th, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1.     private class PlayButtonHandler implements ActionListener
  2.     {
  3.  
  4.         public int rollDice()
  5.         {
  6.             int iDie = (int)(Math.random()*6) +1;
  7.  
  8.             return (iDie);
  9.         }
  10.  
  11.         public void writeMessage(String sOutput)
  12.         {
  13.             jtaGame.append(sOutput);
  14.         }
  15.  
  16.         public void actionPerformed(ActionEvent e)
  17.         {
  18.             rollDice();
  19.  
  20.             int iDie1 = new rollDice();
  21.             int iDie2 = new rollDice();
  22.  
  23.             int iSum = iDie1 + iDie2;
  24.  
  25.             String sRoll = "You rolled " + iDie1 + "+" + iDie2 + "=" + iSum + ".\n";
  26.             String sOutput = "";
  27.             int iPoint = 0;
  28.  
  29.             switch(iSum)
  30.             {
  31.                 case 7:
  32.                 case 11:
  33.                         sOutput = sRoll + "You win because you got a natural :)";
  34.                         break;
  35.                 case 2:
  36.                 case 3:
  37.                 case 12:
  38.                         sOutput = sRoll + "You lost because you got a crap out :(";
  39.                 default:
  40.                         sOutput = sRoll + "Point is: " + iSum + ".";
  41.             }
  42.  
  43.  
  44.         }
  45.  
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment