#!/usr/bin/env python #bounce.py from graphics import* from time import sleep from random import randint #class Microbe: #def __init__(self, win, size): # self.win = win # cx, cy = randint(50, 150), randint(50, 150) # node = Circle(Point(cx, cy), size) # node.draw(win) #def xPlus(self, cx): # self.cx = self.cx + 1 # self.node.move(1, 0) # return self.cx #def xMin(self): # self.cx = self.cx - 1 # self.node.move(-1, 0) #def yPlus(self): # self.cx = self.cx + 1 # self.node.move(0, 1) #def yMin(self): # self.cx = self.cx - 1 # self.node.move(0, -1) def c1MoveL(x, c, ball): if c == 1: ball.move(-1,0) x = x-1 return x def c1MoveR(x, c, ball): if c == 1: ball.move(1,0) x += 1 return x def c0MoveU(y, c, ball): if c == 0: ball.move(0,1) def main(): win = GraphWin("Arena", 300, 300) win.setCoords(0, 0, 200, 200) center = Point(300, 300) xA = randint(50, 150) xB = randint(50, 150) xC = randint(50, 150) xD = randint(50, 150) xE = randint(50, 150) yA = randint(50, 150) yB = randint(50, 150) yC = randint(50, 150) yD = randint(50, 150) yE = randint(50, 150) ball1 = Circle(Point(xA, yA), 2) ball2 = Circle(Point(xB, yB), 2) ball3 = Circle(Point(xC, yC), 2) ball4 = Circle(Point(xD, yD), 2) ball5 = Circle(Point(xE, yE), 2) ball1.draw(win) ball2.draw(win) ball3.draw(win) ball4.draw(win) ball5.draw(win) cx = 100 x = xA raw_input("") while x > 0: c = randint(0, 1) d = randint(0, 1) x = c1MoveL(x, c, ball1) if c == 1: #ball1.move(-1,0) ball5.move(-1,0) elif c == 0: ball2.move(0,-1) ball5.move(0,-1) if d == 1: ball3.move(0,1) else: ball4.move(0,-1) ball5.move(0, -1) sleep(0.005) while x < 200: c = randint(0, 1) x = c1MoveR(x, c, ball1) sleep(0.005) raw_input("Press to quit") win.close() if __name__ == '__main__': main() #!/usr/bin/env python