Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The first player to reach 50 points win
- */
- import javax.swing.JOptionPane;
- class Dice
- {
- public void game()
- {
- int n=0,random;
- int s1=0,s2=0;
- String s;
- while(s1<50 && s2<50)
- {
- random=(int)(Math.random()*100);
- while(random>6)
- random=random-4;
- if((n%2)==0)
- {
- s1+=random;
- JOptionPane.showMessageDialog(null,"Player 1 \n"+random+"\nTotal = "+s1);
- }
- else
- {
- s2+=random;
- JOptionPane.showMessageDialog(null,"Player 2 \n"+random+"\nTotal = "+s2);
- }
- JOptionPane.showMessageDialog(null,"Press ok to continue");
- n++;
- }
- if(s1>50 && s1>s2)
- JOptionPane.showMessageDialog(null,"Player 1 wins");
- else if(s2>50 && s2>s1)
- JOptionPane.showMessageDialog(null,"Player 2 wins");
- else
- JOptionPane.showMessageDialog(null,"Tie");
- }
- public static void main(String args[])
- {
- Dice ob=new Dice();
- ob.game();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment