Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- System.out.println("Simple 21 game");
- Scanner scan = new Scanner(System.in);
- Random myRandom = new Random();
- int total = 1;
- int botTotal = 1;
- boolean loop = false;
- while (!loop) {
- String end = "end";
- String Add = "Add";
- System.out.println("Add/end?");
- String answer = scan.nextLine();
- if (answer.equals(Add)) {
- int human = myRandom.nextInt(11);
- int bot = myRandom.nextInt(11);
- botTotal = (bot + botTotal);
- total = (human + total);
- System.out.println("Your current score: " + total);
- if (total > 21)
- {
- System.out.println("You lose! Too far.");
- //System.out.println("Debug:" + botTotal);
- break;
- }
- else if (botTotal > 21)
- {
- System.out.println("You win! Bot went too far");
- //System.out.println("Debug:" + botTotal);
- break;
- }
- else if (total == 21 && botTotal < 21)
- {
- System.out.println("21, you win!");
- //System.out.println("Debug:" + botTotal);
- break;
- }
- else if (total == 21 && botTotal == 21) {
- System.out.println("Tie!");
- //System.out.println("Debug:" + botTotal);
- break;
- }
- } else if (answer.equals(end)) {
- System.out.println("Current score is Human: " + total + " Bot: " + botTotal);
- if (total == botTotal) {
- System.out.println("Tie!");
- //System.out.println("Debug:" + botTotal);
- break;
- }
- else if (total > botTotal && total < 21)
- {
- System.out.println("You win!");
- //System.out.println("Debug:" + botTotal);
- break;
- }
- else if (total < botTotal && total < 21)
- {
- System.out.println("You lose!");
- //System.out.println("Debug:" + botTotal);
- break;
- }
- }
- else System.out.println("wrong answer");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement