Advertisement
Guest User

Javaprg1

a guest
Nov 25th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         System.out.println("Simple 21 game");
  11.  
  12.         Scanner scan = new Scanner(System.in);
  13.         Random myRandom = new Random();
  14.  
  15.         int total = 1;
  16.         int botTotal = 1;
  17.         boolean loop = false;
  18.         while (!loop) {
  19.  
  20.             String end = "end";
  21.             String Add = "Add";
  22.  
  23.  
  24.             System.out.println("Add/end?");
  25.             String answer = scan.nextLine();
  26.  
  27.  
  28.             if (answer.equals(Add)) {
  29.                 int human = myRandom.nextInt(11);
  30.                 int bot = myRandom.nextInt(11);
  31.                 botTotal = (bot + botTotal);
  32.                 total = (human + total);
  33.                 System.out.println("Your current score: " + total);
  34.  
  35.                 if (total > 21)
  36.                 {
  37.                     System.out.println("You lose! Too far.");
  38.                     //System.out.println("Debug:" + botTotal);
  39.                     break;
  40.                 }
  41.  
  42.                 else if (botTotal > 21)
  43.                 {
  44.                     System.out.println("You win! Bot went too far");
  45.                     //System.out.println("Debug:" + botTotal);
  46.  
  47.                     break;
  48.                 }
  49.                 else if (total == 21 && botTotal < 21)
  50.                 {
  51.                     System.out.println("21, you win!");
  52.                     //System.out.println("Debug:" + botTotal);
  53.  
  54.                     break;
  55.                 }
  56.  
  57.                 else if (total == 21 && botTotal == 21) {
  58.  
  59.                     System.out.println("Tie!");
  60.                     //System.out.println("Debug:" + botTotal);
  61.  
  62.                     break;
  63.                 }
  64.  
  65.  
  66.  
  67.             } else if (answer.equals(end))  {
  68.                 System.out.println("Current score is Human: " + total + " Bot: " + botTotal);
  69.  
  70.                 if (total == botTotal) {
  71.  
  72.                     System.out.println("Tie!");
  73.                     //System.out.println("Debug:" + botTotal);
  74.  
  75.                     break;
  76.                 }
  77.  
  78.                 else if (total > botTotal && total < 21)
  79.                 {
  80.                     System.out.println("You win!");
  81.                     //System.out.println("Debug:" + botTotal);
  82.  
  83.                     break;
  84.                 }
  85.  
  86.                 else if (total < botTotal && total < 21)
  87.                 {
  88.                     System.out.println("You lose!");
  89.                     //System.out.println("Debug:" + botTotal);
  90.  
  91.                     break;
  92.                 }
  93.  
  94.  
  95.             }
  96.  
  97.             else System.out.println("wrong answer");
  98.  
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement