• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Entity类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中jalse.entities.Entity的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Entity类属于jalse.entities包,在下文中一共展示了Entity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: attributeAdded

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void attributeAdded(final AttributeEvent<Double> event) {
final Person person = ((Entity) event.getContainer()).asType(Person.class);
final double infection = event.getValue();

// Check infected
if (infection >= 1.0) {
    person.unmarkAsType(Carrier.class);
    infectPerson(person);
    return;
}

// Base colours
final Color healthyColour = ZombiesProperties.getColour(Healthy.class);
final Color infectedColour = ZombiesProperties.getColour(Infected.class);

// Gradually transition from "healthy" to "infected" color
final float r = (float) ((healthyColour.getRed() * (1. - infection) + infectedColour.getRed() * infection)
	/ 255.);
final float g = (float) ((healthyColour.getGreen() * (1. - infection) + infectedColour.getGreen() * infection)
	/ 255.);
final float b = (float) ((healthyColour.getBlue() * (1. - infection) + infectedColour.getBlue() * infection)
	/ 255.);

person.setColour(new Color(r, g, b));
   }
 
开发者ID:Ellzord,项目名称:JALSE-Zombies,代码行数:27,代码来源:InfectionListener.java


示例2: getClosestPersonOfType

import jalse.entities.Entity; //导入依赖的package包/类
private static Optional<Person> getClosestPersonOfType(final Person person, final Set<Person> people,
    final Class<? extends Entity> type) {
final Point personPos = person.getPosition();
final Integer sightRange = person.getSightRange();
// Stream other entities of type
return people.stream().filter(not(person)).filter(isMarkedAsType(type)).filter(p -> {
    final Point pPos = p.getPosition();
    // Within range
    return Math.abs(pPos.x - personPos.x) <= sightRange && Math.abs(pPos.y - personPos.y) <= sightRange;
}).collect(Collectors.minBy((a, b) -> {
    final Point aPos = a.getPosition();
    final Point bPos = b.getPosition();
    // Closest person
    final int d1 = (aPos.x - personPos.x) * (aPos.x - personPos.x)
	    + (aPos.y - personPos.y) * (aPos.y - personPos.y);
    final int d2 = (bPos.x - personPos.x) * (bPos.x - personPos.x)
	    + (bPos.y - personPos.y) * (bPos.y - personPos.y);
    return d1 - d2;
}));
   }
 
开发者ID:Ellzord,项目名称:JALSE-Zombies,代码行数:21,代码来源:MovePeople.java


示例3: perform

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void perform(final ActionContext<Entity> context) throws InterruptedException {
// Get floor
final Floor floor = context.getActor().asType(Floor.class);

// Get mop
final Mop mop = floor.getMop();

for (;;) {
    final Point movedPos = getPositionInDirection(mop);
    // Check in bounds
    if (inFloorBounds(floor, movedPos)) {
	// Randomly ping off when at an edge
	if (isAtFloorEdge(floor, movedPos) && ThreadLocalRandom.current().nextBoolean()) {
	    mop.setRandomDirection();
	}

	// Move mop
	mop.setPosition(movedPos);
	break;
    }
    // Change direction
    mop.setRandomDirection();
}
   }
 
开发者ID:Ellzord,项目名称:JALSE-RoboMop,代码行数:26,代码来源:MoveMop.java


示例4: perform

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void perform(final ActionContext<Entity> context) {
// Actor this action was for
final Entity actor = context.getActor();

// Creates random 'sentence'
final String text = createText();
System.out.println(String.format("%s -> %s: %s", actor.getID(), to, text));

// Get parent JALSE
final EntityContainer container = actor.getContainer();
// Get recipient messenger
final Messenger recipient = container.getEntityAsType(to, Messenger.class);

// Create message contents
final AttributeContainer contents = new DefaultAttributeContainer();
contents.setAttribute("text", STRING_TYPE, text);
contents.setAttribute("from", newTypeOf(UUID.class), actor.getID());

// Create the message and trigger response
recipient.newMessage(contents);
   }
 
