Advertisement
reyhanzo

Untitled

Dec 17th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.57 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. import java.util.concurrent.TimeUnit;
  4.    
  5. public class Game {
  6.     private final String[] sym = new String[]
  7.     {
  8.         "♤",
  9.         "♥",
  10.         "♢",
  11.         "♧"
  12.     };
  13.     private final String[] val = new String[]
  14.     {
  15.        "A", "2", "3", "4", "5", "6", "7", "8", "9", "10",
  16.         "J", "Q", "K"
  17.     };
  18.     private int ansl, ansr, nlft, nrgt, ans, gss;
  19.     private int score;
  20.    
  21.     public Game()
  22.     {
  23.         score = 0;
  24.         ansl = 0;
  25.         ansr = 0;
  26.         nlft = 0;
  27.         nrgt = 0;
  28.         gss = 0;
  29.         ans = 0;
  30.         System.out.println("Shuffling Cards... Please Wait...");
  31.         try
  32.         {
  33.             TimeUnit.SECONDS.sleep(5);
  34.         }
  35.         catch (InterruptedException ie)
  36.         {
  37.             System.out.println("\n");
  38.         }
  39.         System.out.println("Here's your mystery card:");
  40.         nlft = getCardNum();
  41.         nrgt = getCardNum();
  42.         String numleft = val[nlft];
  43.         String numright = val[nrgt];
  44.         String symleft = sym[getCardSym()];
  45.         String symright = sym[getCardSym()];
  46.         printCard("L", "R", " ", " ", 0, 0);
  47.         play();
  48.         System.out.println("Your cards were:");
  49.         printCard(numleft, numright, symleft, symright, nlft+1, nrgt+1);
  50.     }
  51.    
  52.     public int check()
  53.     {
  54.         if (gss == 1)
  55.         {
  56.             int a = ansl%2;
  57.             int b = (nlft + 1)%2;
  58.             if (a == 0 && b == 0)
  59.             {
  60.                 score = score + 3;
  61.                 System.out.println("Congratulation! You guessed it right.");
  62.                 System.out.println("You got 3 points.");
  63.             }
  64.             else if ( a != 0 && b !=0 )
  65.             {
  66.                 score = score + 3;
  67.                 System.out.println("Congratulation! You guessed it right.");
  68.                 System.out.println("You got 3 points.");
  69.             }
  70.             else
  71.             {
  72.                 score = score - 1;
  73.                 System.out.println("Ow! You guessed wrongly.");
  74.                 System.out.println("You got -1 points.");
  75.                 System.out.println("\nBut don't worry, You can play again.");
  76.             }
  77.         }
  78.         else if (gss == 2)
  79.         {
  80.             int a = ansr%2;
  81.             int b = (nrgt + 1)%2;
  82.             if (a == 0 && b == 0)
  83.             {
  84.                 score = score + 3;
  85.                 System.out.println("Congratulation! You guessed it right.");
  86.                 System.out.println("You got 3 points.");
  87.             }
  88.             else if ( a != 0 && b !=0 )
  89.             {
  90.                 score = score + 3;
  91.                 System.out.println("Congratulation! You guessed it right.");
  92.                 System.out.println("You got 3 points.");
  93.             }
  94.             else
  95.             {
  96.                 score = score - 1;
  97.                 System.out.println("Ow! You guessed wrongly.");
  98.                 System.out.println("You got -1 points.");
  99.                 System.out.println("\nBut don't worry, You can play again.");
  100.             }
  101.         }
  102.         else if (gss == 3)
  103.         {
  104.             int a = ansl%2;
  105.             int b = (nlft + 1)%2;
  106.             int c = ansr%2;
  107.             int d = (nrgt + 1)%2;
  108.             if (((a == 0 && b == 0) || (a != 0 && b != 0)) &&
  109.             ((c == 0 && d == 0) || (c != 0 && d != 0)))
  110.             {
  111.                 score = score + 8;
  112.                 System.out.println("Congratulation! You guessed it right.");
  113.                 System.out.println("You got 8 points.");
  114.             }
  115.             else
  116.             {
  117.                 score = score - 4;
  118.                 System.out.println("Ow! You guessed wrongly.");
  119.                 System.out.println("You got -4 points.");
  120.                 System.out.println("\nBut don't worry, You can play again.");
  121.             }
  122.         }
  123.         else if (gss == 4)
  124.         {
  125.            int a = (ansl + ansr)%2;
  126.            int b = (nlft + nrgt + 2)%2;
  127.             if (a == 0 && b == 0)
  128.             {
  129.                 score = score + 6;
  130.                 System.out.println("Congratulation! You guessed it right.");
  131.                 System.out.println("You got 6 points.");
  132.             }
  133.             else if ( a != 0 && b !=0 )
  134.             {
  135.                 score = score + 6;
  136.                 System.out.println("Congratulation! You guessed it right.");
  137.                 System.out.println("You got 6 points.");
  138.             }
  139.             else
  140.             {
  141.                 score = score - 3;
  142.                 System.out.println("Ow! You guessed wrongly.");
  143.                 System.out.println("You got -3 points.");
  144.                 System.out.println("\nBut don't worry, You can play again.");
  145.             }
  146.         }
  147.         else
  148.         {
  149.             score = score;
  150.         }
  151.         return score;
  152.     }
  153.    
  154.     public void play()
  155.     {
  156.         System.out.println("Wanna Guess?");
  157.         System.out.println("1. Left card only.");
  158.         System.out.println("2. Right card only.");
  159.         System.out.println("3. Left and right card.");
  160.         System.out.println("4. Addition of both cards.");
  161.         System.out.println("Or insert number other than 1 - 4 to cancel the game.");
  162.         Scanner sc = new Scanner(System.in);
  163.         gss = sc.nextInt();
  164.         switch(gss)
  165.         {
  166.             case 1:
  167.             System.out.println("Left Card is: ");
  168.             System.out.println("(insert 1 = Odd or 2 = Even)");
  169.             ansl = sc.nextInt();
  170.             break;
  171.             case 2:
  172.             System.out.println("Right Card is: ");
  173.             System.out.println("(insert 1 = Odd or 2 = Even)");
  174.             ansr = sc.nextInt();
  175.             break;
  176.             case 3:
  177.             System.out.println("Left Card is: ");
  178.             System.out.println("(insert 1 = Odd or 2 = Even)");
  179.             ansl = sc.nextInt();
  180.             System.out.println("Right Card is: ");
  181.             System.out.println("(insert 1 = Odd or 2 = Even)");
  182.             ansr = sc.nextInt();
  183.             break;
  184.             case 4:
  185.             System.out.println("Left + Right Card Number is: ");
  186.             System.out.println("(insert 1 = Odd or 2 = Even)");
  187.             ansl = sc.nextInt();
  188.             ans = ansr + ansl;
  189.             break;
  190.             default:
  191.             System.out.println("You have choosen to cancel the game.");
  192.             break;
  193.         }
  194.     }
  195.    
  196.     public void printCard(String numleft, String numright, String symleft, String symright, int num1, int num2)
  197.     {
  198.         if (num1 != 10 && num2 != 10)
  199.         {
  200.             System.out.println("_____________     _____________");
  201.             System.out.println("|           |     |           |");
  202.             System.out.println("|           |     |           |");
  203.             System.out.println("|           |     |           |");
  204.             System.out.println("|     "+numleft+"     |     |     "+numright+"     |");
  205.             System.out.println("|     "+symleft+"     |     |     "+symright+"     |");
  206.             System.out.println("|           |     |           |");
  207.             System.out.println("|           |     |           |");
  208.             System.out.println("|___________|     |___________|\n");
  209.         }
  210.         else if (num1 == 10 && num2 != 10)
  211.         {
  212.             System.out.println("______________     _____________");
  213.             System.out.println("|            |     |           |");
  214.             System.out.println("|            |     |           |");
  215.             System.out.println("|            |     |           |");
  216.             System.out.println("|     "+numleft+"     |     |     "+numright+"     |");
  217.             System.out.println("|      "+symleft+"     |     |     "+symright+"     |");
  218.             System.out.println("|            |     |           |");
  219.             System.out.println("|            |     |           |");
  220.             System.out.println("|____________|     |___________|\n");
  221.         }
  222.         else if (num1 != 10 && num2 == 10)
  223.         {
  224.             System.out.println("_____________     ______________");
  225.             System.out.println("|           |     |            |");
  226.             System.out.println("|           |     |            |");
  227.             System.out.println("|           |     |            |");
  228.             System.out.println("|     "+numleft+"     |     |     "+numright+"     |");
  229.             System.out.println("|     "+symleft+"     |     |      "+symright+"     |");
  230.             System.out.println("|           |     |            |");
  231.             System.out.println("|           |     |            |");
  232.             System.out.println("|___________|     |____________|\n");
  233.         }
  234.         else
  235.         {
  236.             System.out.println("______________     ______________");
  237.             System.out.println("|            |     |            |");
  238.             System.out.println("|            |     |            |");
  239.             System.out.println("|            |     |            |");
  240.             System.out.println("|     "+numleft+"     |     |     "+numright+"     |");
  241.             System.out.println("|      "+symleft+"     |     |      "+symright+"     |");
  242.             System.out.println("|            |     |            |");
  243.             System.out.println("|            |     |            |");
  244.             System.out.println("|____________|     |____________|\n");
  245.         }
  246.     }
  247.    
  248.     public int getCardNum()
  249.     {
  250.         Random rnd = new Random();
  251.         int num = rnd.nextInt(12);
  252.         return num;
  253.     }
  254.    
  255.     public int getCardSym()
  256.     {
  257.         Random rnd = new Random();
  258.         int sym = rnd.nextInt(3);
  259.         return sym;
  260.     }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement