Package model

Examples of model.Environment


                    int diff = team0PlayerNum - team1PlayerNum;
                    for (int i = 0; i < diff; i++) {
                        int playerPosition = map.removeLastOnePlayerFromTeamN(0);

                        //Remove the environment in row: 0, position: playerPosition of the current world.
                        Environment removedEnv = client.getServer().removeAnEnvFromWorld(pvpWorld.getID(), Constants.GAME_TYPE_PVP, 0, playerPosition);

                        EnvironmentDAO.deleteEnvironmentByID(removedEnv.getID());
                        AvatarDAO.deleteAvatarByID(client.getAvatar().getID());
                    }
                } else if (team1PlayerNum > team0PlayerNum) {
                    int diff = team1PlayerNum - team0PlayerNum;
                    for (int i = 0; i < diff; i++) {
                        int playerPosition = map.removeLastOnePlayerFromTeamN(1);

                        //Remove the environment in row: 0, position: playerPosition of the current world.
                        Environment removedEnv = client.getServer().removeAnEnvFromWorld(pvpWorld.getID(), Constants.GAME_TYPE_PVP, 0, playerPosition);

                        EnvironmentDAO.deleteEnvironmentByID(removedEnv.getID());
                        AvatarDAO.deleteAvatarByID(client.getAvatar().getID());
                    }
                }
            } else {
                System.out.println("PvP world map is null");
View Full Code Here


                    } else {
                        System.out.println("In RequestJoinPvPWorld.java---map is null");
                    }

                    //Create a new environment for this user.
                    Environment env = new Environment(world.getID());
                    env.setRow(row);
                    env.setColumn(col);
                    try {
                        EnvironmentDAO.createEnvironment(env);
                    } catch (SQLException ex) {
                    }

                    Environment sameEnv = null;
                    try {
                        sameEnv = EnvironmentDAO.getEnvironmentByWorldIDAndRowAndCol(env);//Get the environment out of db just to get its id which is generated in db.
                        if (sameEnv != null) {
                            sameEnv.toString();
                        } else {
                            System.out.println("The environment from db is null.");
                        }
                    } catch (SQLException ex) {
                    }

                    world.getEnvironments().add(sameEnv);
                    System.out.println("*****World start*****");
                    world.toString();
                    System.out.println("*****World end*****");

                    //Create an avatar for this user.
                    Avatar ava = new Avatar(-1);
                    ava.setPlayerID(client.getPlayer().getID());
                    //Set [team_no] & [envPosition] for this avatar.
                    ava.setTeamNo(sameEnv.getRow());

                    int avatar_id = AvatarDAO.createAvatar(ava);

                    ava.setPlayerID(client.getPlayer().getID());