开发者ID:Ellzord,项目名称:JALSE-Messengers,代码行数:23,代码来源:SendMessage.java


示例5: invoke

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public Object invoke(final Object proxy, final Entity entity, final Object[] args) throws Throwable {
// Check no args
if (args.length != 1) {
    throw new IllegalArgumentException("Should have 1 argument");
}
if (optional) {
    return entity.setOptAttribute(namedType, args[0]);
} else {
    Object result = entity.setAttribute(namedType, args[0]);
    if (result == null && primitive) {
	result = defaultValue;
    }
    return result;
}
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:17,代码来源:SetAttributeMethod.java


示例6: newIDFilter

import jalse.entities.Entity; //导入依赖的package包/类
private Predicate<Entity> newIDFilter() {
return e -> {
    // No filtering on empty suppliers.
    if (idSuppliers.isEmpty()) {
	return true;
    }
    boolean found = false;
    for (final Supplier<UUID> idSupplier : idSuppliers) {
	// Check is ID
	if (e.getID().equals(idSupplier.get())) {
	    found = true;
	    break;
	}
    }
    return found;
};
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:18,代码来源:GetEntitiesMethod.java


示例7: invoke

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public Object invoke(final Object proxy, final Entity entity, final Object[] args) throws Throwable {
// Check no args
if (args != null && args.length > 0) {
    throw new IllegalArgumentException("Should have no arguments");
}
if (optional) {
    return entity.getOptAttribute(namedType);
} else {
    Object result = entity.getAttribute(namedType);
    if (result == null && primitive) {
	result = defaultValue;
    }
    return result;
}
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:17,代码来源:GetAttributeMethod.java


示例8: apply

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public MarkAsTypeMethod apply(final Method m) {
// Check for annotation
final MarkAsType annonation = m.getAnnotation(MarkAsType.class);
if (annonation == null) {
    return null;
}

// Check subtype
final Class<? extends Entity> entityType = annonation.value();
if (!isEntitySubtype(entityType)) {
    throw new IllegalArgumentException("Entity type must be a subtype");
}

// Basic check method signature
checkNoParams(m);
checkNotDefault(m);

// Check return type.
if (hasReturnType(m) && !returnTypeIs(m, Boolean.TYPE)) {
    throw new IllegalArgumentException("Must have void or boolean return type");
}

// Create get entity method
return new MarkAsTypeMethod(entityType);
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:27,代码来源:MarkAsTypeFunction.java


示例9: apply

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public UnmarkAsTypeMethod apply(final Method m) {
// Check for annotation
final UnmarkAsType annonation = m.getAnnotation(UnmarkAsType.class);
if (annonation == null) {
    return null;
}

// Check subtype
final Class<? extends Entity> entityType = annonation.value();
if (!isEntitySubtype(entityType)) {
    throw new IllegalArgumentException("Entity type must be a subtype");
}

// Basic check method signature
checkNoParams(m);
checkNotDefault(m);

// Check return type.
if (hasReturnType(m) && !returnTypeIs(m, Boolean.TYPE)) {
    throw new IllegalArgumentException("Must have void or boolean return type");
}

// Create get entity method
return new UnmarkAsTypeMethod(entityType);
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:27,代码来源:UnmarkAsTypeFunction.java


示例10: getTreeMember

import jalse.entities.Entity; //导入依赖的package包/类
/**
    * Sets the correct {@link TreeMember} tag for the container.
    *
    * @param container
    *            Container to check for.
    * @return The member enum.
    */
   public static TreeMember getTreeMember(final EntityContainer container) {
// Must be identifiable to be a tree member
if (!(container instanceof Identifiable)) {
    return null;
}
// Entity with no identifable parent (or JALSE).
if (!(container instanceof Entity) || ((Entity) container).getContainer() == null) {
    return TreeMember.ROOT;
}
// Entity with children
else if (container.hasEntities()) {
    return TreeMember.NODE;
}
// Entity with no children
else {
    return TreeMember.LEAF;
}
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:26,代码来源:Tags.java


示例11: attributeTypeTest

import jalse.entities.Entity; //导入依赖的package包/类
@Test
   public void attributeTypeTest() {
Assert.assertEquals(new AttributeType<Boolean>() {}, Attributes.BOOLEAN_TYPE);
Assert.assertEquals(new AttributeType<Integer>() {}, Attributes.INTEGER_TYPE);
Assert.assertEquals(new AttributeType<String>() {}, Attributes.STRING_TYPE);
Assert.assertEquals(new AttributeType<Double>() {}, Attributes.DOUBLE_TYPE);
Assert.assertEquals(new AttributeType<Character>() {}, Attributes.CHARACTER_TYPE);
Assert.assertEquals(new AttributeType<Long>() {}, Attributes.LONG_TYPE);
Assert.assertEquals(new AttributeType<Byte>() {}, Attributes.BYTE_TYPE);
Assert.assertEquals(new AttributeType<Float>() {}, Attributes.FLOAT_TYPE);
Assert.assertEquals(new AttributeType<Short>() {}, Attributes.SHORT_TYPE);
Assert.assertEquals(new AttributeType<Object>() {}, Attributes.OBJECT_TYPE);

Assert.assertEquals(new AttributeType<Entity>() {}, Attributes.newTypeOf(Entity.class));
Assert.assertEquals(new AttributeType<Entity>() {}, Attributes.newUnknownType(Entity.class));
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:17,代码来源:AttributesTest.java


示例12: killEntityTest

import jalse.entities.Entity; //导入依赖的package包/类
@Test
   public void killEntityTest() {
jalse = new DefaultJALSE(new UUID(0, 0), ForkJoinActionEngine.commonPoolEngine(), new DefaultEntityFactory());

final Entity entity1 = jalse.newEntity(new UUID(0, 1));
final Entity entity2 = jalse.newEntity(new UUID(0, 2));
final Entity entity3 = jalse.newEntity(new UUID(0, 3));

Assert.assertTrue(entity1.isAlive());
Assert.assertTrue(entity2.isAlive());
Assert.assertTrue(entity3.isAlive());

jalse.killEntity(new UUID(0, 1));
Assert.assertFalse(entity1.isAlive());
Assert.assertTrue(entity2.isAlive());
Assert.assertTrue(entity3.isAlive());

jalse.killEntities();
Assert.assertFalse(entity1.isAlive());
Assert.assertFalse(entity2.isAlive());
Assert.assertFalse(entity3.isAlive());
   }
 
开发者ID:Ellzord,项目名称:JALSE,代码行数:23,代码来源:DefaultJALSETest.java


示例13: attributeAdded

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void attributeAdded(final AttributeEvent<Double> event) {
final Person person = ((Entity) event.getContainer()).asType(Person.class);
final double starvation = event.getValue();

// Check starvation
if (starvation >= 1.0) {
    person.cancelAllScheduledForActor();
    person.unmarkAsType(Infected.class);
    person.markAsType(Corpse.class);
}
   }
 
开发者ID:Ellzord,项目名称:JALSE-Zombies,代码行数:13,代码来源:StarvationListener.java


示例14: perform

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void perform(final ActionContext<Entity> context) throws InterruptedException {
final Carrier carrier = context.getActor().asType(Carrier.class);

// Increase infection fraction a bit
final double infection = carrier.getInfectionPercentage() + 1. / 30 / ZombiesProperties.getInfectionTime();
carrier.setInfectionPercentage(infection);
   }
 
开发者ID:Ellzord,项目名称:JALSE-Zombies,代码行数:9,代码来源:GetSick.java


示例15: perform

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void perform(final ActionContext<Entity> context) throws InterruptedException {
final Field field = context.getActor().asType(Field.class);
final Set<Person> people = field.getEntitiesOfType(Person.class);
people.stream().filter(notMarkedAsType(Corpse.class)).forEach(person -> {
    // Get correct move angle
    double moveAngle;
    if (person.isMarkedAsType(Infected.class)) {
	// Move towards healthy
	moveAngle = directionToHealthyAndBite(person, people);
    } else if (person.isMarkedAsType(Carrier.class)) {
	// Move randomly
	moveAngle = randomDirection(person);
    } else {
	// Run away
	moveAngle = directionAwayFromInfected(person, people);
    }
    person.setAngle(moveAngle);

    // Calculate move delta
    final double moveDist = person.getSpeed();
    final Point moveDelta = new Point((int) (moveDist * Math.cos(moveAngle)),
	    (int) (moveDist * Math.sin(moveAngle)));

    // Original values
    final Point pos = person.getPosition();
    final int size = ZombiesProperties.getSize();

    // Apply bounded move delta
    final int x = bounded(pos.x + moveDelta.x, 0, ZombiesPanel.WIDTH - size);
    final int y = bounded(pos.y + moveDelta.y, 0, ZombiesPanel.HEIGHT - size);

    if (pos.x != x || pos.y != y) {
	// Update if changed
	person.setPosition(new Point(x, y));
    }
});
   }
 
开发者ID:Ellzord,项目名称:JALSE-Zombies,代码行数:39,代码来源:MovePeople.java


示例16: perform

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void perform(final ActionContext<Entity> context) throws InterruptedException {
final Infected infected = context.getActor().asType(Infected.class);

// Infected slowly starve to death after biting
final double hunger = infected.getHungerPercentage() + 1. / 30 / ZombiesProperties.getStarveTime();
infected.setHungerPercentage(hunger);
   }
 
开发者ID:Ellzord,项目名称:JALSE-Zombies,代码行数:9,代码来源:Starve.java


示例17: entityMarkedAsType

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void entityMarkedAsType(final EntityTypeEvent event) {
final Person person = event.getEntity().asType(Person.class);
final Class<? extends Entity> type = event.getTypeChange();

person.setColour(ZombiesProperties.getColour(type));
person.setSightRange(ZombiesProperties.getSightRange(type));
person.setSpeed(ZombiesProperties.getSpeed(type));
   }
 
开发者ID:Ellzord,项目名称:JALSE-Zombies,代码行数:10,代码来源:TransformationListener.java


示例18: perform

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void perform(final ActionContext<JALSE> tick) {
// The actor for this action
final JALSE jalse = tick.getActor();

// Only process cows
jalse.streamEntitiesOfType(Cow.class).forEach(c -> {
    // Eat grass at the same position
    final Point pos = c.getPosition();
    jalse.streamEntitiesOfType(Grass.class).filter(g -> pos.equals(g.getPosition())).forEach(Entity::kill);
});
   }
 
开发者ID:Ellzord,项目名称:JALSE-HappyCows,代码行数:13,代码来源:CowsEatGrass.java


示例19: entityKilled

import jalse.entities.Entity; //导入依赖的package包/类
@Override
   public void entityKilled(final EntityEvent event) {
// Get entity that was killed
final Entity e = event.getEntity();

// Check it was grass
if (e.isMarkedAsType(Grass.class)) {
    System.out.println(String.format("Grass has been eaten [%s]", e.getID()));
    // Schedule another to be created
    ((JALSE) event.getContainer()).scheduleForActor(new SproutGrass(), 300, TimeUnit.MILLISECONDS);
}
   }
 
开发者ID:Ellzord,项目名称:JALSE-HappyCows,代码行数:13,代码来源:GrowGrass.java


示例20: entitySummary

import jalse.entities.Entity; //导入依赖的package包/类
private EntitySummary entitySummary(final UUID jID, final UUID eID) {
final Entity entity = jalseService.getEntity(jID, eID);
return new EntitySummary(jID, Identifiable.getID(entity.getContainer()), eID,
	entity.getSingletonTag(OriginContainer.class).getValue(), entity.getEntityCount(),
	sdf.get().format(entity.getSingletonTag(Created.class).getValue()),
	entity.getSingletonTag(TreeMember.class), entity.getSingletonTag(TreeDepth.class).getValue());
   }
 
开发者ID:dting,项目名称:RemoteJALSE,代码行数:8,代码来源:SummaryController.java



注:本文中的jalse.entities.Entity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ExpressionConverter类代码示例发布时间:2022-05-22
下一篇:
Java XSLFPowerPointExtractor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap