src/tankrotationexample/game/TRE.java
/**
     * Load all resources for Tank Wars Game. Set all Game Objects to their
     * initial state as well.
     */
Load all resources for Tank Wars Game. Set all Game Objects to their
initial state as well.
Load all resources for Tank Wars Game . Set all Game Objects to their initial state as well .
public void gameInitialize() {
        this.world = new BufferedImage(GameConstants.GAME_WORLD_WIDTH,
                                       GameConstants.GAME_WORLD_HEIGHT,
                                       BufferedImage.TYPE_INT_RGB);
        gameObjs = new ArrayList<>();
        try {
            background = (BufferedImage)Resource.getHashMap().get("wallpaper");
            /*
             * note class loaders read files from the out folder (build folder in Netbeans) and not the
             * current working directory.
             */
            InputStreamReader isr = new InputStreamReader(TRE.class.getClassLoader().getResourceAsStream("map/map1"));
            BufferedReader mapReader = new BufferedReader(isr);
            String row = mapReader.readLine();
            if (row == null) {
                throw new IOException("nothing here");
            }
            String[] mapInfo = row.split("\t");
            int numCols = Integer.parseInt(mapInfo[0]);
            int numRows = Integer.parseInt(mapInfo[1]);
            for (int curRow = 0; curRow < numRows; curRow++){
                row = mapReader.readLine();
                mapInfo = row.split("\t");
                for(int curCol = 0; curCol< numCols; curCol++){
                    switch(mapInfo[curCol]){
                        case "2" :
                            BreakableWall brwall = new BreakableWall(curCol*50, curRow*50, (BufferedImage) Resource.getHashMap().get("BreakableWall"));
                            this.gameObjs.add(brwall);
                            break;
                        case "4" :
                            Health health = new Health(curCol*50, curRow*50, (BufferedImage) Resource.getHashMap().get("Health"));
                            this.gameObjs.add(health);
                            break;
                        case "3" :
                        case "9" :
                            UnbreakableWall sowall = new UnbreakableWall(curCol*50, curRow*50, (BufferedImage) Resource.getHashMap().get("UnBreakableWall"));
                            this.gameObjs.add(sowall);
                            break;
                    }
                }
            }
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        Tank t1 = new Tank(150, 150, 0, 0, 90, (BufferedImage) Resource.getHashMap().get("RedTank"));
        TankControl tc1 = new TankControl(t1, KeyEvent.VK_W, KeyEvent.VK_S, KeyEvent.VK_A, KeyEvent.VK_D, KeyEvent.VK_SPACE);
        this.setBackground(Color.BLACK);
        this.lf.getJf().addKeyListener(tc1);
        Tank t2 = new Tank(2275, 1650, 0, 0, 270, (BufferedImage) Resource.getHashMap().get("BlueTank"));
        TankControl tc2 = new TankControl(t2, KeyEvent.VK_UP, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_ENTER);
        this.setBackground(Color.BLACK);
        this.lf.getJf().addKeyListener(tc2);
        this.gameObjs.add(t1);
        this.gameObjs.add(t2);
    }
public void gameInitialize ( ) { this . world = new BufferedImage ( GameConstants . GAME_WORLD_WIDTH , GameConstants . GAME_WORLD_HEIGHT , BufferedImage . TYPE_INT_RGB ) ; gameObjs = new ArrayList < > ( ) ; try { background = ( BufferedImage ) Resource . getHashMap ( ) . get ( "wallpaper" ) ; /*
             * note class loaders read files from the out folder (build folder in Netbeans) and not the
             * current working directory.
             */ InputStreamReader isr = new InputStreamReader ( TRE . class . getClassLoader ( ) . getResourceAsStream ( "map/map1" ) ) ; BufferedReader mapReader = new BufferedReader ( isr ) ; String row = mapReader . readLine ( ) ; if ( row == null ) { throw new IOException ( "nothing here" ) ; } String [ ] mapInfo = row . split ( "\t" ) ; int numCols = Integer . parseInt ( mapInfo [ 0 ] ) ; int numRows = Integer . parseInt ( mapInfo [ 1 ] ) ; for ( int curRow = 0 ; curRow < numRows ; curRow ++ ) { row = mapReader . readLine ( ) ; mapInfo = row . split ( "\t" ) ; for ( int curCol = 0 ; curCol < numCols ; curCol ++ ) { switch ( mapInfo [ curCol ] ) { case "2" : BreakableWall brwall = new BreakableWall ( curCol * 50 , curRow * 50 , ( BufferedImage ) Resource . getHashMap ( ) . get ( "BreakableWall" ) ) ; this . gameObjs . add ( brwall ) ; break ; case "4" : Health health = new Health ( curCol * 50 , curRow * 50 , ( BufferedImage ) Resource . getHashMap ( ) . get ( "Health" ) ) ; this . gameObjs . add ( health ) ; break ; case "3" : case "9" : UnbreakableWall sowall = new UnbreakableWall ( curCol * 50 , curRow * 50 , ( BufferedImage ) Resource . getHashMap ( ) . get ( "UnBreakableWall" ) ) ; this . gameObjs . add ( sowall ) ; break ; } } } } catch ( IOException ex ) { System . out . println ( ex . getMessage ( ) ) ; ex . printStackTrace ( ) ; } Tank t1 = new Tank ( 150 , 150 , 0 , 0 , 90 , ( BufferedImage ) Resource . getHashMap ( ) . get ( "RedTank" ) ) ; TankControl tc1 = new TankControl ( t1 , KeyEvent . VK_W , KeyEvent . VK_S , KeyEvent . VK_A , KeyEvent . VK_D , KeyEvent . VK_SPACE ) ; this . setBackground ( Color . BLACK ) ; this . lf . getJf ( ) . addKeyListener ( tc1 ) ; Tank t2 = new Tank ( 2275 , 1650 , 0 , 0 , 270 , ( BufferedImage ) Resource . getHashMap ( ) . get ( "BlueTank" ) ) ; TankControl tc2 = new TankControl ( t2 , KeyEvent . VK_UP , KeyEvent . VK_DOWN , KeyEvent . VK_LEFT , KeyEvent . VK_RIGHT , KeyEvent . VK_ENTER ) ; this . setBackground ( Color . BLACK ) ; this . lf . getJf ( ) . addKeyListener ( tc2 ) ; this . gameObjs . add ( t1 ) ; this . gameObjs . add ( t2 ) ; }
Load all resources for Tank Wars Game.
Load all resources for Tank Wars Game .