示例#1
0
    def __init__(self, **kwargs):
        # rip out the game settings we want
        players = kwargs.pop('players')
        gamestate = kwargs.pop('gamestate')
        self.game = PlanetWars(gamestate)
        for p in players:
            self.game.add_player(p)
        self.max_tick = kwargs.pop('max_game_length')
        self.max_tick += self.max_tick / 2

        # set and use pyglet window settings
        kwargs.update({
            'width': 500,
            'height': 500,
            'vsync': True,
            'resizable': False,
        })
        super(PlanetWarsWindow, self).__init__(**kwargs)
        # create a pyglet window and set glOptions
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glClearColor(0., 0., 0., 1.0)  # Grey

        # current "pen" colour of lines
        self.pen_color = (1, 0, 0, 1.)
        self.stroke = 1.0  # - thickness default
        self.qobj = gluNewQuadric()
        # gluQuadricDrawStyle(self.qobj, GLU_FILL) #GLU_SILHOUETTE)

        # prep the fps display and some labels
        self.fps_display = clock.ClockDisplay()
        clWhite = (255, 255, 255, 255)
        self.step_label = Label('STEP', x=5, y=self.height - 20, color=clWhite)
        self.fps = 0
        self.set_fps(20)
        self.paused = True
        self.view_id = 0
        self.label_type = 'num_ships'

        # create adaptor to help with drawing
        self.adaptor = PlanetWarsScreenAdapter(self.game, self.circle)

        # prep the game (space!)
        self.reset_space()
        # add extra event handlers we need
        self.add_handlers()
示例#2
0

# You don't need to change this function
def do_turn(state):
    behavior_tree.execute(planet_wars)


if __name__ == '__main__':
    logging.basicConfig(filename=__file__[:-3] + '.log',
                        filemode='w',
                        level=logging.DEBUG)

    behavior_tree = setup_behavior_tree()
    try:
        map_data = ''
        while True:
            current_line = input()
            if len(current_line) >= 2 and current_line.startswith("go"):
                planet_wars = PlanetWars(map_data)
                do_turn(planet_wars)
                finish_turn()
                map_data = ''
            else:
                map_data += current_line + '\n'

    except KeyboardInterrupt:
        print('ctrl-c, leaving ...')
    except Exception:
        traceback.print_exc(file=sys.stdout)
        logging.exception("Error in bot.")
示例#3
0
 def setUp(self):
     self.pw = PlanetWars()