def on_key_release(symbol, modifiers): global realm, realm_index if symbol == key.C: if selected_province: if can_create_army(realm, selected_province, 1): selected_province.action = CreateArmy(world, realm, selected_province, 1) elif selected_army: if can_create_province(realm, selected_army): selected_army.action = CreateProvince(realm, selected_army) elif symbol == key.I: if selected_army: if can_increase_army(realm, selected_army): selected_army.action = IncreaseArmy(realm, selected_army) elif symbol == key.SPACE: realm_index += 1 realm = world.get_realm(realm_index) if not realm: realm_index = 0 realm = world.get_realm(realm_index) result = world.tick() view.create_batch() print('Turn={0:03d}'.format(world.turn)) for battle in result.battles: print('Battle: Province={0:d},{1:d} {2:s} vs {3:s}'.format(battle.province.x, battle.province.y, battle.army0.realm.name, battle.army1.realm.name)) print('Realm={0:s}:'.format(realm.name)) else: print('Realm={0:s}:'.format(realm.name))
def test_can_create_province(self): realm = Realm() army = Army(0, realm) province = Province(None, 0, 0) province.add_army(army) self.assertTrue(can_create_province(realm, army))
def test_same_realm(self): realm = Realm() army = Army(0, realm) province = Province(None, 0, 0) province.add_army(army) realm.add_province(province) self.assertFalse(can_create_province(realm, army))
def test_wrong_realm(self): realm0 = Realm() realm1 = Realm() army = Army(0, realm0) province = Province(None, 1, 1) province.add_army(army) self.assertFalse(can_create_province(realm1, army))
def test_other_realm(self): realm0 = Realm() realm1 = Realm() army = Army(0, realm0) province = Province(None, 0, 0) province.add_army(army) realm1.add_province(province) self.assertFalse(can_create_province(realm0, army))