Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change the following code so thatinstead of having a square for the aiand players boxers animation have itbe an actual character that is a boxerThe

Change the following code so thatinstead of having a square for the aiand players boxers animation have itbe an actual character that is a boxerThe code is in python:import turtleimport random# Set up the screenscreen = turtle.Screen()screen.title("Boxing Game")screen.bgcolor("white")# Playerplayer = turtle.Turtle()player.speed(0)player.shape("square")player.color("blue")player.shapesize(stretch_wid=2, stretch_len=2)player.penup()player.goto(-200,0)# AIai = turtle.Turtle()ai.speed(0)ai.shape("square")ai.color("red")ai.shapesize(stretch_wid=2, stretch_len=2)ai.penup()ai.goto(200,0)# Heartsplayer_hearts =3ai_hearts =3# Function to update heartsdef update_hearts(): turtle.clear() turtle.hideturtle() turtle.penup() turtle.goto(0,200) turtle.color("black") turtle.write(f"Player Hearts: {player_hearts} AI Hearts: {ai_hearts}", align="center", font=("Courier",16, "normal"))# Function to handle player's movedef player_move(): move = input("Choose your move (dodge left, dodge right, block, punch): ").lower() return move# Function to handle AI's movedef ai_move(): moves =["dodge left", "dodge right", "block", "punch"] return random.choice(moves)# Function to handle punch animationdef punch_animation(turtle_obj, direction): turtle_obj.shape("circle") turtle_obj.color("black") turtle_obj.shapesize(stretch_wid=0.5, stretch_len=2) turtle_obj.setheading(direction) turtle_obj.stamp() turtle_obj.color("blue" if turtle_obj == player else "red") # Explicitly set color turtle_obj.shapesize(stretch_wid=2, stretch_len=2)# Main game loopwhile player_hearts >0 and ai_hearts >0: player_choice = player_move() ai_choice = ai_move() if player_choice == ai_choice: print("It's a draw!") elif ((player_choice == "dodge left" and ai_choice == "punch") or (player_choice == "dodge right" and ai_choice == "punch")): print("You dodged the punch! Free counter punch!") punch_animation(ai,0) ai_hearts -=1 elif ((ai_choice == "dodge left" and player_choice == "punch") or (ai_choice == "dodge right" and player_choice == "punch")): print("AI dodged the punch! AI gets a free counter punch!") punch_animation(player,180) player_hearts -=1 elif (player_choice == "punch" and ai_choice == "block") or ( ai_choice == "punch" and player_choice == "block" ): print("Punch blocked!") elif player_choice == "punch": punch_animation(player,0) ai_hearts -=1 elif ai_choice == "punch": punch_animation(ai,180) player_hearts -=1 update_hearts()# Display the winnerturtle.clear()turtle.hideturtle()turtle.penup()turtle.goto(0,0)turtle.color("black")turtle.write( f"{'You win!' if player_hearts >0 else 'AI wins!'}", align="center", font=("Courier",24, "normal"),)turtle.done()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

Explain how driver tracing works. LO5

Answered: 1 week ago