foobar (Sep.3-2014)

From LiBaX, 7 Years ago, written in Java, viewed 740 times.
URL https://code.nat.moe/view/1d8e577a Embed
Download Paste or View Raw
  1. import java.util.Scanner;
  2. public class foobar {
  3.         public static void main(String[] args) {
  4.                 while (game() == 0) {
  5.                 }
  6.                 System.out.println("Bye.");
  7.                 return;
  8.         }
  9.  
  10.         private static int game() {
  11.                 Scanner input = new Scanner(System.in);
  12.                 int ran = (int)(Math.random() * 3);
  13.  
  14.                 System.out.println("0: paper");
  15.                 System.out.println("1: scissors");
  16.                 System.out.println("2: stone");
  17.                 System.out.println("3: exit the game");
  18.                 System.out.println("Your choice (0, 1, 2, or 3 to exit):");
  19.                 int player = input.nextInt();
  20.                 if (player == 3) return 1;
  21.                 if (player < 0 || player > 3) wrongInput();
  22.                 //System.out.println("Your choice is : " + player);
  23.                 //System.out.println(ran);
  24.  
  25.                 if (player == ran) {
  26.                         draw(player, ran);
  27.                         return 0;
  28.                 }
  29.                 if (player == 0 && ran == 2) {
  30.                         win(player, ran);
  31.                         return 0;
  32.                 }
  33.                 if (player == 1 && ran == 0) {
  34.                         win(player, ran);
  35.                         return 0;
  36.                 }
  37.                 if (player == 2 && ran == 1) {
  38.                         win(player, ran);
  39.                         return 0;
  40.                 }
  41.                 lose(player, ran);
  42.                 return 0;
  43.         }
  44.  
  45.         private static void wrongInput() {
  46.                 System.out.println("Please type 0, 1, 2, or 3 to exit.");
  47.         }
  48.  
  49.         private static void win(int player, int ran) {
  50.                 System.out.println("You win. " + player + " vs " + ran + ".");
  51.         }
  52.  
  53.         private static void lose(int player, int ran) {
  54.                 System.out.println("You lose. " + player + " vs " + ran + ".");
  55.         }
  56.  
  57.         private static void draw(int player, int ran) {
  58.                 System.out.println("Draw. " + player + " vs " + ran + ".");
  59.         }
  60. }
  61.  

Reply to "foobar (Sep.3-2014)"

Here you can reply to the paste above

captcha