# Project #3

## Code

```///colin hinton
///5th period
///Blackjack.java
///12/7/2015

import java.util.Random;
import java.util.Scanner;

class Blackjack
{
public static void main (String [] args)
{
Scanner kb = new Scanner(System.in);
Random r = new Random();

int myBank, hand1, hand2;
myBank = 500;

//This is the intro to our poker boss fight
System.out.println("Welcome to Casino Royal.");

System.out.println("You must beat me AZRL your dealer and opponent.");

System.out.print("Tell me your name worthy opponent? ");
String name = kb.next();

System.out.println("Well then " + name + " I hope you are ready.");
System.out.println("You win if you make \$5000, you loose go broke.");
System.out.println("Just an fyi, 1 is an Ace, 11 is Jack, 12 is Queen, and 13 is King");
System.out.println(name + " Let the games begin");

//The game should continue untill the play is broke or makes 5000 dollars
while ( myBank <= 5000 && myBank > 0)
{
System.out.println("\$" + myBank);
System.out.println("How much do you wager " + name);
int bet = kb.nextInt();
myBank = myBank - bet;
hand1 = 0 ;
hand2 = 0 ;
System.out.println("\$" + myBank);

//this is the for statement for each hand
//there are two hands, one where the ace equals 1 and 11
//the ifs are elses below are for aces and face cards
int x = (1 + r.nextInt(13));
int y = (1 + r.nextInt(13));
if (x==1)
{

x = 1;
hand1++  ;
hand2 = hand2 + 11;
}
else if (x == 11 )
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else if (x == 12)
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else if (x == 13)
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else
{
hand1 = hand1 + x;
hand2 = hand2 + x;
}
if (y==1)
{
hand1++  ;
hand2 = hand2+ 11;
}
else if (y == 11 )
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else if (y == 12)
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else if (y == 13)
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else
{
hand1 = hand1 + y;
hand2 = hand2 + y;
}
System.out.println("You drew "  + x + " and "  + y + ".");

if (hand2 == 21 )
{

System.out.println("Look who got lucky");
myBank = (myBank + (bet  * 3)) ;
//for this game a blackjack will give the bet^2 cause rng
}
else
{
if ((hand1 < 21) && (hand2 < 21))
{
System.out.println("Your two hands could be " + hand1 + " or " + hand2 + ".");
}
else
{
System.out.println("Your hand is " + hand1);
}
//Random boss commentary
System.out.println("Here is my hand well you can see half my hand");
//the boss will not hit if he has a hand >= 16
int hand3 = 0;
int hand4 = 0;
int xx = (1 + r.nextInt(13));
int yy = (1 + r.nextInt(13));
if (xx==1)
{
hand3++  ;
hand4 = hand4 + 11;
}
else if (xx == 11 )
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else if (xx == 12)
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else if (xx == 13)
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else
{
hand3 = hand1 + xx;
hand4 = hand2 + xx;
}
if (yy==1)
{
hand3++  ;
hand4 = hand4+ 11;
}
else if (yy == 11 )
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else if (yy == 12)
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else if (yy == 13)
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else
{
hand3 = hand3 + yy;
hand4 = hand4 + yy;
}
System.out.println("All you get to see is this card " + xx);

String hc;

// this int check is so that when they check it ends the while loop
for (int check = 0 ; check <= 25 ; check = check + 1)
{
System.out.println("What will it be " + name + " hit or check? ");
hc = kb.next();

if (hc.equals("check"))
{
check= check + 25;
}

else if (hc.equals("hit"))
{

int z = (1 + r.nextInt(13));
if (z==1)
{
hand1++  ;
hand2++;
}
else if (z == 11 )
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else if (z == 12)
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else if (z == 13)
{
hand1 = hand1 + 10;
hand2 = hand2 + 10;
}
else
{
hand1 = hand1 + z;
hand2 = hand2 + z;
}
System.out.println("Alright here is your next card " + z);
}
}
if (hand1 > 21)
{
System.out.println("You overdrew you FOOL!");
}
else if ((hand1 == 21) || (hand2 == 21) )
{
myBank = myBank + ( bet * 3 );
System.out.println("Well played, you got lucky " + name);
}
else
{
while (hand3 < 16 || hand4 < 16)
{
int zz = (1 + r.nextInt(13));
if (zz==1)
{
hand3++  ;
hand4++;
}
else if (zz == 11 )
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else if (zz == 12)
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else if (zz == 13)
{
hand3 = hand3 + 10;
hand4 = hand4 + 10;
}
else
{
hand3 = hand3 + zz;
hand4 = hand4 + zz;
}
System.out.println("I drew " + zz);
}
int handFinal, handAi;

if (hand2 > hand1 && hand2 < 21)
{
handFinal = hand2;
}
else
{
handFinal = hand1;
}
if (hand4 > hand3 && hand4 < 21)
{
handAi = hand4;
}
else
{
handAi = hand3;
}
//this determins which hand is the best to use
if ( handFinal > handAi)
{
System.out.println("You win, barley. my hand size was " + handAi);
myBank = myBank + (2 * bet);
}
else if ( handFinal == handAi)
{
System.out.println("A draw, typical just my luck");
myBank = myBank + bet;
}
else
{
System.out.println("I WIN H4H4H4H4 YOUR MONEY IS MINE!");

System.out.println("sorry i got carried away, my hand was " + handAi);
}
}
}
}
System.out.println("This game is done, if you won or lost isn't the point, i'm just bored.");

System.out.println("Till we meet again");
}
}
```

### Picture of the output 