Advertisement
taweesoft

BadmintonGame_Nott

Sep 7th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class BadmintonGame {
  3.     public static void main(String[] args){
  4.             Scanner scanner = new Scanner(System.in);
  5.             System.out.print("Enter name of first player: ");
  6.             String first = scanner.nextLine();
  7.             System.out.print("Enter name of second player: ");
  8.             String second = scanner.nextLine();
  9.             int score;
  10.             int score1;
  11.             int total1 = 0;
  12.             int score2;
  13.             int total2 = 0;
  14.             int ServedNext=0;
  15.             String name="";
  16.             while(total1<30||total2<30){
  17.                 if(total1==0&&total2==0){
  18.                     score = (int)(2*Math.random());
  19.                     if(score==1){
  20.                         total1++;
  21.                         System.out.printf("%s served: %d vs. %d\n",first,total1,total2);
  22.                         ServedNext=1;}
  23.                     else{
  24.                         total2++;
  25.                         System.out.printf("%s served: %d vs. %d\n",first,total1,total2);
  26.                         ServedNext=2;}
  27.                     }
  28.                
  29.                 if(total1>0||total2>0){
  30.                         score = (int)(2*Math.random());
  31.                         if(score==1){
  32.                             total1++;
  33.                             if(ServedNext==1){
  34.                                 name = first;
  35.                             }else{
  36.                                 name = second;
  37.                             }
  38.                             System.out.printf("%s served: %d vs. %d\n",name,total1,total2);
  39.                             ServedNext=1;}
  40.                         else if(score!=1){
  41.                             total2++;
  42.                             if(ServedNext==2){
  43.                                 name = second;
  44.                             }else{
  45.                                 name = first;
  46.                             }
  47.                             System.out.printf("%s served: %d vs. %d\n",name,total1,total2);
  48.                             ServedNext=2;
  49.                             }
  50.                         if(total1<20&&total2==21)
  51.                             break;
  52.                         if(total1==21&&total2<20)
  53.                             break;
  54.                         if(total1>=20&&total2>=20){
  55.                             if(total1-total2==2||total2-total1==2)
  56.                                 break;
  57.                             if(total1==30||total2==30)
  58.                                 break;
  59.                             }
  60.                         }
  61.             }
  62.             if(total1>total2)
  63.                 System.out.printf("%s wins.",first);
  64.             else
  65.                 System.out.printf("%s wins.",second);
  66.         }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement