コード例 #1
0
  public void testBroadcast() {
    Sprite sprite = new SingleSprite("testSprite");
    Script script = new StartScript();
    String message = "simpleTest";
    BroadcastBrick broadcastBrick = new BroadcastBrick(message);
    script.addBrick(broadcastBrick);
    sprite.addScript(script);

    BroadcastScript broadcastScript = new BroadcastScript(message);
    int testPosition = 100;
    SetXBrick testBrick = new SetXBrick(testPosition);
    broadcastScript.addBrick(testBrick);
    sprite.addScript(broadcastScript);

    Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Scene scene = project.getDefaultScene();
    scene.addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>());

    while (!allActionsOfAllSpritesAreFinished()) {
      for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) {
        spriteOfList.look.act(1.0f);
      }
    }

    assertEquals(
        "Simple broadcast failed",
        testPosition,
        (int) sprite.look.getXInUserInterfaceDimensionUnit());
  }
コード例 #2
0
  public void testRestartingOfWhenScriptWithBroadcastWaitBrick() {
    String messageOne = "messageOne";
    String messageTwo = "messageTwo";
    final int xMovement = 1;

    Sprite sprite = new SingleSprite("cat");
    Script startScript = new StartScript();
    BroadcastBrick startBroadcastBrick = new BroadcastBrick(messageOne);
    startScript.addBrick(startBroadcastBrick);
    sprite.addScript(startScript);

    BroadcastScript broadcastScriptMessageOne = new BroadcastScript(messageOne);
    ChangeXByNBrick changeXByNBrickOne = new ChangeXByNBrick(xMovement);
    BroadcastWaitBrick broadcastWaitBrickOne = new BroadcastWaitBrick(messageTwo);
    broadcastScriptMessageOne.addBrick(changeXByNBrickOne);
    broadcastScriptMessageOne.addBrick(broadcastWaitBrickOne);
    sprite.addScript(broadcastScriptMessageOne);

    BroadcastScript broadcastScriptMessageTwo = new BroadcastScript(messageTwo);
    ChangeXByNBrick changeXByNBrickTwo = new ChangeXByNBrick(xMovement);
    BroadcastWaitBrick broadcastWaitBrickTwo = new BroadcastWaitBrick(messageOne);
    broadcastScriptMessageTwo.addBrick(changeXByNBrickTwo);
    broadcastScriptMessageTwo.addBrick(broadcastWaitBrickTwo);
    sprite.addScript(broadcastScriptMessageTwo);

    Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    project.getDefaultScene().addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>());

    int loopCounter = 0;
    while (!allActionsOfAllSpritesAreFinished() && loopCounter++ < 20) {
      for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) {
        spriteOfList.look.act(1.0f);
      }
    }

    assertTrue(
        "When script does not restart itself when a BroadcastWait is sent! ",
        (int) sprite.look.getXInUserInterfaceDimensionUnit() > 5 * xMovement);
  }
コード例 #3
0
  public void testWhenScriptRestartingItself() {
    Sprite sprite = new SingleSprite("testSprite");
    Script script = new StartScript();

    String message = "simpleTest";
    BroadcastBrick broadcastBrick = new BroadcastBrick(message);
    script.addBrick(broadcastBrick);
    sprite.addScript(script);

    BroadcastScript broadcastScript = new BroadcastScript(message);

    final int xMovement = 1;
    ChangeXByNBrick changeXByNBrick = new ChangeXByNBrick(xMovement);
    broadcastScript.addBrick(changeXByNBrick);

    BroadcastBrick broadcastBrickLoop = new BroadcastBrick(message);
    broadcastScript.addBrick(broadcastBrickLoop);

    WaitBrick wb = new WaitBrick(5);
    broadcastScript.addBrick(wb);

    sprite.addScript(broadcastScript);

    Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    project.getDefaultScene().addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>());

    int loopCounter = 0;
    while (!allActionsOfAllSpritesAreFinished() && loopCounter++ < 20) {
      for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) {
        spriteOfList.look.act(1.0f);
      }
    }

    assertTrue(
        "When script does not restart itself!",
        (int) sprite.look.getXInUserInterfaceDimensionUnit() > xMovement);
  }