DatStorm

Untitled

Sep 14th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1.  
  2.     /**
  3.      * Make sure that makeNewUnit do not put a new unit out of map.
  4.      */
  5.     @Test
  6.     public void shouldTestThatMakeNewUnitDoNotPutUnitOutOFMapButIncreaseTreasury() {
  7.         assertThat(game.getCityAt(redCityPosition).getOwner(),is(Player.RED));
  8.  
  9.         int startingTreasury = ((CityImpl) game.getCityAt(redCityPosition)).getTreasurySize();
  10.         assertThat("Start with 0", startingTreasury, is(0));
  11.  
  12.         GameHelperMethods.numberOfEndOfTurn(game,20);
  13.         int currentTreasury = ((CityImpl) game.getCityAt(redCityPosition)).getTreasurySize();
  14.         assertThat("Should have 10*6 = 60 = 6_Archer = 0 treasury left", currentTreasury, is(0));
  15.  
  16.         assertThat("Red city has a new Archer at (0,0) because of Archer (2,0) and Ocean (1,0)",
  17.                 game.getUnitAt(new Position(0, 0)).getTypeString(), is(GameConstants.ARCHER));
  18.  
  19.         assertThat(((CityImpl) game.getCityAt(redCityPosition)).getTreasurySize(),is(0));
  20.  
  21.         GameHelperMethods.numberOfEndOfTurn(game,4);
  22.         assertThat("Instead of new unit out of map it increase treasurySize",
  23.                 ((CityImpl) game.getCityAt(redCityPosition)).getTreasurySize(),is(12));
  24.         GameHelperMethods.numberOfEndOfTurn(game,2);
  25.         assertThat("Instead of new unit out of map it increase treasurySize",
  26.                 ((CityImpl) game.getCityAt(redCityPosition)).getTreasurySize(),is(18));
  27.  
  28.     }
  29.  
  30.  
  31.  
  32.  
  33. ===============================================================================================
  34.  
  35.  
  36.  
  37. private void tryingToBuyUnitsWithProduction(Position p) {
  38.         int treasurySize = getCurrentTreasurySize(p);
  39.         String productionUnitType = getCityAt(p).getProduction();
  40.         int priceForProductionFocus = matchProductionFocusWithPriceOfUnit(productionUnitType);
  41.  
  42.         // If we have money enough
  43.         if (treasurySize >= priceForProductionFocus) {
  44.  
  45.             Position[] freePosition = p.getValidPositions();
  46.             for (Position position : freePosition) {
  47.                 if (isTileFree(position)) {
  48.                     unitWorld.put(position, new UnitImpl(productionUnitType, getPlayerInTurn()));
  49.                     setTreasurySize(p, treasurySize - priceForProductionFocus);
  50.                     break;
  51.                 }
  52.             }
  53.         }
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment