I am fairly new to this, so please tell me whether this is a good way to write code or if I'm missing anything.
import ehs.*;
import java.util.Scanner;
public class blackjack
{
public static void main(String[] args)
{
BlackJack();
}
public static void BlackJack()
{
boolean again;
int money = money();
int cheat = hiddenCheat();
do{
int cheatCode = cheatMenu(cheat);
int multiplier = activate(cheatCode);
int bet = bet(money, cheatCode);
Deck deck = dealDeck();
int com = comDeal(deck, cheatCode);
int user = userDeal(deck, cheatCode);
int userTotal = userHit(user, deck, cheatCode);
int comTotal = comHit(com, deck, userTotal, cheatCode);
int winner = whoWon(userTotal, comTotal);
money = winnings(winner, bet, money, multiplier, cheatCode);
cheat = hiddenCheat();}
while(money > 0);
bye();
}
public static int money()
{
System.out.println("You will start with 50 dollars");
System.out.println();
return 50;
}
public static int hiddenCheat()
{
Delay.wait(100);
Scanner kb = new Scanner(System.in);
System.out.print("Ready To Play (y)es (n)o -> ");
String again = kb.nextLine();
while (!again.equals("n") && !again.equals("y") && !again.equals("cheat")){
System.out.print("Ready To Play (y)es (n)o -> ");
again = kb.nextLine();}
if ((again).equals("n"))
System.exit(0);
if (again .equals("y"))
return 0;
if ((again).equals("cheat"))
return 1;
return 0;
}
public static int cheatMenu(int cheat)
{
if(cheat == 0)
return 0;
System.out.println();
System.out.println("HIDDEN CHEAT MENU");
System.out.println();
System.out.println("1. Score Multiplier");
System.out.println();
System.out.println("2. Unlimited Money");
System.out.println();
System.out.println("3. Com Alwyas Busts");
System.out.println();
System.out.println("4. 21 Everytime");
System.out.println();
System.out.println("5. Turn Off All Cheats");
System.out.println();
Scanner kb = new Scanner(System.in);
System.out.print("Which cheat would you like? - > ");
int code = kb.nextInt();
while(code != 1 && code != 2 && code != 3 && code != 4 && code != 5){
System.out.print("Not a valid cheat code, try again - > ");
code = kb.nextInt();}
return code;
}
public static int activate(int code)
{
if(code == 0)
return 1;
Scanner kb = new Scanner(System.in);
System.out.println();
if(code == 1){
System.out.print("what Would you like you Score Multiplier to be - > ");
int score = kb.nextInt();
System.out.print("Score Multiplier Activated (" + score + ")");
System.out.println();
return score;
}
if(code == 2){
System.out.println("Unlimited Money Activated");
System.out.println();}
if(code == 3){
System.out.println("Com Alwyas Busts Activated");
System.out.println();}
if(code == 4){
System.out.println("21 Everytime Activated");
System.out.println();}
if(code == 5){
System.out.println("All Cheats Deactivated");
System.out.println();}
return 1;
}
public static int bet(int money, int code)
{
if(code == 2){
money = 999999999;
System.out.println("You now have " + money + " dollars");}
Scanner kb = new Scanner(System.in);
System.out.println();
System.out.print("How much would you like to bet - > ");
int bet = kb.nextInt();
while(bet > money){
System.out.println("You dont have that much money");
System.out.println();
System.out.print("How much would you like to bet - > ");
bet = kb.nextInt();}
return bet;
}
public static Deck dealDeck()
{
Deck deck = new Deck();
deck.shuffle();
return deck;
}
public static int comDeal(Deck deck, int code)
{
Card c1 = deck.dealOne();
Card c2 = deck.dealOne();
int total = 0;
total = total + c1.BJvalue() + c2.BJvalue();
if(code == 3){
while(total != 16){
total = 0;
c1 = deck.dealOne();
c2 = deck.dealOne();
total = c1.BJvalue() + c2.BJvalue();}}
System.out.println();
System.out.println("Com Cards...");
Delay.wait(100);
System.out.println();
System.out.print(c1.face() + " of " + c1.suit());
System.out.println(" and blank");
if(c1.BJvalue() == 1 || c2.BJvalue() == 1){
if(c1.BJvalue() == 1 && c2.BJvalue() == 1){
total = 12;}
else if(c1.BJvalue() == 1){
total = 11 + c2.BJvalue();}
else total = 11 + c1.BJvalue();}
return total;
}
public static int userDeal(Deck deck, int code)
{
Scanner kb = new Scanner(System.in);
System.out.println();
Delay.wait(300);
Card c1 = deck.dealOne();
Card c2 = deck.dealOne();
int total = 0;
total = total + c1.BJvalue() + c2.BJvalue();
int ace = 0;
int ace2 = 0;
if(c1.BJvalue() == 1 || c2.BJvalue() == 1){
System.out.println();
System.out.print(c1.face() + " of " + c1.suit());
System.out.println(" and " + c2.face() + " of " + c2.suit());
if(c1.BJvalue() == 1 && c2.BJvalue() == 1){
System.out.println();
System.out.print("Would you like your first ace to be (11) or (1) -> ");
ace = kb.nextInt();
while(ace != 1 && ace != 11){
System.out.print("Has to be either (11) or (1) -> ");
ace = kb.nextInt();}
System.out.println();
System.out.print("Would you like your second ace to be (11) or (1) -> ");
ace2 = kb.nextInt();
while(ace2 != 1 && ace2 != 11){
System.out.print("Has to be either (11) or (1) -> ");
ace2 = kb.nextInt();}
total = ace + ace2;}
if(c1.BJvalue() == 1){
System.out.println();
System.out.print("Would you like your ace to be (11) or (1) -> ");
ace = kb.nextInt();
while(ace != 1 && ace != 11){
System.out.print("Has to be either (11) or (1) -> ");
ace = kb.nextInt();}
total = ace + c2.BJvalue();}
if(c2.BJvalue() == 1){
System.out.println();
System.out.print("Would you like your ace to be (11) or (1) -> ");
ace2 = kb.nextInt();
while(ace2 != 1 && ace2 != 11){
System.out.print("Has to be either (11) or (1) -> ");
ace2 = kb.nextInt();}
total = ace2 + c1.BJvalue();}}
if(code == 4){
while(total < 10){
total = 0;
c1 = deck.dealOne();
c2 = deck.dealOne();
total = c1.BJvalue() + c2.BJvalue();}}
System.out.println("Your Cards...");
Delay.wait(100);
System.out.println();
System.out.print(c1.face() + " of " + c1.suit());
System.out.println(" and " + c2.face() + " of " + c2.suit() + " (" + total + ")");
System.out.println();
return total;
}
public static int userHit(int total, Deck deck, int code)
{
Scanner kb = new Scanner(System.in);
int ace = 0;
boolean again = true;
again = again("Hit?");
if(again == false)
return total;
int cheat = total;
do{
Card c1 = deck.dealOne();
int total2 = total;
total = total + c1.BJvalue();
if(c1.BJvalue() == 1){
System.out.println();
System.out.print(c1.face() + " of " + c1.suit());
System.out.println();
System.out.println();
System.out.print("Would you like your ace to be (11) or (1) -> ");
ace = kb.nextInt();
while(ace != 1 && ace != 11){
System.out.print("Has to be either (11) or (1) -> ");
ace = kb.nextInt();}
total = total2 + ace;}
if(code == 4){
while(total != 21){
c1 = deck.dealOne();
total = cheat + c1.BJvalue();}}
Delay.wait(100);
System.out.println();
System.out.println(c1.face() + " of " + c1.suit() + " (" + total + ")");
System.out.println();
if(total < 21)
again = again("Hit?");
if(total > 21){
System.out.println();
System.out.println("BUSTED");
System.out.println();
return total;}}
while(again && total < 21);
return total;
}
public static int comHit(int total, Deck deck , int user, int code)
{
int total2 = total;
if(user > 21)
return total;
System.out.println("Com's Turn");
while(total <= 17){
Card c1 = deck.dealOne();
if(code == 3){
while (c1.BJvalue() < 6){
c1 = deck.dealOne();}}
total = total + c1.BJvalue();
if(c1.BJvalue() == 1){
if(total2 <= 10){
total = total2 + 11;}}
Delay.wait(200);
System.out.println();
System.out.println(c1.face() + " of " + c1.suit() + " (" + total + ")");}
while(user > total){
Card c1 = deck.dealOne();
total = total + c1.BJvalue();
Delay.wait(200);
System.out.println();
System.out.println(c1.face() + " of " + c1.suit() + " (" + total + ")");}
if(total > 21){
System.out.println();
System.out.println("BUSTED");
System.out.println();
return total;}
return total;
}
public static int whoWon(int total, int comtotal)
{
if (total == comtotal)
return 2;
if (total > 21)
return 0;
if (comtotal > 21)
return 1;
if (total <= 21 && comtotal <= 21){
if(total > comtotal)
return 1;
else
return 0;}
return 3;
}
public static int winnings(int winner, int bet, int money, int multiplier, int code)
{
if(code == 2)
money = 999999999;
Delay.wait(200);
if(winner == 1){
System.out.println("You Won " + (bet * 2) * multiplier + " Dollars");
System.out.println();
Delay.wait(100);
System.out.println("You Now Have " + (money + bet) * multiplier + " Dollars");
System.out.println();
return (money + bet) * multiplier;}
else if(winner == 2){
System.out.println();
System.out.println("Push");
System.out.println();
return money;}
else{
System.out.println();
System.out.println("You Lost " + bet + " Dollars");
System.out.println();
System.out.println("You Now Have " + (money - bet) + " Dollars");
System.out.println();
return money - bet;}
}
public static boolean again(String msg)
{
boolean local;
Scanner kb = new Scanner(System.in);
System.out.print(msg + " (y)es (n)o -> ");
char again = kb.next().charAt(0);
while (again != 'n' && again != 'y'){
System.out.print(msg + " (y)es (n)o -> ");
again = kb.next().charAt(0);}
if (again == 'n')
local = false;
else local = true;
return local;
}
public static void bye()
{
System.out.println("You are out of money, come back later");
}
}