Created
February 15, 2018 22:59
-
-
Save abeforgit/2fa5636e4f99d6170fd6e893154efd17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
height = int(input(">")) | |
width = int(input(">")) | |
class Ball(): | |
def __init__(self, field): | |
self.x = 0 | |
self.y = 0 | |
self.cur_vect = [1, 1] | |
self.field = field | |
def move(self): | |
self.x += self.cur_vect[0] | |
self.y += self.cur_vect[1] | |
def is_in_hole(self): | |
hole = '' | |
if self.x == 0 and self.y == 0: | |
hole = 'linkeronderpocket' | |
elif self.x == self.field.width and self.y == 0: | |
hole = 'rechteronderpocket' | |
elif self.x == 0 and self.y == self.field.height: | |
hole = 'linkerbovenpocket' | |
elif self.x == self.field.width and self.y == self.field.height: | |
hole = 'rechterbovenpocket' | |
return hole | |
def is_at_wall(self): | |
wall = '' | |
if self.x == 0: | |
wall = 'linkerband' | |
elif self.x == self.field.width: | |
wall = 'rechterband' | |
elif self.y == 0: | |
wall = 'onderband' | |
elif self.y == self.field.height: | |
wall = 'bovenband' | |
return wall | |
def flip(self, wall): | |
if wall == 'linkerband' or wall == 'rechterband': | |
self.cur_vect[0] *= -1 | |
elif wall == 'bovenband' or wall == 'onderband': | |
self.cur_vect[1] *= -1 | |
class Field(): | |
def __init__(self, height, width): | |
self.height = height | |
self.width = width | |
my_field = Field(height, width) | |
my_ball = Ball(my_field) | |
my_ball.move() | |
hole = my_ball.is_in_hole() | |
while True: | |
my_ball.move() | |
wall = my_ball.is_at_wall() | |
hole = my_ball.is_in_hole() | |
if hole: | |
print(f"{hole} ({my_ball.x}, {my_ball.y})") | |
break | |
if wall: | |
print(f"{wall} ({my_ball.x}, {my_ball.y})") | |
my_ball.flip(wall) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment