Untitled Documenta
Untitled Documenta
writer.forward(35)
writer.right(90)
writer.backward(y)
y = y - 50
wn.update()
# Does the stuff for actual decision for ace
if pick == "A":
Ace()
'''def dealer_ai():
dealer_total = sum(dealer_score)
if dealer_total < 17:
dealer_new_card()
dealer_total = sum(dealer_score)'''
# Lets the dealer choose whether to take again or stop
def dealer_ai():
dealer_total = sum(dealer_score)
for num in range(1):
if dealer_total < 17:
# Gives the dealer a new card
dealer_new_card()
dealer_total = sum(dealer_score)
return dealer_total
def hit_or_stand2():
# I dont even think this function does anything fr
global get_card
if get_card == "hit" and total < 21:
hit_or_stand(total)
def end_game(total, score):
# Builds the end screen
writer.pencolor("black")
writer.fillcolor("black")
writer.speed(1)
writer.goto(-400,400)
writer.begin_fill()
writer.pendown()
writer.goto(400, 400)
writer.goto(400, -400)
writer.goto(-400, -400)
writer.end_fill()
# sets up for writing end
writer.pencolor("khaki")
global dealer_score
total = sum(score)
'''if total == 21 and dealer_total > 21 or total == 21 and dealer_total < 21:
writer.write("BlackJack!", font=("Arial", 75, "bold"))
writer.left(80)
writer.backward(75)
writer.right(80)'''
Final_total = sum(score)
dealer_final_total = sum(dealer_score)
writer.pencolor("khaki")
writer.right(60)
writer.goto(-400, 0)
# Puts its total on board
writer.write("Dealer Final Total:", dealer_final_total, font=("Arial", 75, "bold"))
writer.left(160)
writer.forward(30)
writer.write(dealer_final_total, font=("Arial", 65, "bold"))
writer.goto(-400, 0)
# Writes if there was a blackjack
if total == 21 and dealer_total > 21 or total == 21 and dealer_total < 21:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.pencolor("white")
writer.write("BlackJack!", font=("Arial", 75, "bold"))
writer.pencolor("khaki")
# Writes if there was a dealer bust
if dealer_total > 21 and Final_total < 22:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("Dealer busted", font=("Arial", 65, "bold"))
# Writes if there was a dealer blackjack
if dealer_final_total == 21 and Final_total < 21:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("Dealer Blackjack", font=("Arial", 65, "bold"))
# Writes if there you won
if dealer_final_total < Final_total and Final_total < 22:
writer.goto(-100, -200)
writer.write("You Win",font=("Arial", 65, "bold"))
# Writes if you busted
if Final_total > 21 and dealer_final_total > 22:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("You Busted", font=("Arial", 65, "bold"))
# Writes if you both busted
if Final_total > 21 and dealer_final_total > 21:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("Both busted, no winner", font=("Arial", 65, "bold"))
# Writes if the Dealer won
if dealer_final_total > Final_total and dealer_final_total < 22:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("Dealer Won", font=("Arial", 65, "bold"))
# Writes if the dealer busted, but you won
if dealer_final_total > 21 and Final_total < 22:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("Dealer busted, you win", font=("Arial", 65, "bold"))
# Writes if you busted, but the dealer won
if dealer_final_total < 22 and Final_total > 21:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("You busted, dealer wins", font=("Arial", 65, "bold"))
# Writes if there was a tie
if dealer_final_total == 21 and Final_total == 21:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("Tie", font=("Arial", 65, "bold"))
# Writes if there was a tie
if dealer_final_total == Final_total and Final_total < 21:
writer.left(80)
writer.backward(75)
writer.right(80)
writer.write("Tie", font=("Arial", 65, "bold"))
# The function for actually writing the Card
def write_card():
global pick
global score
global total
# sets total
total = sum(score)
writer.write(pick, font=("Arial", 50, "bold"))
# The Function for actually writing the total
def write_total():
global pick
global score
global total
# sets total
total = sum(score)
writer.left(90)
writer.forward(75)
# Writes total
writer.write("Total:", font=("Arial", 50, "bold"))
writer.forward(150)
writer.write(total, font=("Arial", 50, "bold"))
writer.backward(225)
writer.right(90)
# goes back to original spot
# Writes dealers code
def dealer_write_card():
global pick
dealer_writer.write(pick, font=("Arial", 50, "bold"))
# Im not sure if this is gonna be in the code yet
def new_game():
restart.pendown()
restart.goto(0,-100)
restart.pensize(45)
restart.forward(30)
# Writes hit or stand
def written_hit():
hit.goto(-100, -300)
hit.write("Hit or Stand? (Type)", font=("Arial", 50, "bold"))
# Game Function ----------------------------
# Gives you your hidden and new card
written_hit()
hidden_card()
new_card()
# Counts your first totals
total = sum(score)
print("Total:", total)
# Gives dealer hidden and new cards
dealer_hidden_card()
dealer_new_card()
global dealer_total
# sets dealers total
dealer_total = sum(dealer_score)
global get_card
# Fixing alternating dealer and your card picks
# Sets values to be used in the hit_or_stand function
if total < 21:
get_card = "hit"
else:
get_card = "stand"
# uses the dealer AI to choose what it does
while dealer_total < 17 and get_card != "stand" and total < 21:
hit_or_stand(total)
# Utilizes dealer ai
dealer_ai()
# Takes dealers total
dealer_total = sum(dealer_score)
total = sum(score)
if total > 21:
# leaves loop if the total goes above 21
break
# makes dealer continue taking more cards until it gets 17+
while dealer_total < 17:
dealer_ai()
# Takes dealers total
dealer_total = sum(dealer_score)
# Lets you take more cards
while total < 21 and get_card != "stand":
hit_or_stand(total)
# Gets total
total = sum(score)
# Done with that
# gets totals one more time for dealer
dealer_final_total = sum(dealer_score)
# gives results
end_game(total, score)
new_game()
wn.mainloop()