/mpango-game-core/src/test/java/net/sf/mpango/game/core/TestUtils.java

https://bitbucket.org/edevera/mpango · Java · 101 lines · 82 code · 16 blank · 3 comment · 0 complexity · b861ba1b47c7035be75dc892e4e02e8c MD5 · raw file

  1. package net.sf.mpango.game.core;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Set;
  5. import net.sf.mpango.common.directory.enums.StateEnum;
  6. import net.sf.mpango.game.core.action.Command;
  7. import net.sf.mpango.game.core.entity.BoardConfiguration;
  8. import net.sf.mpango.game.core.entity.Cell;
  9. import net.sf.mpango.game.core.entity.City;
  10. import net.sf.mpango.game.core.entity.Construction;
  11. import net.sf.mpango.game.core.entity.GameBoard;
  12. import net.sf.mpango.game.core.entity.Player;
  13. import net.sf.mpango.game.core.entity.Shield;
  14. import net.sf.mpango.game.core.entity.Technology;
  15. import net.sf.mpango.game.core.entity.Unit;
  16. import net.sf.mpango.game.core.entity.Weapon;
  17. import net.sf.mpango.game.core.enums.Resources;
  18. /**
  19. * @author <a href="mailto:eduardo.devera@gmail.com">Eduardo de Vera</a>
  20. */
  21. public class TestUtils {
  22. private TestUtils() {}
  23. public static final int ROW_SIZE = 20;
  24. public static final int COLUMN_SIZE = 15;
  25. public static City getCity(Long id) {
  26. City city = new City();
  27. city.setId(id);
  28. city.setAttackBonus(1.0f);
  29. city.setDefenseBonus(1f);
  30. city.setHitPoints(1f);
  31. city.setMaximumHitPoints(1f);
  32. return city;
  33. }
  34. public static Cell getCell(Long id) {
  35. Cell cell = new Cell(1,1);
  36. cell.setIdentifier(id);
  37. cell.setAttackBonus(1f);
  38. cell.setColumn(1);
  39. cell.setDefenseBonus(1f);
  40. cell.setRow(1);
  41. cell.setConstructions(new ArrayList<Construction>());
  42. cell.getConstructions().add(getCity(1L));
  43. return cell;
  44. }
  45. public static GameBoard getGameBoard(Long id) {
  46. GameBoard board = prepareGameBoard(ROW_SIZE, COLUMN_SIZE);
  47. board.setId(id);
  48. return board;
  49. }
  50. public static Player getPlayer() {
  51. Player player = new Player();
  52. player.setState(StateEnum.CREATED);
  53. return player;
  54. }
  55. public static Unit getUnit() {
  56. Unit unit = TestUnit.instance();
  57. unit.setWeapon(new Weapon(10f));
  58. unit.setShield(new Shield(10f));
  59. return unit;
  60. }
  61. public static net.sf.mpango.game.core.entity.GameBoard prepareGameBoard (int colSize, int rowSize) {
  62. BoardConfiguration boardConfiguration = new BoardConfiguration(rowSize, colSize);
  63. return GameBoard.generateRandomBoard(boardConfiguration);
  64. }
  65. public static Cell prepareCell(int colPosition, int rowPosition, Set<Resources> resources) {
  66. return new Cell(colPosition, rowPosition, resources);
  67. }
  68. public static Technology getTechnology(Long id, int cost) {
  69. Technology tech = new Technology();
  70. tech.setId(id);
  71. tech.setTechnologyCost(cost);
  72. tech.setRequiredTechnologies((List<Technology>)new ArrayList<Technology>());
  73. return tech;
  74. }
  75. private static class TestUnit extends Unit {
  76. private TestUnit(List<Technology> technology, List<Command> command) {
  77. super(new City(), command, technology, 10f, 100f);
  78. }
  79. public static Unit instance() {
  80. List<Technology> tech = new ArrayList<Technology>();
  81. List<Command> com = new ArrayList<Command>();
  82. return new TestUnit(tech, com);
  83. }
  84. }
  85. }