Esempio n. 1
0
 public Array<Soldier> getHealthyArchers() {
   Array<Soldier> toReturn = new Array<Soldier>();
   for (Soldier s : healthy) {
     if (s.getType() == SoldierType.ARCHER) toReturn.add(s);
   }
   return toReturn;
 }
Esempio n. 2
0
  @Test
  public void testCascadeAndFetchCollection() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    Troop disney = new Troop();
    disney.setName("Disney");
    Soldier mickey = new Soldier();
    mickey.setName("Mickey");
    disney.addSoldier(mickey);
    em.persist(disney);
    em.getTransaction().commit();
    em.close();

    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    Troop troop = em.find(Troop.class, disney.getId());
    assertFalse(Hibernate.isInitialized(troop.getSoldiers()));
    em.getTransaction().commit();
    assertFalse(Hibernate.isInitialized(troop.getSoldiers()));
    em.close();

    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    troop = em.find(Troop.class, disney.getId());
    em.remove(troop);
    // Fail because of HHH-1187
    em.getTransaction().commit();
    em.close();
  }
Esempio n. 3
0
 // used for placing troops
 public Array<Soldier> getHealthyInfantry() {
   Array<Soldier> roReturn = new Array<Soldier>();
   for (Soldier s : healthy) {
     if (s.getType() == SoldierType.INFANTRY) roReturn.add(s);
   }
   return roReturn;
 }
Esempio n. 4
0
 public Array<Soldier> getHealthyCavalry() {
   Array<Soldier> toReturn = new Array<Soldier>();
   for (Soldier s : healthy) {
     if (s.getType() == SoldierType.CAVALRY) toReturn.add(s);
   }
   return toReturn;
 }
Esempio n. 5
0
 public void checkHeal() { // to be called every frame
   Iterator<Soldier> iter = wounded.iterator();
   while (iter.hasNext()) {
     Soldier soldier = iter.next();
     if (soldier.isHealed()) heal(soldier);
     updated = true;
   }
 }
