/** * Random roll chooses which army will execute it's action first, sets those actions and then * executes them turn for turn. Also rolls for a chance that random event will occur. */ public void engageArmies() { while (!firstArmy.isDefeated() && !secondArmy.isDefeated()) { turns++; System.out.println("\nTURN " + turns); if (RandomEventGenerator.eventHappens()) { executeRandomEvent(); } System.out.println(firstArmy.getDetails()); System.out.println(secondArmy.getDetails()); if (firstStrikeChance() > firstStrikeChance()) { System.out.println("You have first strike!"); setPlayerAction(); setComputerAction(); executeFight(firstArmy, secondArmy); } else { System.out.println("Your opponent has first strike!"); setPlayerAction(); setComputerAction(); executeFight(secondArmy, firstArmy); } } }
@SuppressWarnings({"rawtypes", "unchecked"}) public void testSchemaNodeProcessing() throws Exception { RandomEventGenerator node = new RandomEventGenerator(); node.setMinvalue(0); node.setMaxvalue(999); node.setTuplesBlast(5000); CollectorTestSink integer_data = new CollectorTestSink(); node.integer_data.setSink(integer_data); CollectorTestSink string_data = new CollectorTestSink(); node.string_data.setSink(string_data); node.setup(null); node.beginWindow(1); node.emitTuples(); node.endWindow(); node.teardown(); assertTrue("tuple blast", integer_data.collectedTuples.size() == 5000); assertTrue("tuple blast", string_data.collectedTuples.size() == 5000); }
/** * Executes one of possible random events that effect the battle for this turn. The event is * chosen randomly. */ private void executeRandomEvent() { RandomEventGenerator.createRandomEvent().executeEvent(firstArmy, secondArmy); }