Question: Can figure out how get my program to keep track of a total score, here is my code so far in python 3.6.6 import math
Can figure out how get my program to keep track of a total score, here is my code so far in python 3.6.6
import math import random import turtle
def target(): """Turtle drawing the target""" t = turtle.Turtle() wn = turtle.Screen() wn.bgcolor("black") t.hideturtle() t.speed(0) #most outside circle worth 10 points t.setposition(0,-275) t.color("grey") t.begin_fill() t.circle(275) t.end_fill() #2nd most outter circle worth 20 points t.penup() t.setposition(0,-200) t.pendown() t.color("red") t.begin_fill() t.circle(200) t.end_fill() #3rd most outter circle worth 30 points t.penup() t.setposition(0,-125) t.pendown() t.color("orange") t.begin_fill() t.circle(125) t.end_fill() #center circle worth 50 points t.penup() t.setposition(0,-50) t.pendown() t.color("blue") t.begin_fill() t.circle(50) t.end_fill() t.showturtle() def drawCross(pen, color, size, x, y): pen.pensize(3) pen.color(color) pen.penup() pen.goto(x-size,y-size) pen.pendown() pen.goto(x+size,y+size) pen.penup() pen.goto(x-size,y+size) pen.pendown() pen.goto(x+size,y-size)
def calculateScore(arrowx,arrowy): score = 0 totalScore = 0 totalScore = totalScore + score distance = 0 distance = math.sqrt((arrowx ** 2) + (arrowy ** 2))
if (distance <= 50): score = 50 print(f" Great shot! You just scored {score} points!")
elif (distance > 50 and distance <= 125): score = 30 print(f" Great shot! You just scored {score} points!") elif (distance > 125 and distance <= 200): score = 20 print(f" Great shot! You just scored {score} points!") elif (distance > 200 and distance <= 275): score = 10 print(f" Great shot! You just scored {score} points!") elif (distance > 275): score = 0 print(f" Too bad, you missed the target and you scored {score} points :(") return totalScore
def main(): """Starts the archery game. Lets user choose how many arrows they want to fire at the target""" user = str(input("Please enter name: ")) print(f" Hello, {user}! Welcome to the wonderful game of Archery!") choice = "" while(choice != "q"): #Menu options print(" Please choose an option:") print(" 1. Fire one arrow") print(" 2. Fire many arrows") print(" 3. Reset the target") print(" q. Quit") choice = input(f" ") #for firing one arrow if(choice == "1"): target() myPen = turtle.Turtle() myPen.speed(0) myPen.shape("arrow") #Shooting the arrow arrowx= random.randint(-300,300) arrowy= random.randint(-300,300) drawCross(myPen,"cyan",10,arrowx,arrowy) calculateScore(arrowx,arrowy) myPen.hideturtle() myPen.getscreen().update() elif(choice == "2"): manyArrows = int(input(" How many arrows would you like to fire? ")) target() myPen = turtle.Turtle() myPen.speed(0) myPen.shape("arrow") for x in range(manyArrows): arrowx= random.randint(-300,300) arrowy= random.randint(-300,300) drawCross(myPen, "cyan", 10, arrowx, arrowy) calculateScore(arrowx,arrowy)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
