Re: JAVA Learning Group
Posted: 17 Dec 2017, 00:28
IT'S ALIVE
Finally managed to make your code into .json file.[/i}
...
Finally managed to make your code into .json file.[/i}
...
A feature rich city builder game for Android, iOS and PC
https://forum.theotown.com/
Meanwhile several nuclear wars has startedJustAnyone wrote: ↑17 Dec 2017, 00:28IT'S ALIVE
Finally managed to make your code into .json file.[/i}
...
Code: Select all
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Random;
public class BlackJack {
Random User = new Random();
public static void main(String[] agrs) {
Random User = new Random();
Random Bot = new Random();
Scanner Hit = new Scanner(System.in);
Scanner Bet = new Scanner(System.in);
ArrayList<Integer> UserCards = new ArrayList<Integer>();
ArrayList<Integer> BotCards = new ArrayList<Integer>();
String hit;
int bet;
int bal = 500;
int UserDeck;
int BotDeck;
int UserSum = 0;
int BotSum = 0;
System.out.println("How much will you bet?\n" + "Remaining: " + bal + "$");
bet = Bet.nextInt();
if (bet > bal) {
System.out.println("You don't have that much money left...");
}
else if (bet >= 10) {
UserDeck = User.nextInt(13)+1;
UserCards.add(UserDeck);
System.out.println("Type hit to draw another card, type stand to pass.\n\nYour cards.\n"+ UserDeck +"\n");
BotDeck = Bot.nextInt(13)+1;
BotCards.add(BotDeck);
System.out.println("Bot's cards\n"+ BotDeck);
hit = Hit.nextLine();
while (hit.equals("hit")) {
UserDeck = User.nextInt(13)+1;
UserCards.add(UserDeck);
BotDeck = Bot.nextInt(13)+1;
BotCards.add(BotDeck);
for(int i : UserCards)
UserSum += i;
for(int ii : BotCards)
BotSum += ii;
System.out.println("\n\nYour cards.\n" + UserSum + "\n");
System.out.println("bots cards.\n" + BotSum + "\n");
if(UserSum == 21) {
System.out.println("Black Jack!" + bet + " x2");
bal = bal + bet * 2;
break;
}
else if (UserSum > 21) {
if (BotSum > 21) {
System.out.println("Draw");
break;
}
else if (UserSum > 21) {
if (BotSum < 21) {
System.out.println("You lost..." + bet);
bal = bal - bet;
break;
}
}
else if (BotSum > 21){
if (UserSum < 21) {
System.out.println("You won" + bet);
bal = bal + bet;
break;
}
}
}
hit = Hit.nextLine();
}
if (BotSum < UserSum) {
BotDeck = Bot.nextInt(13)+1;
BotCards.add(BotDeck);
}
if (!hit.equals("hit")){
if (UserSum > BotSum) {
if (UserSum < 21) {
System.out.println("You won!" + bet);
bal = bal + bet;
}
}
else if (UserSum < BotSum){
if (BotSum < 21) {
System.out.println("You Lost..." + bet);
bal = bal - bet;
}
}
else if (UserSum == BotSum) {
System.out.println("Draw");
}
else if (BotSum > UserSum) {
if (BotSum > 21) {
if(UserSum < 21) {
System.out.println("You won!" + bet);
bal = bal + bet;
}
}
else if (UserSum > 21) {
if (BotSum > 21) {
System.out.println("Draw");
}
}
}
}
}
else
System.out.println("You must bet more then 10$");
System.out.println("Remaining: " + bal + "$");
}
}