将ArrayList Map显示为Painted String / Minimap

时间:2018-04-23 19:03:51

标签: java arrays eclipse list

我正在基于程序生成的ArrayList映射进行Isaac-esque Roguelike的绑定。我想知道如何获取ArrayList并将其显示为屏幕右侧的小地图。

我正在考虑用一对括号来代表一个房间和空白空间......好空白。

但它目前显示的内存位置如下:

RoomState@6ad22b72

这是我目前的代码:

public class GameState extends JFrame implements KeyListener {
    Container contentPane=this.getContentPane();
    Graphics bufferGraphics;

    int characterX=463;
    int characterY=486;
    int oldCharacterX=463;
    int oldCharacterY=486;
    int xAxis;
    int yAxis;
    Image characterNorth = CustomImages.createImageIcon("Images/characterNorth.jpg").getImage();
    Image characterEast = CustomImages.createImageIcon("Images/characterEast.jpg").getImage();
    Image characterSouth = CustomImages.createImageIcon("Images/characterSouth.jpg").getImage();
    Image characterWest = CustomImages.createImageIcon("Images/characterWest.jpg").getImage();
    Image brickWall = CustomImages.createImageIcon("Images/brickWall.jpg").getImage();
    Image brickFloor = CustomImages.createImageIcon("Images/brickFloor.jpg").getImage();
    Image character=characterNorth;
    boolean pressed=false;

    ArrayList<RoomState> map = new ArrayList<RoomState>();
    RoomState currentRoom = new RoomState();
    RoomState currentRoomState=new RoomState();


    GameState() {
        this.setBounds(0, 0, 1680, 1050);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        addKeyListener(this);
        setFocusable(true);
        requestFocusInWindow();
    }

    public void move(int x, int y) { //Check Move
        currentRoomState=currentRoomState.MoveToNextRoom(true, false, false, false);
        currentRoomState=currentRoomState.MoveToNextRoom(false, true, false, false);
        currentRoomState=currentRoomState.MoveToNextRoom(false, false, true, false);
        currentRoomState=currentRoomState.MoveToNextRoom(false, false, false, true);
    }

    public void paint(Graphics g) { //Graphics
        for(xAxis=58;xAxis<=858;xAxis=xAxis+50) {
            for(yAxis=81;yAxis<=881;yAxis=yAxis+50) {
                g.drawImage(brickFloor,xAxis,yAxis,null);
            }
            yAxis=31;
        }
        for(xAxis=8;xAxis<958;xAxis=xAxis+50) {
            g.drawImage(brickWall,xAxis,yAxis,null);
        }
        yAxis=931;
        for(xAxis=8;xAxis<=908;xAxis=xAxis+50) {
            g.drawImage(brickWall,xAxis,yAxis,null);
        }
        xAxis=8;
        for(yAxis=81;yAxis<=881;yAxis=yAxis+50) {
            g.drawImage(brickWall,xAxis,yAxis,null);
        }
        xAxis=908;
        for(yAxis=81;yAxis<=881;yAxis=yAxis+50) {
            g.drawImage(brickWall,xAxis,yAxis,null);
        }

        if(currentRoom.northDoor) {
            g.drawImage(brickFloor,458,31,null);
        }
        if(currentRoom.eastDoor) {
            g.drawImage(brickFloor,908,481,null);
        }
        if(currentRoom.southDoor) {
            g.drawImage(brickFloor,458,931,null);
        }
        if(currentRoom.westDoor) {
            g.drawImage(brickFloor,8,481,null);
        }

        g.drawImage(character,characterX,characterY,null);

        String minimap=Arrays.toString(map.toArray());
        g.drawString(minimap,975,500);

    }

    @Override
    public void keyPressed(KeyEvent arg0) { //Character Rotation/Movement.
        if(pressed==false) {
            pressed=true;
            oldCharacterX=characterX;
            oldCharacterY=characterY;
            if(arg0.getKeyCode() == KeyEvent.VK_W || arg0.getKeyCode() == KeyEvent.VK_UP) {
                if(character==characterNorth) {
                    if(characterY>86 && characterX>13 && characterX<913) {
                        characterY=characterY-50;
                    }else if(currentRoom.northDoor && characterX==463) {
                        oldCharacterY=characterY;
                        characterY=characterY-50;
                        if(characterY==-14) {
                            if(currentRoom.rs_NorthDoor != null) {
                                currentRoom=currentRoom.rs_NorthDoor;
                            }else {
                                RoomState nextRoom = new RoomState(currentRoom,false, false, true, false);
                                currentRoom.rs_NorthDoor = nextRoom;
                                map.add(nextRoom);
                                currentRoom = nextRoom;
                                nextRoom = null;
                            }
                            characterX=463;
                            characterY=936;
                            repaint();
                        }
                    }
                }else {
                    character=characterNorth;
                }
            }
            if(arg0.getKeyCode() == KeyEvent.VK_A || arg0.getKeyCode() == KeyEvent.VK_LEFT) {
                if(character==characterWest && characterY>36 && characterY<926) {
                    if(characterX>63) {
                        oldCharacterX=characterX;
                        characterX=characterX-50;
                    }else if(currentRoom.westDoor && characterY==486) {
                        oldCharacterX=characterX;
                        characterX=characterX-50;
                        if(characterX==-37) {
                            if(currentRoom.rs_WestDoor != null) {
                                currentRoom = currentRoom.rs_WestDoor;
                            }else {
                                RoomState nextRoom = new RoomState(currentRoom,false, true, false, false);
                                currentRoom.rs_WestDoor = nextRoom;
                                map.add(nextRoom);
                                currentRoom = nextRoom;
                                nextRoom = null;
                            }
                            characterX=913;
                            characterY=486;
                            repaint();
                        }
                    }
                }else {
                    character=characterWest;
                }
            }
            if(arg0.getKeyCode() == KeyEvent.VK_S || arg0.getKeyCode() == KeyEvent.VK_DOWN) {
                if(character==characterSouth) {
                    if(characterY<871 && characterX>13 && characterX<913) {
                        oldCharacterY=characterY;
                        characterY=characterY+50;
                    }else if(currentRoom.southDoor && characterX==463) {
                        oldCharacterY=characterY;
                        characterY=characterY+50;
                        if(characterY==986) {
                            if(currentRoom.rs_SouthDoor != null) {
                                currentRoom=currentRoom.rs_SouthDoor;
                            }else {
                                RoomState nextRoom = new RoomState(currentRoom,true, false, false, false);
                                currentRoom.rs_SouthDoor = nextRoom;
                                map.add(nextRoom);
                                currentRoom = nextRoom;
                                nextRoom = null;
                            }
                            characterX=463;
                            characterY=36;
                            repaint();
                        }
                    }
                }else {
                    character=characterSouth;
                }
            }
            if(arg0.getKeyCode() == KeyEvent.VK_D || arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
                if(character==characterEast && characterY>36 && characterY<926) {
                    if(characterX<848) {
                        oldCharacterX=characterX;
                        characterX=characterX+50;
                    }else if(currentRoom.eastDoor && characterY==486) {
                        oldCharacterX=characterX;
                        characterX=characterX+50;
                        if(characterX==963) {
                            if(currentRoom.rs_EastDoor != null) {
                                currentRoom = currentRoom.rs_EastDoor;
                            }else {
                                RoomState nextRoom = new RoomState(currentRoom,false, false, false, true);
                                currentRoom.rs_EastDoor = nextRoom;
                                map.add(nextRoom);
                                currentRoom = nextRoom;         
                                nextRoom = null;
                            }
                            characterX=13;
                            characterY=486;
                            repaint();
                        }
                    }
                }else {
                    character=characterEast;
                }
            }
            if(oldCharacterX != characterX || oldCharacterY != characterY) {
                repaint(oldCharacterX,oldCharacterY,40,40);
            }
            repaint(characterX,characterY,40,40);
        }
    }

    @Override
    public void keyReleased(KeyEvent arg0) { //Prevents Holding Down Keys.
        if(arg0.getKeyCode() == KeyEvent.VK_W || arg0.getKeyCode() == KeyEvent.VK_UP) { 
            pressed=false;
        }
        if(arg0.getKeyCode() == KeyEvent.VK_A || arg0.getKeyCode() == KeyEvent.VK_LEFT) {
            pressed=false;
        }
        if(arg0.getKeyCode() == KeyEvent.VK_S || arg0.getKeyCode() == KeyEvent.VK_DOWN) {
            pressed=false;
        }
        if(arg0.getKeyCode() == KeyEvent.VK_D || arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
            pressed=false;
        }
    }

    @Override
    public void keyTyped(KeyEvent arg0) {
    }
}

有人可以向我倾斜正确的方向吗?

0 个答案:

没有答案