当前位置: 首页>>代码示例>>Java>>正文


Java Entity类代码示例

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


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


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