View Full Code Here

    public void doBusiness() throws Exception {
        if (status) {
            World world = client.getWorld();

            if (world != null) {
                Environment env = world.getEnvByUserID(client.getPlayer().getID());

                for (Zone zone : env.getZones()) {
                    if (zone.isEnable()) {
                        zone.restart();

                        SimulationEngine se = new SimulationEngine();
                        zone.setSimulationEngine(se);

                        String networkName = "WoB-" + env.getID() + "." + zone.getOrder() + "-" + System.currentTimeMillis() % 100000;

                        int nodeList[] = {1, 8, 9};
                        zone.setManipulationID(se.createAndRunSeregenttiSubFoodweb(nodeList, networkName, 0, 0, false));

                        ZoneDAO.updateManipulationID(zone.getID(), zone.getManipulationID());
View Full Code Here

    public void doBusiness() throws Exception {
        System.out.println("At the beggining of doBusiness()");
        System.out.println("Username is:" + client.getPlayer().getUsername());

        if (client.getWorld() != null) {
            Environment currentEnv1 = client.getWorld().getEnvByUserID(client.getPlayer().getID());
            System.out.println("currentEnv1 is:");
            currentEnv1.toString();
        } else {
            System.out.println("client.getWorld() is null");
        }

        //Get the environment of this client.
        Environment currentEnv = client.getWorld().getEnvByUserID(client.getPlayer().getID());
        if (currentEnv != null) {
            System.out.println("Envrionment is not null");
            responseWaterSource.setStatus((short) 0);
            responseWaterSource.setWorld(client.getWorld());

            for (WaterSource ws : waters) {
                try {
                    WaterSourceDAO.createWaterSource(ws);
                } catch (SQLException ex) {
                    Logger.getLogger(RequestWaterSource.class.getName()).log(Level.SEVERE, null, ex);
                }

                //Get this WaterSource from database just for its id.
                try {
                    List<WaterSource> sameWSList = WaterSourceDAO.getByZoneID(ws.getZoneID());
                    if (sameWSList != null) {
                        WaterSource sameWS = sameWSList.get(0);//Each zone only has one water source.
                        if (sameWS != null) {
                            Zone zone = currentEnv.getZoneByID(sameWS.getZoneID());
                            if (zone != null) {
//                                zone.getWaters().add(sameWS);
                            }
                        }
                    }
View Full Code Here

        return env_id;
    }

    public static Environment getEnvironment(int player_id, int world_id) throws SQLException {
        Environment environment = null;

        String query = "SELECT * FROM `environment` WHERE `world_id` = ? AND `player_id` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, world_id);
            pstmt.setInt(2, player_id);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                environment = new Environment(rs.getInt("env_id"));
                environment.setWorldID(rs.getInt("world_id"));
                environment.setOwnerID(rs.getInt("player_id"));
                environment.setRow(rs.getInt("row"));
                environment.setColumn(rs.getInt("column"));
                environment.setEnvironmentScore(rs.getInt("score"));
                environment.setHighEnvScore(rs.getInt("high_score"));
                environment.setAccumulatedEnvScore(rs.getInt("accumulated_score"));

                List<Zone> zoneList = ZoneDAO.getZoneByEnvironmentID(environment.getID());

                for (Zone zone : zoneList) {
                    zone.setEnvironment(environment);
                }

                environment.setZones(zoneList);
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

     * Environment is retrieved by matching all three inWorldIDFk, envRow, and
     * envColumn in the database.  If no Environment is found the returns null.
     * @throws SQLException
     */
    public static Environment getEnvironmentByWorldIDAndRowAndCol(Environment environment) throws SQLException {
        Environment returnEnvironment = null;

        String query = "SELECT * FROM `environment` WHERE `world_id` = ? AND `row` = ? AND `column` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, environment.getWorldID());
            pstmt.setInt(2, environment.getRow());
            pstmt.setInt(3, environment.getColumn());
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                returnEnvironment = new Environment(rs.getInt("env_id"));
                returnEnvironment.setWorldID(rs.getInt("world_id"));
                returnEnvironment.setOwnerID(rs.getInt("player_id"));
                returnEnvironment.setRow(rs.getInt("row"));
                returnEnvironment.setColumn(rs.getInt("column"));
                returnEnvironment.setEnvironmentScore(rs.getInt("score"));
                returnEnvironment.setHighEnvScore(rs.getInt("high_score"));
                returnEnvironment.setAccumulatedEnvScore(rs.getInt("accumulated_score"));
            }

            rs.close();
            pstmt.close();

            List<Zone> zoneList = ZoneDAO.getZoneByEnvironmentID(returnEnvironment.getID());

            for (Zone zone : zoneList) {
                zone.setEnvironment(returnEnvironment);
            }

            returnEnvironment.setZones(zoneList);
        } finally {
            if (connection != null) {
                connection.close();
            }
        }
View Full Code Here

            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, world_id);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                Environment env = new Environment(rs.getInt("env_id"));
                env.setWorldID(rs.getInt("world_id"));
                env.setOwnerID(rs.getInt("player_id"));
                env.setRow(rs.getInt("row"));
                env.setColumn(rs.getInt("column"));
                env.setEnvironmentScore(rs.getInt("score"));
                env.setHighEnvScore(rs.getInt("high_score"));
                env.setAccumulatedEnvScore(rs.getInt("accumulated_score"));

                returnEnvironmentList.add(env);
            }

            rs.close();
            pstmt.close();

            for (Environment env : returnEnvironmentList) {
                List<Zone> zoneList = ZoneDAO.getZoneByEnvironmentID(env.getID());
               
                for (Zone zone : zoneList) {
                    zone.setEnvironment(env);
                }
               
                env.setZones(zoneList);
            }
        } finally {
            if (connection != null) {
                connection.close();
            }
View Full Code Here

     * @return Returns the Environment which matches the passed argument in the
     * database.  If none found returns null.
     * @throws SQLException
     */
    public static Environment getEnvironmentByEnvID(int envID) throws SQLException {
        Environment env = null;

        String query = "SELECT * FROM `environment` WHERE `env_id` = ?";

        Connection connection = null;
        PreparedStatement pstmt = null;

        try {
            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            pstmt.setInt(1, envID);
            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {
                env = new Environment(rs.getInt("env_id"));
                env.setWorldID(rs.getInt("world_id"));
                env.setOwnerID(rs.getInt("player_id"));
                env.setRow(rs.getInt("row"));
                env.setColumn(rs.getInt("column"));
                env.setEnvironmentScore(rs.getInt("score"));
                env.setHighEnvScore(rs.getInt("high_score"));
                env.setAccumulatedEnvScore(rs.getInt("accumulated_score"));
            }

            rs.close();
            pstmt.close();
        } finally {
View Full Code Here

     * Test of saveEnvironment method, of class EnvironmentDAO.
     */
    @Test
    public void testSaveEnvironment() throws Exception {
        System.out.println("saveEnvironment");
        Environment environment = null;
        EnvironmentDAO instance = new EnvironmentDAO();
        instance.saveEnvironment(environment);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
View Full Code Here

     * Test of getEnvironmentByWorldIDAndRowAndCol method, of class EnvironmentDAO.
     */
    @Test
    public void testGetEnvironmentByWorldIDAndRowAndCol() throws Exception {
        System.out.println("getEnvironmentByWorldIDAndRowAndCol");
        Environment environment = null;
        EnvironmentDAO instance = new EnvironmentDAO();
        Environment expResult = null;
        Environment result = instance.getEnvironmentByWorldIDAndRowAndCol(environment);
        assertEquals(expResult, result);
        // TODO review the generated test code and remove the default call to fail.
        fail("The test case is a prototype.");
    }
View Full Code Here

TOP

Related Classes of model.Environment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.