Esempio n. 6
0
 public void checkUpgrades() {
   for (Soldier s : getUpgradable()) {
     if (s.unitType.upgrades.length == 0) return;
     int selection = (int) (Math.random() * s.unitType.upgrades.length);
     s.upgrade(s.unitType.upgrades[selection]);
     //			s.upgrade(Weapon.upgrade(s.getWeapon()).random());
   }
 }
    public void monitorSoldier(MyMessage myMsg) {
      /** 开启多线程 */
      Thread[] threadList = new Thread[Values.THREAD_NUMBER];
      for (int i = 0; i < Values.THREAD_NUMBER; i++) {
        Soldier soldier = new Soldier();
        soldier.myMsg = Utils.deepCopyMsg(myMsg);
        soldier.threadId = i + 1;
        Thread soldierThread = new Thread(soldier);
        soldierThread.start();
        threadList[i] = soldierThread;
      }
      /** 轮询查看下载进度,并告知UI线程 */
      boolean monitorLive = true;
      long t1 = System.currentTimeMillis();
      Log.d("johnchain", "Commander commanderLive = " + Values.commanderLive);
      while (!Thread.currentThread().isInterrupted() && monitorLive && Values.commanderLive) {
        try {
          Thread.sleep(2000);
        } catch (InterruptedException e) {
          Log.e("johnchain", "Commander get interrupt signal from UI thread");
          break;
        }

        if (Values.downloadedBlock >= Values.blockNum) {
          Log.i("johnchain", "Commander downloaded already finished");
          monitorLive = false;
        }
        Message msg = commanderToMainHandler.obtainMessage();
        msg.what = Values.MT_PROG;
        Bundle bundle = new Bundle();

        try {
          int prog = (Values.downloadedBlock * 100 / Values.blockNum);
          bundle.putInt("TotalProg", prog);
          bundle.putString("filename", Values.fileName);
          msg.setData(bundle);
          //		    		Log.d("johnchain" ,"Commander prog = " + prog + " [" + Values.downloadedBlock +
          // "/" + Values.blockNum + "]");

          Values.timeCost = (System.currentTimeMillis() - t1) / 1000;
          commanderToMainHandler.sendMessage(msg);
        } catch (ArithmeticException e) {
          Log.e("johnchain", "Commander Uninitialed blockNum, 0");
          monitorLive = false;
        }
      }
      Values.soldierLive = false;
      for (Thread thread : threadList) {
        if (thread.isAlive()) {
          try {
            thread.join();
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    }
Esempio n. 8
0
 public void calcStats() {
   atkTotal = 0;
   defTotal = 0;
   spdTotal = 0;
   for (Soldier s : healthy) {
     atkTotal += s.baseAtk + s.getBonusAtk();
     defTotal += s.baseDef + s.getBonusDef();
     spdTotal += s.baseSpd + s.getBonusSpd();
   }
   if (!player) minWealth = (int) (MIN_WEALTH_FACTOR * getTotalSize());
   else minWealth = 0;
 }
Esempio n. 9
0
File: Demo.java Progetto: CKiilu/COD
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   Soldier ghost = new Soldier(3, 2500);
   SuperSoldier snake = new SuperSoldier(4, 10000);
   SuperSoldier solid = new SuperSoldier(4, 2500);
   ghost.takeDamage(1000);
   snake.takeDamage(1000);
   solid.takeDamage(1000);
   System.out.println("Ghost has " + ghost.getRemainingHP() + " HP remaining.");
   System.out.println("Solid has " + solid.getRemainingHP() + " HP remaining.");
   System.out.println("Snake has " + snake.getRemainingHP() + " HP remaining.");
   snake.superSelection();
   solid.superSelection();
 }
Esempio n. 10
0
 /** @param args */
 public static void main(String[] args) {
   Soldier s = new Soldier();
   s.cure();
   s.wound();
   s.wound();
   s.resurrect();
   s.kill();
   s.resurrect();
   s.wound();
   s.kill();
   s.resurrect();
 }
Esempio n. 11
0
 public void healNoMessage(Soldier soldier) {
   soldier.heal();
   wounded.removeValue(soldier, true);
   this.addSoldier(soldier);
   healthy.sort();
   updated = true;
 }
Esempio n. 12
0
 public void wound(Soldier soldier) {
   if (army != null) soldier.wound();
   healthy.removeValue(soldier, true);
   this.addSoldier(soldier);
   //	if (player) BottomPanel.log(soldier.name + " wounded", "orange");
   calcStats();
 }
 public static void run(RobotController _rc) throws Exception {
   switch (_rc.getType()) {
     case ARCHON:
       Archon.run(_rc);
       break;
     case GUARD:
       Guard.run(_rc);
       break;
     case SCOUT:
       Scout.run(_rc);
       break;
     case SOLDIER:
       Soldier.run(_rc);
       break;
     case TTM:
     case TURRET:
       Turret.run(_rc);
       break;
     case VIPER:
       Viper.run(_rc);
       break;
     default:
       // this shouldn't happen
       throw new Exception("I am a bad robot.");
   }
 }
Esempio n. 14
0
 // repairs an army as much as its wealth will allow it.
 public void repair(PartyType pt) { // returns a repair cost
   int newSize = pt.getRandomSize();
   int missing = Math.max(newSize - this.getTotalSize(), 0); // no negative ints
   //		int totalCost = 0;
   boolean canAfford = true;
   while (missing > 0 && canAfford) {
     Soldier newSoldier = new Soldier(pt.randomSoldierType(), this);
     int cost = newSoldier.getCost();
     if (this.wealth > cost) {
       this.addSoldier(newSoldier);
       this.wealth -= cost;
       missing--;
     } else {
       canAfford = false;
     }
   }
   System.out.println("party repaired");
 }
Esempio n. 15
0
  public static void main(String[] args) {
    Soldier sanmao = new Soldier();
    AbstractGun gun = new Handgun();
    sanmao.setGun(gun);
    sanmao.killEnemy();

    gun = new Rifle();
    sanmao.setGun(gun);
    sanmao.killEnemy();

    gun = new MachineGun();
    sanmao.setGun(gun);
    sanmao.killEnemy();
  }
Esempio n. 16
0
 public void addSoldier(Soldier soldier) {
   if (this.getTotalSize() >= maxSize) {
     System.out.println("trying to add more than max size");
     return;
   } else {
     updated = true;
     if (soldier.isWounded()) {
       wounded.add(soldier);
       wounded.sort();
     } else {
       healthy.add(soldier);
       healthy.sort();
     }
     calcStats();
   }
 }
Esempio n. 17
0
  // TODO maybe inefficient? can make more by sorting array by name
  private Array<Array<Soldier>> getConsol(Array<Soldier> arrSoldier) {
    // first thing: sort arrSoldier by name
    arrSoldier.sort();

    Array<String> names = new Array<String>();
    Array<Array<Soldier>> consol = new Array<Array<Soldier>>();
    for (Soldier s : arrSoldier) {
      if (!names.contains(s.getName() + s.getUnitClass(), false)) {
        names.add(s.getName() + s.getUnitClass());
        Array<Soldier> type = new Array<Soldier>();
        type.add(s);
        consol.add(type);
      } else {
        consol.get(names.indexOf(s.getName() + s.getUnitClass(), false)).add(s);
      }
    }
    return consol;
  }
Esempio n. 18
0
 @Test
 public void testStrike() {
   assertEquals(25, s2.strike());
 }
Esempio n. 19
0
 @Test
 public void testSword() {
   s2 = EquipmentFactory.createSword(s2, 175);
   assertEquals(200, s2.strike());
 }
Esempio n. 20
0
 @Test
 public void testShield() {
   s1 = EquipmentFactory.createShield(s1, 50);
   s1.parry(s2.strike());
   assertEquals(150, s1.getHealth());
 }
Esempio n. 21
0
  @Test
  public void testPerfCascadeAndFetchEntity() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    // init data
    em.getTransaction().begin();
    int loop = 50;
    for (int i = 0; i < loop; i++) {
      Troop disney = new Troop();
      disney.setName("Disney");
      Soldier mickey = new Soldier();
      mickey.setName("Mickey");
      disney.addSoldier(mickey);
      em.persist(disney);
    }
    em.getTransaction().commit();
    em.close();

    // Warm up loop
    em = getOrCreateEntityManager();
    em.getTransaction().begin();
    for (int i = 0; i < loop; i++) {
      // Soldier soldier = em.find( Soldier.class, new Integer(i) );
      Troop troop = em.find(Troop.class, new Integer(i));
      // ( ( HibernateEntityManager ) em ).getSession().evict(soldier);
    }
    long l11 = System.currentTimeMillis();
    Query query = em.createQuery("SELECT count(t) FROM Soldier t");
    query.getSingleResult();
    long l2 = System.currentTimeMillis();
    System.out.println("Query1 " + (l2 - l11));
    em.getTransaction().commit();
    em.close();

    // do not evict
    for (int j = 0; j < 10; j++) {
      em = getOrCreateEntityManager();
      em.getTransaction().begin();
      for (int i = 0; i < loop; i++) {
        Troop troop = em.find(Troop.class, new Integer(i));
        ((HibernateEntityManager) em).getSession().evict(troop);
      }
      l11 = System.currentTimeMillis();
      query = em.createQuery("SELECT count(t) FROM Soldier t");
      query.getSingleResult();
      l2 = System.currentTimeMillis();
      System.out.println("Query " + (l2 - l11));
      em.getTransaction().commit();
      em.close();

      // evict
      em = getOrCreateEntityManager();
      em.getTransaction().begin();
      for (int i = 0; i < loop; i++) {
        // Soldier soldier = em.find( Soldier.class, new Integer(i) );
        Troop troop = em.find(Troop.class, new Integer(i));

        // ( ( HibernateEntityManager ) em ).getSession().evict(troop);
      }
      l11 = System.currentTimeMillis();
      query = em.createQuery("SELECT count(t) FROM Soldier t");
      query.getSingleResult();
      l2 = System.currentTimeMillis();
      System.out.println("Query " + (l2 - l11));
      em.getTransaction().commit();
    }
    em.close();
  }
Esempio n. 22
0
 public void addSoldier(Soldier soldier) {
   soldiers.add(soldier);
   soldier.setCapo(this);
 }
Esempio n. 23
0
 public void heal(Soldier soldier) {
   healNoMessage(soldier);
   if (player) BottomPanel.log(soldier.getName() + " healed", "blue");
 }
Esempio n. 24
0
  @Test
  public void testParry() {
    s1.parry(s2.strike());

    assertEquals(150 - 25, s1.getHealth());
  }