@Test public void shouldInstantiateAnObjectIfRequiredToSetAProperty() throws OgnlException { OgnlRuntime.setNullHandler(House.class, handler); House house = new House(); Ognl.setValue("mouse.name", context, house, "James"); MatcherAssert.assertThat(house.getMouse().getName(), Matchers.is(Matchers.equalTo("James"))); }
@Test public void shouldNotInstantiateIfLastTerm() throws OgnlException, NoSuchMethodException { OgnlRuntime.setNullHandler(House.class, handler); final TypeConverter typeConverter = mockery.mock(TypeConverter.class); final House house = new House(); final Mouse tom = new Mouse(); mockery.checking( new Expectations() { { one(typeConverter) .convertValue( context, house, House.class.getDeclaredMethod("setMouse", Mouse.class), "mouse", "22", Mouse.class); will(returnValue(tom)); } }); Ognl.setTypeConverter(context, typeConverter); Ognl.setValue("mouse", context, house, "22"); MatcherAssert.assertThat(house.getMouse(), Matchers.is(Matchers.equalTo(tom))); mockery.assertIsSatisfied(); }
public static void main(String[] args) { Builder builder = new Worker(); Designer designer = new Designer(builder); designer.makeHouse(); House house = builder.getHouse(); house.liveIn(); }
public void stateChanged(List<ActionRule> appliedRules) { /* * Update score */ int appliedScore = 0; for (ActionRule aRule : appliedRules) { appliedScore += aRule.score(); } this.playerScore += appliedScore; /* * Check whether a Rule ended the game */ for (ActionRule aRule : appliedRules) { if (aRule.endsGame() == false) { continue; } this.gameOver = true; this.gameOverMessage = aRule.getDescription(); notifyListeners(0); return; } /* * Check whether all houses are closed */ boolean allClosed = true; for (House house : this.houses) { if (house.isOpened()) allClosed = false; } if (allClosed) { /* * If all closed, then game over */ this.gameOver = true; this.gameOverMessage = "All houses where closed."; } else { /* * If at least one opened, try to deal */ try { deal(); } catch (HoCException e) { /* * If there are no cards left, game over */ this.playersHandCard = null; this.gameOver = true; notifyListenersGameWon( this.hallOfFame.addPlayer(new Player("Enter Name", this.playerScore))); return; } } notifyListeners(appliedScore); }
public void update(float deltaTime) { // farm.closeEnoughToFarm(); // farm.farmTimer(); house.closeEnough(); house.gettingInandOut(); player.move(); player.setSprites(); }
private void logPosition(Santa santa) { for (House house : houses) { if (santa.getPos().equals(house.getPos())) { house.visit(); return; } } houses.add(new House(new Position(santa.getPos().getX(), santa.getPos().getY()))); }
private String getInfo(House house) { return new StringBuilder() .append("Cost: ") .append(house.getCost()) .append("\nWalls: ") .append(house.getWalls().size()) .append("\nEnjoy your new ") .append(house.getShape()) .append(" house!") .toString(); }
public void testErrorDuringUpdateOwneeDoesNotLeakMemory() throws Exception { Session hibSession = sessionFactory.openSession(); Transaction hibTr = hibSession.beginTransaction(); CompassSession session = compass.openSession(); // (AGR_OSEM) ... CompassTransaction tr = session.beginTransaction(); Roof r1 = new Roof(); r1.setName("the roof"); House h1 = new House(); h1.setName("my house"); h1.setRoof(r1); r1.setHouse(h1); hibSession.save(h1); // (AGR_OSEM) ... tr.commit(); session.close(); hibTr.commit(); hibSession.close(); hibSession = sessionFactory.openSession(); hibTr = hibSession.beginTransaction(); session = compass.openSession(); // (AGR_OSEM) ... tr = session.beginTransaction(); // h1 = (House) hibSession.get(House.class, h1.getId()); Roof r2 = new Roof(); r2.setName("the new roof"); h1.setRoof(r2); r2.setHouse(h1); r2.throwError = true; try { hibSession.update(h1); fail("should throw error"); } catch (RuntimeException ex) { // good // (AGR_OSEM) ... tr.rollback(); session.close(); hibTr.rollback(); hibSession.close(); } Map pendingCreate = (Map) getProperty(hibernateEventListener, "pendingCreate"); assertTrue(pendingCreate.isEmpty()); Map pendingSave = (Map) getProperty(hibernateEventListener, "pendingSave"); assertTrue(pendingSave.isEmpty()); }
private void setMovePoint(int touchX, int touchY) { House house = (House) mWallShelf.getParent(); SEVector3f location = house.getFingerLocation(touchX, touchY); float radius = house.getWallRadius() * 0.8f; // SERay Ray = getScene().getCamera().screenCoordinateToRay(touchX, touchY); mRealLocation = location; // getTouchLocation(Ray, mWallShelf.getBorderHeight()); // SEVector3f touchLocation = getTouchLocation(Ray, mWallShelf.getBorderHeight() + 5); mObjectTransParas = new SETransParas(); mObjectTransParas.mTranslate = new SEVector3f(location.getX(), location.getY() - 60, location.getZ()); mObjectTransParas.mRotate.set(mWallShelf.getUserRotate().getAngle(), 0, 0, 1); }
public void runAppExample() throws Exception { House house = new House(); CircleTable circleTable = null; // 从工具列选择一个家具加入房子中 circleTable = (CircleTable) circleTablePrototype.clone(); circleTable.setCenter(new Point(10, 10)); house.addFurniture(circleTable); // 从工具列选择一个家具加入房子中 circleTable = (CircleTable) circleTablePrototype.clone(); circleTable.setCenter(new Point(20, 30)); house.addFurniture(circleTable); }
public GameScreen(Game game) { this.game = game; camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); batch = new SpriteBatch(); // farm = new Farm(); house = new House(); house.x = 1000; house.y = 950; level = new Level(); player = new Player(); resource = new Resource(); }
private boolean notOtherGroupInTheNextRoom(Group groupItem) { boolean retValue = true; if (!groupItem.getPlayers().get(0).getActRoom().equals(House.poison)) { int index = house.getRooms().indexOf(groupItem.getPlayers().get(0).getActRoom()); for (Group group : groups) { if (group.isEveryBodyInTheRoom(house.getRooms().get(index + 1))) { retValue = false; } } } return retValue; }
/** * This method is used for houses to damage other houses, which they can attack * * @param opp The house will be attacked and damaged */ public void harmHouse(House opp) { Random num3 = new Random(); int num5 = num3.nextInt(10) + 1; if (num5 <= 2) { opp.life -= 7; } }
/* * Searches for a house section by name */ public HouseSection selectHousesection(String name) { // 1st validate user input if (name == null) { throw new IllegalArgumentException("The name supplied is undefined!"); } return house.getHouseSection(name); }
/** * This method is used for houses to damage other houses, which they can attack * * @param opp The house will be attacked and damaged */ public void harmHouse(House opp) { Random num3 = new Random(); int num5 = num3.nextInt(10) + 1; if (!(opp instanceof Baratheon)) { opp.life -= 7; } }
/** * Moves a card from players hand to the given house. * * @param house the house to add the card * @throws HoCException when there is no card in players hand <br> * when house is closed <br> * when game hasn't started */ public void addCardToHouse(House house) throws HoCException { if (this.playersHandCard == null) throw new HoCException("Player doesn't have any card in hand"); if ((!this.started) || (this.gameOver)) throw new HoCException("Game hasn't started"); house.addCard(this.playersHandCard); }
@Test public void shouldInstantiateAListOfStrings() throws OgnlException { mockery.checking( new Expectations() { { one(removal).add((Collection<?>) with(an(Collection.class))); } }); OgnlRuntime.setNullHandler(House.class, handler); OgnlRuntime.setNullHandler(Mouse.class, handler); House house = new House(); Ognl.setValue("mouse.eyeColors[0]", context, house, "Blue"); Ognl.setValue("mouse.eyeColors[1]", context, house, "Green"); MatcherAssert.assertThat( house.getMouse().getEyeColors().get(0), Matchers.is(Matchers.equalTo("Blue"))); MatcherAssert.assertThat( house.getMouse().getEyeColors().get(1), Matchers.is(Matchers.equalTo("Green"))); }
public static void removeGuild(int id) { // Maison de guilde+SQL House.removeHouseGuild(id); // Enclo+SQL Carte.MountPark.removeMountPark(id); // Percepteur+SQL Percepteur.removePercepteur(id); // Guilde Guildes.remove(id); SQLManager.DEL_ALL_GUILDMEMBER(id); // Supprime les membres SQLManager.DEL_GUILD(id); // Supprime la guilde }
public void draw(float deltaTime) { Gdx.gl.glClearColor(255f, 255f, 255f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); level.draw(batch); // farm.draw(batch, font); house.draw(batch, font); player.draw(batch); batch.end(); }
@Override public void init(GameContainer gc) throws SlickException { // Load the resources ResourceManager manager = ResourceManager.getInstance(); manager.addResourceLoader(ImageLoader.getInstance()); manager.addResourceLoader(ColorLoader.getInstance()); manager.fromXML("wizardgame.xml"); CitySetting setting = new CitySetting(); setting.setWidth(10000); setting.setHeight(10000); world = new TileWorld("TileWorld", gc, setting); Camera camera = world.getCamera(); camera.addComponent(new WorldBoundComponent(world)); camera.addComponent(new CameraMovementComponent()); cursorTorch = new Torch(0, 0, world); world.addWorldEntity(cursorTorch); // Add some houses for (int i = 0; i < 300; i++) { House house = new House(world); house.setGlobalPosition( (float) (Math.random() * world.getWidth()), (float) (Math.random() * world.getHeight())); world.addWorldEntity(house); Light light = new Light( (int) (Math.random() * world.getWidth()), (int) (Math.random() * world.getHeight()), 650, new Color(50, 120, 255), world); world.addWorldEntity(light); } }
public void testSave() throws Exception { CompassSession session = compass.openSession(); // (AGR_OSEM) ... CompassTransaction tr = session.beginTransaction(); Session hibSession = sessionFactory.openSession(); Transaction hibTr = hibSession.beginTransaction(); Roof r1 = new Roof(); r1.setName("the roof"); Foundations f1 = new Foundations(); f1.setName("foundations"); House h1 = new House(); h1.setName("my house"); h1.setRoof(r1); r1.setHouse(h1); h1.setFoundations(f1); // (AGR_OSEM) ... assertEquals(0, // session.queryBuilder().matchAll().setTypes(Roof.class).hits().length()); // (AGR_OSEM) ... assertEquals(0, // session.queryBuilder().matchAll().setTypes(House.class).hits().length()); hibSession.save(h1); // objects are present in index after save, before commit // (AGR_OSEM) ... assertEquals(1, // session.queryBuilder().matchAll().setTypes(Roof.class).hits().length()); // (AGR_OSEM) ... assertEquals(1, // session.queryBuilder().matchAll().setTypes(House.class).hits().length()); // (AGR_OSEM) ... tr.commit(); session.close(); hibTr.commit(); hibSession.close(); }
private static House cloneHouse(House house) { return new House( house.getName(), house.getDescription(), house.getLevel(), house.getUpgradeCost(), house.getCost(), house.getInhabitants()); }
/** * When the game first starts, this method initializes all new Houses * * @param suit the CardSuit of the House * @return the House that was created * @param withJokerRule <code>true</code> for the Joker Rule to be added, otherwise <code>false * </code> * @param withNumCardRule <code>true</code> for the NumCard Rule to be added, otherwise <code> * false</code> */ private House createNewHouse(CardSuit suit, boolean withJokerRule, boolean withNumCardRule) { House house = new House(suit); house.addHouseListener(this); /* * Add all PermissionRules */ house.addPermissionRule((new ClosedHouseRule())); /* * Add all ActionRules */ if (withJokerRule) house.addActionRule(new JokerRule()); if (withNumCardRule) house.addActionRule(new NumCardRule(NUM_CARDS_THRESHOLD_RULE, NUM_POINTS_THRESHOLD_RULE)); house.addActionRule(new ScoreRule(NUM_POINTS_THRESHOLD_RULE)); return house; }
public static void saveAll(Personnage saver) { PrintWriter _out = null; if (saver != null) _out = saver.get_compte().getGameThread().get_out(); set_state((short) 2); try { GameServer.addToLog("Lancement de la sauvegarde du Monde..."); Ancestra.isSaving = true; SQLManager.commitTransacts(); SQLManager.TIMER(false); // Arrête le timer d'enregistrement SQL Thread.sleep(10000); GameServer.addToLog("Sauvegarde des personnages..."); for (Personnage perso : Persos.values()) { if (!perso.isOnline()) continue; Thread.sleep(100); // 0.1 sec. pour 1 objets SQLManager.SAVE_PERSONNAGE(perso, true); // sauvegarde des persos et de leurs items } Thread.sleep(2500); GameServer.addToLog("Sauvegarde des guildes..."); for (Guild guilde : Guildes.values()) { Thread.sleep(100); // 0.1 sec. pour 1 guilde SQLManager.UPDATE_GUILD(guilde); } Thread.sleep(2500); GameServer.addToLog("Sauvegarde des percepteurs..."); for (Percepteur perco : Percepteurs.values()) { if (perco.get_inFight() > 0) continue; Thread.sleep(100); // 0.1 sec. pour 1 percepteur SQLManager.UPDATE_PERCO(perco); } Thread.sleep(2500); GameServer.addToLog("Sauvegarde des maisons..."); for (House house : Houses.values()) { if (house.get_owner_id() > 0) { Thread.sleep(100); // 0.1 sec. pour 1 maison SQLManager.UPDATE_HOUSE(house); } } Thread.sleep(2500); GameServer.addToLog("Sauvegarde des coffres..."); for (Trunk t : Trunks.values()) { if (t.get_owner_id() > 0) { Thread.sleep(100); // 0.1 sec. pour 1 coffre SQLManager.UPDATE_TRUNK(t); } } Thread.sleep(2500); GameServer.addToLog("Sauvegarde des enclos..."); for (Carte.MountPark mp : MountPark.values()) { if (mp.get_owner() > 0 || mp.get_owner() == -1) { Thread.sleep(100); // 0.1 sec. pour 1 enclo SQLManager.UPDATE_MOUNTPARK(mp); } } Thread.sleep(2500); GameServer.addToLog("Sauvegarde des Hdvs..."); ArrayList<HdvEntry> toSave = new ArrayList<HdvEntry>(); for (HDV curHdv : Hdvs.values()) { toSave.addAll(curHdv.getAllEntry()); } SQLManager.SAVE_HDVS_ITEMS(toSave); Thread.sleep(10000); GameServer.addToLog("Sauvegarde effectuee !"); set_state((short) 1); // TODO : Rafraichir } catch (ConcurrentModificationException e) { if (saveTry < 10) { GameServer.addToLog("Nouvelle tentative de sauvegarde"); if (saver != null && _out != null) SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET( _out, "Erreur. Nouvelle tentative de sauvegarde"); saveTry++; saveAll(saver); } else { set_state((short) 1); // TODO : Rafraichir String mess = "Echec de la sauvegarde apres " + saveTry + " tentatives"; if (saver != null && _out != null) SocketManager.GAME_SEND_CONSOLE_MESSAGE_PACKET(_out, mess); GameServer.addToLog(mess); } } catch (Exception e) { GameServer.addToLog("Erreur lors de la sauvegarde : " + e.getMessage()); e.printStackTrace(); } finally { SQLManager.commitTransacts(); SQLManager.TIMER(true); // Redémarre le timer d'enregistrement SQL Ancestra.isSaving = false; saveTry = 1; } }
private void killAllRoom() { for (Room room : house.getRooms()) { room.setIsScary(new AtomicBoolean(false)); room.shutdownHorrorPlayers(); } }
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("house-config.xml"); House house = (House) context.getBean("house"); System.out.println(house.getPrice()); }
private void readLog() { for (House house : houses) { System.out.println(house.toString()); } }
/* * Indicates that user has ended house sections picking and ready to apply the * transaction. */ public TransactionStatus endControlLighting() { TransactionStatus status = lct.process(); house.logTransaction(lct, TransactionType.CONTROL_LIGHTING, status); return status; }
public static void addHouse(House house) { Houses.put(house.get_id(), house); }
private void setFirstRoom(Group g) { // TODO Auto-generated method stub for (Player item : g.getPlayers()) { item.setActRoom(house.getFirstRoom()); } }