示例#1
0
文件: archer.py 项目: tnajdek/archers
    def test_player_kills_player(self):
        attacker_spawn = self.world.get_object_by_name('spawn2')
        defender_spawn = self.world.get_object_by_name('spawn3')
        attacker = Archer(self.world, name="attacker", reactor=self.clock)
        defender = Archer(self.world, name="defender", reactor=self.clock)
        attacker.spawn(attacker_spawn)
        defender.spawn(defender_spawn)

        attacker.want_attack(directions['south'])
        self.advance_clock(1)
        self.assertEqual(attacker.state, "shooting")
        self.assertEqual(defender.state, "standing")
        self.advance_clock(50)
        self.assertEqual(attacker.state, "standing")
        self.assertEqual(defender.state, "dying")
        self.advance_clock(250)
        self.assertEqual(defender.state, "dead")
示例#2
0
文件: archer.py 项目: tnajdek/archers
 def setUp(self):
     super(TestPlayer, self).setUp()
     path = os.path.dirname(os.path.os.path.realpath(__file__))
     path = os.path.join(path, 'assets/test1.tmx')
     self.world = World(path)
     self.spawn_point = self.world.get_spawn_points()[0]
     self.world_update_task = task.LoopingCall(self.world.processing_step)
     self.world_update_task.clock = self.clock
     self.world_update_task.start(1.0 / 30)
     self.player = Archer(self.world, reactor=self.clock)
     self.player.spawn(self.spawn_point)
示例#3
0
	def test_get_update(self):
		""" Test raw execution performance of the 'get_update'"""
		self.connection = Connection(self.world, self.cache)
		archers = list()
		for i in range(50):
			archer = Archer(self.world, reactor=self.clock)
			archer.spawn(self.spawn_point)
			archer.want_move(directions['south'])
			archers.append(archer)
		self.pr.enable()
		for i in range(100):
			self.connection.get_update()
		self.pr.disable()
		print self.process_stats('test_get_update.txt')
示例#4
0
    def test_get_update(self):
        self.connection.on('update', self.callback)
        self.clock.advance(1)
        items_expected = self.get_items_expected('get_update_message')
        update = self.get_last_callback_arguments()
        self.assertEqual(len(update), len(items_expected))
        for message in update:
            self.assertIsInstance(message, UpdateMessage)
            matching_expected_item = items_expected.pop(message['id'])
            self.assertEqual(message['id'], matching_expected_item.id)
            # self.assertEqual(message['center'], False)
            #TEST MORE
        self.assertEqual(len(items_expected), 0)

        self.clock.advance(1)
        update = self.get_last_callback_arguments()

        self.assertIsNone(update)
        self.archer = Archer(self.world, reactor=self.clock)
        self.archer.spawn(self.spawn_point)
        self.clock.advance(1)
        update = self.get_last_callback_arguments()
        self.assertEqual(len(update), 1)
示例#5
0
    def __init__(self, world, cache):
        super(Connection, self).__init__()
        self.session_id = uuid.UUID(bytes=urandom(16))
        self.world = world
        self.cache = cache
        self.known = dict()
        self.last_world_index = 0
        self.last_frame_index = 0
        self.archer = Archer(self.world, player=self)

        self.meta = {
            "id": self.archer.id,
            "username": "******",
            "gender": "male",
            "slots": {},
            "kills": 0,
            "deaths": 0,
            "score": 0,
            "budget": settings.initial_budget,
            "attributes": self.archer.attributes
        }

        self.archer.interface = self

        logging.info("New connection %s" % self.session_id)

        self.world.on('destroy_object', self.on_destroy)
        self.world.on('step', self.on_step)
        self.on('useraction', self.on_user_action)
        self.on('disconnect', self.on_disconnect)
        self.on('usermsg', self.on_user_message)
        self.on('kill', self.on_kill)
        self.on('die', self.on_die)
        self.on('mob', self.on_mob)
        self.on('pickup', self.on_pickup)
        self.on('spawn', self.on_spawn)
示例#6
0
    def test_get_frame(self):
        self.archer = Archer(self.world, reactor=self.clock)
        self.archer.spawn(self.spawn_point)
        self.connection.on('frame', self.callback)
        self.clock.advance(1)
        frame = self.get_last_callback_arguments()
        items_expected = self.get_items_expected('get_frame_message')
        self.assertEqual(len(frame), len(items_expected))

        for message in frame:
            matching_expected_item = items_expected.pop(message['id'])
            self.assertEqual(
                message['x'],
                int(settings.PPM * matching_expected_item.get_position()['x']))
            self.assertEqual(
                message['y'],
                int(settings.PPM * matching_expected_item.get_position()['y']))
            self.assertEqual(message['direction'],
                             matching_expected_item.get_direction())

        self.assertEqual(len(items_expected), 0)

        self.clock.advance(1)
        frame = self.get_last_callback_arguments()
        # Nothing has changed!
        self.assertEqual(len(frame), 0)
        self.archer.want_move(directions['south'])
        self.advance_clock(1)
        frame = self.get_last_callback_arguments()
        self.assertEqual(len(frame), 1)
        message = frame.pop()
        self.assertEqual(message['x'],
                         int(settings.PPM * self.archer.get_position()['x']))
        self.assertEqual(message['y'],
                         int(settings.PPM * self.archer.get_position()['y']))
        self.assertEqual(message['direction'], self.archer.get_direction())
示例#7
0
def spawn_archer():
    global archer
    world = archers.world
    spawn_point = world.get_spawn_points()[0]
    archer = Archer(world)
    archer.spawn(spawn_point)
示例#8
0
def spawn_sucker():
    world = archers.world
    spawn_point = world.get_spawn_points()[2]
    sucker = Archer(world)
    sucker.spawn(spawn_point)