public void updateMovie(Movie m) throws ServerFailureException, ObjectNotFoundException {
   try {
     pm.updateMovie(m);
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
 public void deleteMovie(int id) throws ServerFailureException, ObjectNotFoundException {
   try {
     pm.deleteMovie(id);
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
 public Movie getMovieById(int id) throws ServerFailureException, ObjectNotFoundException {
   try {
     return pm.getMovieById(id);
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
 public void addMovie(Movie m) throws ServerFailureException {
   try {
     pm.insertMovie(m);
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
 public void deleteAllMovies() throws ServerFailureException {
   try {
     pm.deleteAllMovies();
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
 public List getAllMovieRatings() throws ServerFailureException {
   try {
     return pm.getAllMovieRatings();
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
 public boolean validateUser(String userId, String password) throws ServerFailureException {
   try {
     return pm.validateUser(userId, password);
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
Beispiel #8
0
 /**
  * Creates a new unit at the X and Y location. X and Y should be a factory.
  *
  * @param x
  * @param y
  * @param unitType
  * @param owner
  */
 public Unit createUnit(int x, int y, UnitType unitType, Player owner) {
   Unit newUnit = null;
   switch (unitType) {
     case SOLDIER:
       newUnit = Unit.createSoldier(owner);
       break;
     case TANK:
       newUnit = Unit.createTank(owner);
       break;
     case ARTILLERY:
       newUnit = Unit.createArtillery(owner);
       break;
   }
   try {
     // Game Logic here -- Prevent creation if factory isn't here.
     if (gameMap.getTerrainAt(x, y).terrainType.equals(TerrainType.Factory)) {
       Structure factoryStructure = (Structure) gameMap.getTerrainAt(x, y);
       if (factoryStructure.owner == owner) {
         this.gameMap.createUnit(x, y, newUnit);
       }
     }
   } catch (MapException e) {
     System.out.println("Game: Error in creating new unit. This should never happen.");
     e.printStackTrace();
   }
   return newUnit;
 }
 private BusinessDelegate() throws ServerFailureException {
   super();
   try {
     pm = PersistenceMapFactory.getInstance().getMap();
   } catch (MapException e) {
     throw new ServerFailureException(e.getMessage());
   }
 }
Beispiel #10
0
 /**
  * Uses the unit to capture a structure.
  *
  * @param x The X coordinate of the structure.
  * @param y The Y coordinate of the structure.
  * @param capturer The Unit that is trying to capture.
  */
 public void captureStructure(int x, int y, Unit capturer) {
   try {
     this.gameMap.captureStructure(x, y, capturer);
   } catch (MapException e) {
     System.out.println("Game: Error in capturing structure.  This should never happen.");
     e.printStackTrace();
   }
 }
Beispiel #11
0
 /**
  * Moves a unit from its initial position to its final position.
  *
  * @param xStart
  * @param yStart
  * @param xDest
  * @param yDest
  */
 public void moveUnit(int xStart, int yStart, int xDest, int yDest) {
   try {
     gameMap.moveUnit(xStart, yStart, xDest, yDest);
   } catch (MapException e) {
     System.out.println("Game: Error in moving unit.  This should never happen.");
     e.printStackTrace();
   }
 }
Beispiel #12
0
  /**
   * Starter map for demo. Same layout as map 2, but with units in pre-set positions.
   *
   * @return Map
   */
  public static Map generateMap03(Player player1, Player player2) {
    Map newMap = generateMap02(player1, player2);

    // delete players default units
    newMap.deleteUnitAt(0, 0);
    newMap.deleteUnitAt(15, 15);

    // Add units for each player.
    try {
      newMap.createUnit(9, 3, Unit.createTank(player1));
      newMap.createUnit(5, 4, Unit.createSoldier(player1));
      newMap.createUnit(2, 7, Unit.createSoldier(player1));
      newMap.createUnit(7, 6, Unit.createSoldier(player2));
    } catch (MapException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return newMap;
  }
Beispiel #13
0
 private void check(String expected, MapException ex) {
   String msg = ex.getMessage();
   boolean ends = msg.startsWith(expected);
   assertEquals(
       "Message should have started with: \""
           + expected
           + ".\"  Full message was \""
           + msg
           + "\".",
       true,
       ends);
   boolean resolvedThings = msg.endsWith("[]");
   assertEquals(true, resolvedThings);
 }
Beispiel #14
0
 /**
  * Starter map for two players. Contains two player controlled factories, one at each corner. The
  * rest is plains.
  *
  * @return
  */
 public static Map generateMap01(Player player1, Player player2) {
   Map newMap = new Map(16, 16);
   newMap.addPlayer(player1);
   newMap.addPlayer(player2);
   for (int i = 0; i < 16; i++) {
     for (int j = 0; j < 16; j++) {
       // Loop through all the coordinates
       if (i == 0 && j == 0) {
         // Player 1's factory.
         Terrain playerOneFactory = Structure.createFactory(player1);
         try {
           newMap.addTerrain(0, 0, playerOneFactory);
         } catch (MapException e) {
           System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
           e.printStackTrace();
         }
       } else if (i == 15 && j == 15) {
         // Player 2's factory.
         Terrain playerTwoFactory = Structure.createFactory(player2);
         try {
           newMap.addTerrain(i, j, playerTwoFactory);
         } catch (MapException e) {
           System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
           e.printStackTrace();
         }
       } else {
         // Fill with plain.
         Terrain plainTerrain = Terrain.createPlainTerrain();
         try {
           newMap.addTerrain(i, j, plainTerrain);
         } catch (MapException e) {
           System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
           e.printStackTrace();
         }
       }
     }
   }
   return newMap;
 }
Beispiel #15
0
  /**
   * Starter map for two players. Contains two player controlled factories, one at each corner. The
   * rest is plains.
   *
   * @return
   */
  public static Map generateMap02(Player player1, Player player2) {
    Map newMap = new Map(16, 16);
    newMap.addPlayer(player1);
    newMap.addPlayer(player2);
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 16; j++) {
        // Loop through all the coordinates
        if ((i == 0 && j == 0) || (i == 2 && j == 0) || (i == 0 && j == 2)) {
          // Player 1's factory.
          Terrain playerOneFactory = Structure.createFactory(player1);
          try {
            newMap.addTerrain(i, j, playerOneFactory);
          } catch (MapException e) {
            System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
            e.printStackTrace();
          }
        } else if ((i == 15 && j == 15) || (i == 13 && j == 15) || (i == 15 && j == 13)) {
          // Player 2's factory.
          Terrain playerTwoFactory = Structure.createFactory(player2);
          try {
            newMap.addTerrain(i, j, playerTwoFactory);
          } catch (MapException e) {
            System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
            e.printStackTrace();
          }
        } else if ((i == 3 || i == 11) && (j > 3 && j < 11)) {
          // Fill with mountain.
          Terrain mountainTerrain = Terrain.createMountainTerrain();
          try {
            newMap.addTerrain(i, j, mountainTerrain);
          } catch (MapException e) {
            System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
            e.printStackTrace();
          }
        } else if ((i > 3 && i < 11) && (j > 3 && j < 11)) {
          // Fill with wood.
          Terrain woodTerrain = Terrain.createWoodTerrain();
          try {
            newMap.addTerrain(i, j, woodTerrain);
          } catch (MapException e) {
            System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
            e.printStackTrace();
          }
        } else {
          // Fill with plain.
          Terrain plainTerrain = Terrain.createPlainTerrain();
          try {
            newMap.addTerrain(i, j, plainTerrain);
          } catch (MapException e) {
            System.out.println("GenerateMap01 Terrain Adding Error: This should never happen.");
            e.printStackTrace();
          }
        }
      }
    }

    // Add a unit for each player.
    try {
      newMap.createUnit(0, 0, Unit.createSoldier(player1));
      newMap.createUnit(15, 15, Unit.createSoldier(player2));
    } catch (MapException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return newMap;
  }