def setup(): """Sets up the game for playing and initialises objects """ pygame.init() clock = pygame.time.Clock() display = pygame.display screen = display.set_mode((BOARD_WIDTH, BOARD_HEIGHT)) player = Paddle(player_color) ball_one = Ball((4, 3), DIFFICULTY) ball_two = Ball((3, 2), DIFFICULTY) board = Board(screen=screen, player=player, balls=[ball_one, ball_two]) return board, clock, display
def __init__(self, agent, end_score=10): self.agent = agent self.score1 = 0 self.score2 = 0 self.end_score = end_score pygame.init() self.screen = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT]) pygame.display.set_caption('Pong') pygame.mouse.set_visible(1) self.font = pygame.font.Font(None, 36) self.background = pygame.Surface(self.screen.get_size()) self.ball = Ball(WHITE) self.balls = pygame.sprite.Group() self.balls.add(self.ball) self.player_bottom = Player(580, PLAYER_WIDTH, WHITE) self.player_top = Player(25, PLAYER_WIDTH, WHITE) self.movingsprites = pygame.sprite.Group() self.movingsprites.add(self.player_bottom) self.movingsprites.add(self.player_top) self.movingsprites.add(self.ball) self.clock = pygame.time.Clock()
def __init__(self, initial_delay, interval, application): self.ip = my_ip() self.api_version = 'v1' self.next_ball = Ball() self.view = [] self.fanout = int(os.environ['FANOUT']) self.ttl = int(os.environ['TTL']) self.stability_oracle = StabilityOracle(self.ttl) self.ordering = EpTOOrdering(self.stability_oracle, application) self.schedule_repeated_task(initial_delay, interval)
def repeated_task(self): logger.debug('This repeated_task is started.', next_ball=self.next_ball) if not self.next_ball.is_empty(): self.next_ball.increase_events_ttl() logger.debug('I increased the ttl of events in self.next_ball.') self.view = self.get_k_view(self.fanout) logger.info('I got a k-view from cyclon: ' + str(self.view)) for destination in self.view: response = self.send_next_ball(destination) logger.info('I sent next ball to ' + destination + ' and I got ' + str(response)) self.ordering.order(self.next_ball.copy()) self.next_ball = Ball() logger.debug("I reset next_ball.", next_ball=self.next_ball)
def setUp(self): self.ball = Ball()
def generate_empty_ball(cls): return Ball()