This is due within a few hours, and I am unable to spot what is causing the program to not work.
Any suggestions?

["""Bounce - is a game that has a ball which increases in speed when you click
on the ball. That click signals the ball to speed up, records the click as a
win for the player. Once the player has reached the maximum speed, they have
the choice to restart or finish. The ball will never leave the screen but it
has a random pattern so when you lose and start over; one can not tell where
the ball will begin at."""
import time
import random
from math import *
from graphics import *
win = GraphWin("Bounce", 500, 500)
win.setCoords(0.0, 0.0, 500, 500)
from graphics import *
import random

class Bounce(object):#class

def __init__ (self, circle):#construtor
self.circle = circle
self.wins = 0
self.speed = 2

def ball(self):
#Ball, creates the ball for the game- has its shape, path and speed
#create windown
#draw ball, red ball, starts near upper window? or random
#Print game title near top
#self.circle = Circle(Point (random.randint(0,400), random.randint(0,400)), 25)#may change
#to smaller for challenge, or adjustable size
self.circle.setFill("red")
self.circle.draw(win)
#needs move function
for i in range(100):
self.circle.move(random.randint(-100,150),random.randint(-100,175))#the move needs
#to be inside the window, make sure the numbers are different
#the move moves in one direction!
# if self.circle.getCenter().getX() > 500:
# self.circle.move(200,0)
#elif self.circle.getCenter().getY() < 500:
# self.circle.move(0,200)
# elif self.circle.getCenter().getX() < 0:
# self.circle.move(200,0)
#elif self.circle.getCenter().getY() > 0:
# self.circle.move(0, 200)
time.sleep(self.speed)# go back over the sides after everything else
#the speed is going to be added to over time after certain event
#can I get it to move in other directions
#goes off screen, due to random; but since its random I can't predict it coming back on
#use if statements to keep on screen.

def isclicked(self):
#allows the user to click the ball and increase the speed due to click.
p = win.getMouse()
X1 = self.circle.getCenter().getX()
Y1 = self.circle.getCenter().getY()
X2 = p.getX()
Y2 = p.getY()
D = sqrt(((X2-X1)**2)+((Y2-Y1)**2))#distance formula from center to click
r = self.circle.getRadius()
if D <= r:
print D

def Wins(self):
#wins, records the amount of wins one gets whenever the ball is clicked.
self.wins = self.wins + 1
self.speed = self.speed *.01
winner = str(self.wins) + str(self.speed) + "Winner"
return winner


def main():
b = Bounce(Circle(Point (random.randint(0,400),random.randint(0,400)), 25))
b.isclicked()
b.Wins()

main()


]

Recommended Answers

All 3 Replies

import time
import random
from math import *
from graphics import *
win = GraphWin("Bounce", 500, 500)
win.setCoords(0.0, 0.0, 500, 500)
from graphics import *
import random

class Bounce(object):#class

def __init__ (self, circle):#construtor
self.circle = circle
self.wins = 0
self.speed = 2

def ball(self):
#Ball, creates the ball for the game- has its shape, path and speed
#create windown
#draw ball, red ball, starts near upper window? or random
#Print game title near top
#self.circle = Circle(Point (random.randint(0,400), random.randint(0,400)), 25)#may change
#to smaller for challenge, or adjustable size
self.circle.setFill("red")
self.circle.draw(win)
#needs move function
for i in range(100):
self.circle.move(random.randint(-100,150),random.randint(-100,175))#the move needs
#to be inside the window, make sure the numbers are different
#the move moves in one direction!
# if self.circle.getCenter().getX() > 500:
# self.circle.move(200,0)
#elif self.circle.getCenter().getY() < 500:
# self.circle.move(0,200)
# elif self.circle.getCenter().getX() < 0:
# self.circle.move(200,0)
#elif self.circle.getCenter().getY() > 0:
# self.circle.move(0, 200)
time.sleep(self.speed)# go back over the sides after everything else
#the speed is going to be added to over time after certain event
#can I get it to move in other directions
#goes off screen, due to random; but since its random I can't predict it coming back on
#use if statements to keep on screen.

def isclicked(self):
#allows the user to click the ball and increase the speed due to click.
p = win.getMouse()
X1 = self.circle.getCenter().getX()
Y1 = self.circle.getCenter().getY()
X2 = p.getX()
Y2 = p.getY()
D = sqrt(((X2-X1)**2)+((Y2-Y1)**2))#distance formula from center to click
r = self.circle.getRadius()
if D <= r:
print D

def Wins(self):
#wins, records the amount of wins one gets whenever the ball is clicked.
self.wins = self.wins + 1
self.speed = self.speed *.01
winner = str(self.wins) + str(self.speed) + "Winner"
return winner


def main():
b = Bounce(Circle(Point (random.randint(0,400),random.randint(0,400)), 25))
b.isclicked()
b.Wins()

main()

double

Maybe because you did not write all this code adviced in comments of teacher?
#create windown
etc.
even they look almost ready code from teacher, you only uncomment them and finalize them.

When you have done what is requested in these comments, you can test your code and if you have specific difficulty of some last functionality. You can give exact details of what you tried to do and what response the program gave (copy and paste from IDLE, for example, take out most stupid mistakes and post it by clicking firs the quote symbol here in editing window for message). For code, you click first the code tag [code].

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.