# target.py # Justin Ryder # 10-22-09 # from graphics import * from random import randint def main(): z = 0 while (z == 0): d = raw_input("Enter e for easy, h for hard, or q to quit: ") if (d == "e"): win = GraphWin() p = Point(99,99) white = Circle(p, 75) black = Circle(p, 60) blue = Circle(p, 45) red = Circle(p, 30) yellow = Circle(p, 15) white.setFill('white') black.setFill('black') blue.setFill('blue') red.setFill('red') yellow.setFill('yellow') white.setOutline('white') black.setOutline('black') blue.setOutline('blue') red.setOutline('red') yellow.setOutline('yellow') white.draw(win) black.draw(win) blue.draw(win) red.draw(win) yellow.draw(win) Text(Point(75,10), "You have five tries to win!").draw(win) for i in range(5): s = win.getMouse() addsub = randint(1,2) x = randint(0,5) y = randint(0,5) if (addsub == 1): sx = s.getX() + x yx = s.getY() + y if (addsub == 2): sx = s.getX() - x yx = s.getY() - y point = Point(sx,yx) shot = Circle(point, 3) shot.setFill('green') shot.draw(win) Text(Point(99,99), "You win!").draw(win) win.getMouse() win.close() if (d == "h"): win = GraphWin() p = Point(99,99) white = Circle(p, 75) black = Circle(p, 60) blue = Circle(p, 45) red = Circle(p, 30) yellow = Circle(p, 15) white.setFill('white') black.setFill('black') blue.setFill('blue') red.setFill('red') yellow.setFill('yellow') white.setOutline('white') black.setOutline('black') blue.setOutline('blue') red.setOutline('red') yellow.setOutline('yellow') white.draw(win) black.draw(win) blue.draw(win) red.draw(win) yellow.draw(win) Text(Point(75,10), "You have five tries to win!").draw(win) for i in range(5): s = win.getMouse() x = randint(50,150) y = randint(50,150) point = Point(x,y) shot = Circle(point, 3) shot.setFill('green') shot.draw(win) Text(Point(99,99), "You lose!").draw(win) win.getMouse() win.close() if (d == "q"): z = 1 else: main() main()