Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python 3.5.2. and IDLE Design a computer game in which a player finds a tr

ID: 3812183 • Letter: U

Question

Using Python 3.5.2. and IDLE Design a computer game in which a player finds a treasure. Using Turtle graphics, create a "treasure square" with a corner at a random (x, y) location on the screen. Set the player's starting position at another random (x, y) location on the screen. Let the player specify whether they want to move forward, backward, turn  left or right, and by what distance or angle, in their quest to find the treasure. Let the player continue moving until the treasure is found (the player's turtle intersects the boundary of the treasure). When the treasure is found, produce a message or special effect indicating success.

Explanation / Answer

from turtle import *
import random

title("Treasure hunt") #title of the game

setup(555,555) #sets the screensize into 555x555 px

bgcolor("yellow") #background color

#pressed key functions
def up():
penup()
pendown()
head(70)


def right():
penup()
pendown()
head(0)

def left():
penup()
pendown()
head(160)

def down():
penup()
pendown()
head(250)


#draw Treasure
def dotx():
pen2.penup()
pen2.goto(x1,y1)
pen2.pendown()
pen2.dot(16,"green")

#player
def hero(x):
for i in range(999999):
for ii in range(16):
seth(x)
fd(2)
if xcor()>=250.0 or ycor()>=250.0 or xcor()<=-250.0 or ycor()<=-250.0:
clear()
pen2.clear()
pen4.write("GAME OVER")
break
elif (xcor() in x2) and (ycor() in y2):
pen2.clear()
pen4.write("CAUGHT",False,'center',font=('Arial',15,'normal'))
if xcor()>=250.0 or ycor()>=250.0 or xcor()<=-250.0 or ycor()<=-250.0:
clear()
pen2.clear()
pen4.write("GAME OVER")
break
clear()


color("white")
pensize(5) #pensize

shape('turtle')

#hideturtle()


delay(2) #delay of animation
speed(10) #speed of animation

pen2=Pen() #dots
pen2.hideturtle()

pen4=Pen()
pen4.hideturtle()
pen4.color("white")

#border
pen3=Pen()
pen3.color("red")
pen3.pensize(3)
pen3.hideturtle()
pen3.speed(10)
pen3.penup()
pen3.goto(-250,-250)
pen3.pendown()
for p3 in range(4):
pen3.fd(500)
pen3.left(90)


#dots coordinates

x1=random.randint(-225,225)
y1=random.randint(-225,225)
x2=list(range(x1-6,x1+6))
y2=list(range(y1-6,y1+6))


dotx() #call dots


#controls
onkey(up,"Up")
onkey(right,"Right")
onkey(left,"Left")
onkey(down,"Down")
listen()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote