Making a maze. Movement is carried out on the frame, depending on the value in the array map , where 1 - you can move, 2 - wall. Well, as a result, it turns out that I move one pixel at a time and for a large maze I have to create a large array. How to increase the size of the maze without increasing the array?
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class RealMaze implements ActionListener { int x = 1; int y = 1; JButton button; MyDrawPanel myDrawPanel; JFrame frame; public static void main(String[] args) { RealMaze realMaze = new RealMaze(); realMaze.go(); } public void go() { frame = new JFrame(); myDrawPanel = new MyDrawPanel(); button = new JButton("Test"); frame.setSize(100, 100); frame.setVisible(true); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(BorderLayout.CENTER, myDrawPanel); frame.getContentPane().add(BorderLayout.SOUTH, button); button.addActionListener(this); } //Движение по фрейму public void actionPerformed(ActionEvent event) { if (map[x][y] == 1) { x++; System.out.println(x); System.out.println(map[x][y]); } frame.repaint(); } class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { g.setColor(Color.gray); g.fillRect(x, y, 10, 10); } } //Карта, 2 - стена. int[][] map = new int[][]{ {1,1,1,1,1,1,1,2,1,1}, {1,1,1,1,1,1,1,2,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1}, {2,2,1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1,1,1} }; }